Skip to content

Commit

Permalink
fix: download response
Browse files Browse the repository at this point in the history
  • Loading branch information
izatop committed Jul 26, 2023
1 parent 3fc3b14 commit 7494999
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions packages/web/src/Transport/Response/DownloadResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class DownloadResponse extends ResponseAbstract<Readable> {
function createHeaders(options: DownloadOptions): Record<string, string> {
const size = options.size;
const headers: Record<string, string> = {
"Content-Disposition": `attachment; filename=${options.filename}`,
"Content-Disposition": `attachment; filename=${encodeURI(options.filename)}`,
"Content-Length": size.toString(),
"Content-Type": options.mimeType,
};
Expand Down Expand Up @@ -66,10 +66,9 @@ function createTemporarySource(options: DownloadOptionsAuth): ResponseArgs<Reada
const inputReadable = factoryReadableStream(options.source);
const tmpname = `${tmpdir()}/${Date.now()}-${randomBytes(16).toString("hex")}`;
const writable = createWriteStream(tmpname);
inputReadable.pipe(writable);

const defer = new Defer<number>();
writable.once("close", () => stat(tmpname).then((s) => defer.resolve(s.size)));
inputReadable.pipe(writable);

const ready = (): Readable => createReadStream(tmpname).once("close", () => unlink(tmpname));
const headers = (size: number): Record<string, string> => createHeaders({...options, size});
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ __metadata:
languageName: node
linkType: hard

"@bunt/app@^0.29.6, @bunt/app@workspace:packages/app":
"@bunt/app@^0.29.9, @bunt/app@workspace:packages/app":
version: 0.0.0-use.local
resolution: "@bunt/app@workspace:packages/app"
dependencies:
Expand Down Expand Up @@ -457,7 +457,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@bunt/cli@workspace:packages/cli"
dependencies:
"@bunt/app": ^0.29.6
"@bunt/app": ^0.29.9
"@bunt/assert": ^0.29.0
"@bunt/util": ^0.29.0
path-to-regexp: ^6.2.1
Expand Down Expand Up @@ -552,11 +552,11 @@ __metadata:
languageName: unknown
linkType: soft

"@bunt/web@^0.29.7, @bunt/web@workspace:packages/web":
"@bunt/web@^0.29.9, @bunt/web@workspace:packages/web":
version: 0.0.0-use.local
resolution: "@bunt/web@workspace:packages/web"
dependencies:
"@bunt/app": ^0.29.6
"@bunt/app": ^0.29.9
"@bunt/assert": ^0.29.0
"@bunt/async": ^0.29.6
"@bunt/is": ^0.29.0
Expand All @@ -571,14 +571,14 @@ __metadata:
version: 0.0.0-use.local
resolution: "@bunt/ws@workspace:packages/ws"
dependencies:
"@bunt/app": ^0.29.6
"@bunt/app": ^0.29.9
"@bunt/assert": ^0.29.0
"@bunt/async": ^0.29.6
"@bunt/is": ^0.29.0
"@bunt/type": ^0.29.0
"@bunt/unit": ^0.29.6
"@bunt/util": ^0.29.0
"@bunt/web": ^0.29.7
"@bunt/web": ^0.29.9
"@types/websocket": ^1.0.5
"@types/ws": ^8.5.5
websocket: ^1.0.34
Expand Down

0 comments on commit 7494999

Please sign in to comment.