@gallop.software/studio 0.1.108 → 0.1.109
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/handlers/index.js
CHANGED
|
@@ -270,14 +270,37 @@ async function handleList(request) {
|
|
|
270
270
|
const fileEntries = getFileEntries(meta);
|
|
271
271
|
const cdnUrls = getCdnUrls(meta);
|
|
272
272
|
const r2PublicUrl = _optionalChain([process, 'access', _ => _.env, 'access', _2 => _2.CLOUDFLARE_R2_PUBLIC_URL, 'optionalAccess', _3 => _3.replace, 'call', _4 => _4(/\/$/, "")]) || "";
|
|
273
|
-
if (fileEntries.length === 0) {
|
|
274
|
-
return _server.NextResponse.json({ items: [], isEmpty: true });
|
|
275
|
-
}
|
|
276
273
|
const relativePath = requestedPath.replace(/^public\/?/, "");
|
|
277
274
|
const pathPrefix = relativePath ? `/${relativePath}/` : "/";
|
|
278
275
|
const items = [];
|
|
279
276
|
const seenFolders = /* @__PURE__ */ new Set();
|
|
280
277
|
const metaKeys = fileEntries.map(([key]) => key);
|
|
278
|
+
const absoluteDir = _path2.default.join(process.cwd(), requestedPath);
|
|
279
|
+
try {
|
|
280
|
+
const dirEntries = await _fs.promises.readdir(absoluteDir, { withFileTypes: true });
|
|
281
|
+
for (const entry of dirEntries) {
|
|
282
|
+
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "images") {
|
|
283
|
+
if (!seenFolders.has(entry.name)) {
|
|
284
|
+
seenFolders.add(entry.name);
|
|
285
|
+
const folderPrefix = pathPrefix === "/" ? `/${entry.name}/` : `${pathPrefix}${entry.name}/`;
|
|
286
|
+
let fileCount = 0;
|
|
287
|
+
for (const k of metaKeys) {
|
|
288
|
+
if (k.startsWith(folderPrefix)) fileCount++;
|
|
289
|
+
}
|
|
290
|
+
items.push({
|
|
291
|
+
name: entry.name,
|
|
292
|
+
path: relativePath ? `public/${relativePath}/${entry.name}` : `public/${entry.name}`,
|
|
293
|
+
type: "folder",
|
|
294
|
+
fileCount
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
} catch (e6) {
|
|
300
|
+
}
|
|
301
|
+
if (fileEntries.length === 0 && items.length === 0) {
|
|
302
|
+
return _server.NextResponse.json({ items: [], isEmpty: true });
|
|
303
|
+
}
|
|
281
304
|
for (const [key, entry] of fileEntries) {
|
|
282
305
|
if (!key.startsWith(pathPrefix) && pathPrefix !== "/") continue;
|
|
283
306
|
if (pathPrefix === "/" && !key.startsWith("/")) continue;
|
|
@@ -323,7 +346,7 @@ async function handleList(request) {
|
|
|
323
346
|
await _fs.promises.access(localThumbPath);
|
|
324
347
|
thumbnail = thumbPath;
|
|
325
348
|
hasThumbnail = true;
|
|
326
|
-
} catch (
|
|
349
|
+
} catch (e7) {
|
|
327
350
|
thumbnail = key;
|
|
328
351
|
hasThumbnail = false;
|
|
329
352
|
}
|
|
@@ -342,7 +365,7 @@ async function handleList(request) {
|
|
|
342
365
|
const filePath = _path2.default.join(process.cwd(), "public", key);
|
|
343
366
|
const stats = await _fs.promises.stat(filePath);
|
|
344
367
|
fileSize = stats.size;
|
|
345
|
-
} catch (
|
|
368
|
+
} catch (e8) {
|
|
346
369
|
}
|
|
347
370
|
}
|
|
348
371
|
items.push({
|
|
@@ -402,7 +425,7 @@ async function handleSearch(request) {
|
|
|
402
425
|
await _fs.promises.access(localThumbPath);
|
|
403
426
|
thumbnail = thumbPath;
|
|
404
427
|
hasThumbnail = true;
|
|
405
|
-
} catch (
|
|
428
|
+
} catch (e9) {
|
|
406
429
|
thumbnail = key;
|
|
407
430
|
hasThumbnail = false;
|
|
408
431
|
}
|
|
@@ -584,7 +607,7 @@ async function handleUpload(request) {
|
|
|
584
607
|
w: metadata.width || 0,
|
|
585
608
|
h: metadata.height || 0
|
|
586
609
|
};
|
|
587
|
-
} catch (
|
|
610
|
+
} catch (e10) {
|
|
588
611
|
meta[imageKey] = { w: 0, h: 0 };
|
|
589
612
|
}
|
|
590
613
|
} else {
|
|
@@ -633,7 +656,7 @@ async function handleDelete(request) {
|
|
|
633
656
|
const absoluteThumbPath = _path2.default.join(process.cwd(), "public", thumbPath);
|
|
634
657
|
try {
|
|
635
658
|
await _fs.promises.unlink(absoluteThumbPath);
|
|
636
|
-
} catch (
|
|
659
|
+
} catch (e11) {
|
|
637
660
|
}
|
|
638
661
|
}
|
|
639
662
|
}
|
|
@@ -649,14 +672,14 @@ async function handleDelete(request) {
|
|
|
649
672
|
const absoluteThumbPath = _path2.default.join(process.cwd(), "public", thumbPath);
|
|
650
673
|
try {
|
|
651
674
|
await _fs.promises.unlink(absoluteThumbPath);
|
|
652
|
-
} catch (
|
|
675
|
+
} catch (e12) {
|
|
653
676
|
}
|
|
654
677
|
}
|
|
655
678
|
}
|
|
656
679
|
delete meta[imageKey];
|
|
657
680
|
}
|
|
658
681
|
}
|
|
659
|
-
} catch (
|
|
682
|
+
} catch (e13) {
|
|
660
683
|
if (entry) {
|
|
661
684
|
delete meta[imageKey];
|
|
662
685
|
} else {
|
|
@@ -709,7 +732,7 @@ async function handleCreateFolder(request) {
|
|
|
709
732
|
try {
|
|
710
733
|
await _fs.promises.access(folderPath);
|
|
711
734
|
return _server.NextResponse.json({ error: "A folder with this name already exists" }, { status: 400 });
|
|
712
|
-
} catch (
|
|
735
|
+
} catch (e14) {
|
|
713
736
|
}
|
|
714
737
|
await _fs.promises.mkdir(folderPath, { recursive: true });
|
|
715
738
|
return _server.NextResponse.json({ success: true, path: _path2.default.join(safePath, sanitizedName) });
|
|
@@ -737,13 +760,13 @@ async function handleRename(request) {
|
|
|
737
760
|
}
|
|
738
761
|
try {
|
|
739
762
|
await _fs.promises.access(absoluteOldPath);
|
|
740
|
-
} catch (
|
|
763
|
+
} catch (e15) {
|
|
741
764
|
return _server.NextResponse.json({ error: "File or folder not found" }, { status: 404 });
|
|
742
765
|
}
|
|
743
766
|
try {
|
|
744
767
|
await _fs.promises.access(absoluteNewPath);
|
|
745
768
|
return _server.NextResponse.json({ error: "An item with this name already exists" }, { status: 400 });
|
|
746
|
-
} catch (
|
|
769
|
+
} catch (e16) {
|
|
747
770
|
}
|
|
748
771
|
const stats = await _fs.promises.stat(absoluteOldPath);
|
|
749
772
|
const isFile = stats.isFile();
|
|
@@ -765,7 +788,7 @@ async function handleRename(request) {
|
|
|
765
788
|
await _fs.promises.mkdir(_path2.default.dirname(newThumbPath), { recursive: true });
|
|
766
789
|
try {
|
|
767
790
|
await _fs.promises.rename(oldThumbPath, newThumbPath);
|
|
768
|
-
} catch (
|
|
791
|
+
} catch (e17) {
|
|
769
792
|
}
|
|
770
793
|
}
|
|
771
794
|
delete meta[oldKey];
|
|
@@ -880,7 +903,7 @@ async function handleMoveStream(request) {
|
|
|
880
903
|
await deleteFromCdn(oldKey, hasProcessedThumbnails);
|
|
881
904
|
try {
|
|
882
905
|
await _fs.promises.unlink(newAbsolutePath);
|
|
883
|
-
} catch (
|
|
906
|
+
} catch (e18) {
|
|
884
907
|
}
|
|
885
908
|
if (hasProcessedThumbnails) {
|
|
886
909
|
await deleteLocalThumbnails(newKey);
|
|
@@ -897,7 +920,7 @@ async function handleMoveStream(request) {
|
|
|
897
920
|
}
|
|
898
921
|
try {
|
|
899
922
|
await _fs.promises.access(absolutePath);
|
|
900
|
-
} catch (
|
|
923
|
+
} catch (e19) {
|
|
901
924
|
errors.push(`${itemName} not found`);
|
|
902
925
|
continue;
|
|
903
926
|
}
|
|
@@ -905,7 +928,7 @@ async function handleMoveStream(request) {
|
|
|
905
928
|
await _fs.promises.access(newAbsolutePath);
|
|
906
929
|
errors.push(`${itemName} already exists in destination`);
|
|
907
930
|
continue;
|
|
908
|
-
} catch (
|
|
931
|
+
} catch (e20) {
|
|
909
932
|
}
|
|
910
933
|
await _fs.promises.rename(absolutePath, newAbsolutePath);
|
|
911
934
|
const stats = await _fs.promises.stat(newAbsolutePath);
|
|
@@ -918,7 +941,7 @@ async function handleMoveStream(request) {
|
|
|
918
941
|
await _fs.promises.mkdir(_path2.default.dirname(newThumbPath), { recursive: true });
|
|
919
942
|
try {
|
|
920
943
|
await _fs.promises.rename(oldThumbPath, newThumbPath);
|
|
921
|
-
} catch (
|
|
944
|
+
} catch (e21) {
|
|
922
945
|
}
|
|
923
946
|
}
|
|
924
947
|
delete meta[oldKey];
|
|
@@ -1038,7 +1061,7 @@ async function handleSync(request) {
|
|
|
1038
1061
|
ContentType: getContentType(thumbPath)
|
|
1039
1062
|
})
|
|
1040
1063
|
);
|
|
1041
|
-
} catch (
|
|
1064
|
+
} catch (e22) {
|
|
1042
1065
|
}
|
|
1043
1066
|
}
|
|
1044
1067
|
entry.c = cdnIndex;
|
|
@@ -1046,12 +1069,12 @@ async function handleSync(request) {
|
|
|
1046
1069
|
const localPath = _path2.default.join(process.cwd(), "public", thumbPath);
|
|
1047
1070
|
try {
|
|
1048
1071
|
await _fs.promises.unlink(localPath);
|
|
1049
|
-
} catch (
|
|
1072
|
+
} catch (e23) {
|
|
1050
1073
|
}
|
|
1051
1074
|
}
|
|
1052
1075
|
try {
|
|
1053
1076
|
await _fs.promises.unlink(originalLocalPath);
|
|
1054
|
-
} catch (
|
|
1077
|
+
} catch (e24) {
|
|
1055
1078
|
}
|
|
1056
1079
|
pushed.push(imageKey);
|
|
1057
1080
|
} catch (error) {
|
|
@@ -1088,7 +1111,7 @@ async function handleReprocess(request) {
|
|
|
1088
1111
|
const originalPath = _path2.default.join(process.cwd(), "public", imageKey);
|
|
1089
1112
|
try {
|
|
1090
1113
|
buffer = await _fs.promises.readFile(originalPath);
|
|
1091
|
-
} catch (
|
|
1114
|
+
} catch (e25) {
|
|
1092
1115
|
if (isPushedToCloud) {
|
|
1093
1116
|
buffer = await downloadFromCdn(imageKey);
|
|
1094
1117
|
const dir = _path2.default.dirname(originalPath);
|
|
@@ -1105,7 +1128,7 @@ async function handleReprocess(request) {
|
|
|
1105
1128
|
await deleteLocalThumbnails(imageKey);
|
|
1106
1129
|
try {
|
|
1107
1130
|
await _fs.promises.unlink(originalPath);
|
|
1108
|
-
} catch (
|
|
1131
|
+
} catch (e26) {
|
|
1109
1132
|
}
|
|
1110
1133
|
}
|
|
1111
1134
|
meta[imageKey] = updatedEntry;
|
|
@@ -1205,7 +1228,7 @@ async function handleProcessAllStream() {
|
|
|
1205
1228
|
await deleteLocalThumbnails(key);
|
|
1206
1229
|
try {
|
|
1207
1230
|
await _fs.promises.unlink(fullPath);
|
|
1208
|
-
} catch (
|
|
1231
|
+
} catch (e27) {
|
|
1209
1232
|
}
|
|
1210
1233
|
}
|
|
1211
1234
|
processed.push(key.slice(1));
|
|
@@ -1244,13 +1267,13 @@ async function handleProcessAllStream() {
|
|
|
1244
1267
|
}
|
|
1245
1268
|
}
|
|
1246
1269
|
}
|
|
1247
|
-
} catch (
|
|
1270
|
+
} catch (e28) {
|
|
1248
1271
|
}
|
|
1249
1272
|
}
|
|
1250
1273
|
const imagesDir = _path2.default.join(process.cwd(), "public", "images");
|
|
1251
1274
|
try {
|
|
1252
1275
|
await findOrphans(imagesDir);
|
|
1253
|
-
} catch (
|
|
1276
|
+
} catch (e29) {
|
|
1254
1277
|
}
|
|
1255
1278
|
async function removeEmptyDirs(dir) {
|
|
1256
1279
|
try {
|
|
@@ -1268,13 +1291,13 @@ async function handleProcessAllStream() {
|
|
|
1268
1291
|
await _fs.promises.rmdir(dir);
|
|
1269
1292
|
}
|
|
1270
1293
|
return isEmpty;
|
|
1271
|
-
} catch (
|
|
1294
|
+
} catch (e30) {
|
|
1272
1295
|
return true;
|
|
1273
1296
|
}
|
|
1274
1297
|
}
|
|
1275
1298
|
try {
|
|
1276
1299
|
await removeEmptyDirs(imagesDir);
|
|
1277
|
-
} catch (
|
|
1300
|
+
} catch (e31) {
|
|
1278
1301
|
}
|
|
1279
1302
|
await saveMeta(meta);
|
|
1280
1303
|
sendEvent({
|
|
@@ -1337,7 +1360,7 @@ async function handleScanStream() {
|
|
|
1337
1360
|
allFiles.push({ relativePath: relPath, fullPath });
|
|
1338
1361
|
}
|
|
1339
1362
|
}
|
|
1340
|
-
} catch (
|
|
1363
|
+
} catch (e32) {
|
|
1341
1364
|
}
|
|
1342
1365
|
}
|
|
1343
1366
|
const publicDir = _path2.default.join(process.cwd(), "public");
|
|
@@ -1397,7 +1420,7 @@ async function handleScanStream() {
|
|
|
1397
1420
|
h: metadata.height || 0,
|
|
1398
1421
|
b: blurhash
|
|
1399
1422
|
};
|
|
1400
|
-
} catch (
|
|
1423
|
+
} catch (e33) {
|
|
1401
1424
|
meta[imageKey] = { w: 0, h: 0 };
|
|
1402
1425
|
}
|
|
1403
1426
|
}
|