@hyperframes/studio-server 0.8.31 → 0.8.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +30 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2318,12 +2318,13 @@ async function processUploadedFiles(formData, targetDir, projectDir) {
|
|
|
2318
2318
|
if (!isSafePath(projectDir, destPath)) continue;
|
|
2319
2319
|
let finalPath = destPath;
|
|
2320
2320
|
let finalName = name;
|
|
2321
|
+
const dotIdx = name.indexOf(".", name.startsWith(".") ? 1 : 0);
|
|
2322
|
+
const ext = dotIdx > 0 ? name.slice(dotIdx) : "";
|
|
2323
|
+
const base = dotIdx > 0 ? name.slice(0, dotIdx) : name;
|
|
2324
|
+
const MAX_COPY_INDEX = 1e4;
|
|
2325
|
+
let n = 1;
|
|
2321
2326
|
if (existsSync4(finalPath)) {
|
|
2322
|
-
|
|
2323
|
-
const ext = dotIdx > 0 ? name.slice(dotIdx) : "";
|
|
2324
|
-
const base = dotIdx > 0 ? name.slice(0, dotIdx) : name;
|
|
2325
|
-
let n = 2;
|
|
2326
|
-
const MAX_COPY_INDEX = 1e4;
|
|
2327
|
+
n = 2;
|
|
2327
2328
|
while (n < MAX_COPY_INDEX && existsSync4(resolve3(targetDir, `${base} (${n})${ext}`))) n++;
|
|
2328
2329
|
if (n >= MAX_COPY_INDEX) {
|
|
2329
2330
|
skipped.push(name);
|
|
@@ -2339,7 +2340,30 @@ async function processUploadedFiles(formData, targetDir, projectDir) {
|
|
|
2339
2340
|
invalid.push({ name: finalName, reason: validation.reason });
|
|
2340
2341
|
continue;
|
|
2341
2342
|
}
|
|
2342
|
-
|
|
2343
|
+
let written = false;
|
|
2344
|
+
while (n < MAX_COPY_INDEX && isSafePath(projectDir, finalPath)) {
|
|
2345
|
+
try {
|
|
2346
|
+
const fd = openSync(finalPath, "wx");
|
|
2347
|
+
try {
|
|
2348
|
+
writeFileSync4(fd, buffer);
|
|
2349
|
+
} finally {
|
|
2350
|
+
closeSync(fd);
|
|
2351
|
+
}
|
|
2352
|
+
written = true;
|
|
2353
|
+
break;
|
|
2354
|
+
} catch (error) {
|
|
2355
|
+
if (!(error instanceof Error) || !("code" in error) || error.code !== "EEXIST") {
|
|
2356
|
+
throw error;
|
|
2357
|
+
}
|
|
2358
|
+
n++;
|
|
2359
|
+
finalName = `${base} (${n})${ext}`;
|
|
2360
|
+
finalPath = resolve3(targetDir, finalName);
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
if (!written) {
|
|
2364
|
+
if (n >= MAX_COPY_INDEX) skipped.push(name);
|
|
2365
|
+
continue;
|
|
2366
|
+
}
|
|
2343
2367
|
const relativePath = subDir ? join6(subDir, finalName) : finalName;
|
|
2344
2368
|
uploaded.push(relativePath);
|
|
2345
2369
|
if (isAudioFile(finalName)) {
|