Skip to content

Commit

Permalink
fix: tmpname
Browse files Browse the repository at this point in the history
  • Loading branch information
izatop committed Apr 15, 2024
1 parent 8b16d77 commit 6b37930
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {randomBytes} from "crypto";
import {randomUUID} from "crypto";
import {tmpdir} from "os";
import {join} from "path";
import {createWriteStream} from "fs";
Expand All @@ -24,10 +24,7 @@ export const MultipartFormDataTransform = async <T = unknown>(request: IRequest)
bb
.on("file", (name, file, info) => {
const {encoding, filename, mimeType} = info;
const tmpname = join(
tmpdir(),
`${randomBytes(4).toString("hex")}-${Buffer.from(filename, "utf-8").toString("hex")}`,
);
const tmpname = join(tmpdir(), randomUUID());

const value = {
filename,
Expand Down
5 changes: 3 additions & 2 deletions packages/web/src/Transport/Response/DownloadResponse.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {createReadStream, createWriteStream} from "fs";
import {Readable} from "stream";
import {randomBytes} from "crypto";
import {randomUUID} from "crypto";
import {tmpdir} from "os";
import {stat, unlink} from "fs/promises";
import {join} from "path";
import {isString, isUndefined} from "@bunt/is";
import {Defer} from "@bunt/async";
import {ResponseAbstract, ResponseArgs} from "./ResponseAbstract.js";
Expand Down Expand Up @@ -71,7 +72,7 @@ function createOptions(options: DownloadOptionsAuth): ResponseArgs<Readable> {

function createTemporarySource(options: DownloadOptionsAuth): ResponseArgs<Readable> {
const inputReadable = factoryReadableStream(options.source);
const tmpname = `${tmpdir()}/${Date.now()}-${randomBytes(16).toString("hex")}`;
const tmpname = join(tmpdir(), randomUUID());
const writable = createWriteStream(tmpname);
const defer = new Defer<number>();
writable.once("close", () => stat(tmpname).then((s) => defer.resolve(s.size)));
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ __metadata:
languageName: node
linkType: hard

"@bunt/app@npm:^0.29.26, @bunt/app@workspace:packages/app":
"@bunt/app@npm:^0.29.27, @bunt/app@workspace:packages/app":
version: 0.0.0-use.local
resolution: "@bunt/app@workspace:packages/app"
dependencies:
Expand Down Expand Up @@ -454,7 +454,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@bunt/cli@workspace:packages/cli"
dependencies:
"@bunt/app": "npm:^0.29.26"
"@bunt/app": "npm:^0.29.27"
"@bunt/assert": "npm:^0.29.19"
"@bunt/util": "npm:^0.29.26"
path-to-regexp: "npm:^6.2.2"
Expand Down Expand Up @@ -554,11 +554,11 @@ __metadata:
languageName: unknown
linkType: soft

"@bunt/web@npm:^0.29.26, @bunt/web@workspace:packages/web":
"@bunt/web@npm:^0.29.27, @bunt/web@workspace:packages/web":
version: 0.0.0-use.local
resolution: "@bunt/web@workspace:packages/web"
dependencies:
"@bunt/app": "npm:^0.29.26"
"@bunt/app": "npm:^0.29.27"
"@bunt/assert": "npm:^0.29.19"
"@bunt/async": "npm:^0.29.19"
"@bunt/is": "npm:^0.29.19"
Expand All @@ -573,14 +573,14 @@ __metadata:
version: 0.0.0-use.local
resolution: "@bunt/ws@workspace:packages/ws"
dependencies:
"@bunt/app": "npm:^0.29.26"
"@bunt/app": "npm:^0.29.27"
"@bunt/assert": "npm:^0.29.19"
"@bunt/async": "npm:^0.29.19"
"@bunt/is": "npm:^0.29.19"
"@bunt/type": "npm:^0.29.19"
"@bunt/unit": "npm:^0.29.26"
"@bunt/util": "npm:^0.29.26"
"@bunt/web": "npm:^0.29.26"
"@bunt/web": "npm:^0.29.27"
"@types/websocket": "npm:^1.0.10"
"@types/ws": "npm:^8.5.10"
websocket: "npm:^1.0.34"
Expand Down

0 comments on commit 6b37930

Please sign in to comment.