@gallop.software/studio 1.0.0 → 1.0.1
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
|
@@ -314,15 +314,25 @@ async function handleList(request) {
|
|
|
314
314
|
try {
|
|
315
315
|
const dirEntries = await _fs.promises.readdir(absoluteDir, { withFileTypes: true });
|
|
316
316
|
for (const entry of dirEntries) {
|
|
317
|
-
if (entry.
|
|
317
|
+
if (entry.name.startsWith(".")) continue;
|
|
318
|
+
if (entry.isDirectory()) {
|
|
318
319
|
if (!seenFolders.has(entry.name)) {
|
|
319
320
|
seenFolders.add(entry.name);
|
|
320
321
|
const isImagesFolder = entry.name === "images" && !relativePath;
|
|
321
322
|
const folderPath = relativePath ? `public/${relativePath}/${entry.name}` : `public/${entry.name}`;
|
|
322
|
-
const folderPrefix = pathPrefix === "/" ? `/${entry.name}/` : `${pathPrefix}${entry.name}/`;
|
|
323
323
|
let fileCount = 0;
|
|
324
|
-
|
|
325
|
-
|
|
324
|
+
if (isInsideImagesFolder || isImagesFolder) {
|
|
325
|
+
const subDir = _path2.default.join(absoluteDir, entry.name);
|
|
326
|
+
try {
|
|
327
|
+
const subEntries = await _fs.promises.readdir(subDir);
|
|
328
|
+
fileCount = subEntries.filter((f) => !f.startsWith(".")).length;
|
|
329
|
+
} catch (e6) {
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
const folderPrefix = pathPrefix === "/" ? `/${entry.name}/` : `${pathPrefix}${entry.name}/`;
|
|
333
|
+
for (const k of metaKeys) {
|
|
334
|
+
if (k.startsWith(folderPrefix)) fileCount++;
|
|
335
|
+
}
|
|
326
336
|
}
|
|
327
337
|
items.push({
|
|
328
338
|
name: entry.name,
|
|
@@ -332,9 +342,28 @@ async function handleList(request) {
|
|
|
332
342
|
isProtected: isImagesFolder || isInsideImagesFolder
|
|
333
343
|
});
|
|
334
344
|
}
|
|
345
|
+
} else if (isInsideImagesFolder) {
|
|
346
|
+
const filePath = relativePath ? `public/${relativePath}/${entry.name}` : `public/${entry.name}`;
|
|
347
|
+
const fullPath = _path2.default.join(absoluteDir, entry.name);
|
|
348
|
+
let fileSize;
|
|
349
|
+
try {
|
|
350
|
+
const stats = await _fs.promises.stat(fullPath);
|
|
351
|
+
fileSize = stats.size;
|
|
352
|
+
} catch (e7) {
|
|
353
|
+
}
|
|
354
|
+
const isImage = isImageFile(entry.name);
|
|
355
|
+
items.push({
|
|
356
|
+
name: entry.name,
|
|
357
|
+
path: filePath,
|
|
358
|
+
type: "file",
|
|
359
|
+
size: fileSize,
|
|
360
|
+
thumbnail: isImage ? `/${relativePath}/${entry.name}` : void 0,
|
|
361
|
+
hasThumbnail: false,
|
|
362
|
+
isProtected: true
|
|
363
|
+
});
|
|
335
364
|
}
|
|
336
365
|
}
|
|
337
|
-
} catch (
|
|
366
|
+
} catch (e8) {
|
|
338
367
|
}
|
|
339
368
|
if (fileEntries.length === 0 && items.length === 0) {
|
|
340
369
|
return _server.NextResponse.json({ items: [], isEmpty: true });
|
|
@@ -385,7 +414,7 @@ async function handleList(request) {
|
|
|
385
414
|
await _fs.promises.access(localThumbPath);
|
|
386
415
|
thumbnail = thumbPath;
|
|
387
416
|
hasThumbnail = true;
|
|
388
|
-
} catch (
|
|
417
|
+
} catch (e9) {
|
|
389
418
|
thumbnail = key;
|
|
390
419
|
hasThumbnail = false;
|
|
391
420
|
}
|
|
@@ -404,7 +433,7 @@ async function handleList(request) {
|
|
|
404
433
|
const filePath = _path2.default.join(process.cwd(), "public", key);
|
|
405
434
|
const stats = await _fs.promises.stat(filePath);
|
|
406
435
|
fileSize = stats.size;
|
|
407
|
-
} catch (
|
|
436
|
+
} catch (e10) {
|
|
408
437
|
}
|
|
409
438
|
}
|
|
410
439
|
items.push({
|
|
@@ -465,7 +494,7 @@ async function handleSearch(request) {
|
|
|
465
494
|
await _fs.promises.access(localThumbPath);
|
|
466
495
|
thumbnail = thumbPath;
|
|
467
496
|
hasThumbnail = true;
|
|
468
|
-
} catch (
|
|
497
|
+
} catch (e11) {
|
|
469
498
|
thumbnail = key;
|
|
470
499
|
hasThumbnail = false;
|
|
471
500
|
}
|
|
@@ -521,7 +550,7 @@ async function handleListFolders() {
|
|
|
521
550
|
await scanDir(_path2.default.join(dir, entry.name), folderRelPath);
|
|
522
551
|
}
|
|
523
552
|
}
|
|
524
|
-
} catch (
|
|
553
|
+
} catch (e12) {
|
|
525
554
|
}
|
|
526
555
|
}
|
|
527
556
|
const publicDir = _path2.default.join(process.cwd(), "public");
|
|
@@ -662,7 +691,7 @@ async function handleUpload(request) {
|
|
|
662
691
|
w: metadata.width || 0,
|
|
663
692
|
h: metadata.height || 0
|
|
664
693
|
};
|
|
665
|
-
} catch (
|
|
694
|
+
} catch (e13) {
|
|
666
695
|
meta[imageKey] = { w: 0, h: 0 };
|
|
667
696
|
}
|
|
668
697
|
} else {
|
|
@@ -711,7 +740,7 @@ async function handleDelete(request) {
|
|
|
711
740
|
const absoluteThumbPath = _path2.default.join(process.cwd(), "public", thumbPath);
|
|
712
741
|
try {
|
|
713
742
|
await _fs.promises.unlink(absoluteThumbPath);
|
|
714
|
-
} catch (
|
|
743
|
+
} catch (e14) {
|
|
715
744
|
}
|
|
716
745
|
}
|
|
717
746
|
}
|
|
@@ -727,14 +756,14 @@ async function handleDelete(request) {
|
|
|
727
756
|
const absoluteThumbPath = _path2.default.join(process.cwd(), "public", thumbPath);
|
|
728
757
|
try {
|
|
729
758
|
await _fs.promises.unlink(absoluteThumbPath);
|
|
730
|
-
} catch (
|
|
759
|
+
} catch (e15) {
|
|
731
760
|
}
|
|
732
761
|
}
|
|
733
762
|
}
|
|
734
763
|
delete meta[imageKey];
|
|
735
764
|
}
|
|
736
765
|
}
|
|
737
|
-
} catch (
|
|
766
|
+
} catch (e16) {
|
|
738
767
|
if (entry) {
|
|
739
768
|
delete meta[imageKey];
|
|
740
769
|
} else {
|
|
@@ -787,7 +816,7 @@ async function handleCreateFolder(request) {
|
|
|
787
816
|
try {
|
|
788
817
|
await _fs.promises.access(folderPath);
|
|
789
818
|
return _server.NextResponse.json({ error: "A folder with this name already exists" }, { status: 400 });
|
|
790
|
-
} catch (
|
|
819
|
+
} catch (e17) {
|
|
791
820
|
}
|
|
792
821
|
await _fs.promises.mkdir(folderPath, { recursive: true });
|
|
793
822
|
return _server.NextResponse.json({ success: true, path: _path2.default.join(safePath, sanitizedName) });
|
|
@@ -815,13 +844,13 @@ async function handleRename(request) {
|
|
|
815
844
|
}
|
|
816
845
|
try {
|
|
817
846
|
await _fs.promises.access(absoluteOldPath);
|
|
818
|
-
} catch (
|
|
847
|
+
} catch (e18) {
|
|
819
848
|
return _server.NextResponse.json({ error: "File or folder not found" }, { status: 404 });
|
|
820
849
|
}
|
|
821
850
|
try {
|
|
822
851
|
await _fs.promises.access(absoluteNewPath);
|
|
823
852
|
return _server.NextResponse.json({ error: "An item with this name already exists" }, { status: 400 });
|
|
824
|
-
} catch (
|
|
853
|
+
} catch (e19) {
|
|
825
854
|
}
|
|
826
855
|
const stats = await _fs.promises.stat(absoluteOldPath);
|
|
827
856
|
const isFile = stats.isFile();
|
|
@@ -843,7 +872,7 @@ async function handleRename(request) {
|
|
|
843
872
|
await _fs.promises.mkdir(_path2.default.dirname(newThumbPath), { recursive: true });
|
|
844
873
|
try {
|
|
845
874
|
await _fs.promises.rename(oldThumbPath, newThumbPath);
|
|
846
|
-
} catch (
|
|
875
|
+
} catch (e20) {
|
|
847
876
|
}
|
|
848
877
|
}
|
|
849
878
|
delete meta[oldKey];
|
|
@@ -958,7 +987,7 @@ async function handleMoveStream(request) {
|
|
|
958
987
|
await deleteFromCdn(oldKey, hasProcessedThumbnails);
|
|
959
988
|
try {
|
|
960
989
|
await _fs.promises.unlink(newAbsolutePath);
|
|
961
|
-
} catch (
|
|
990
|
+
} catch (e21) {
|
|
962
991
|
}
|
|
963
992
|
if (hasProcessedThumbnails) {
|
|
964
993
|
await deleteLocalThumbnails(newKey);
|
|
@@ -975,7 +1004,7 @@ async function handleMoveStream(request) {
|
|
|
975
1004
|
}
|
|
976
1005
|
try {
|
|
977
1006
|
await _fs.promises.access(absolutePath);
|
|
978
|
-
} catch (
|
|
1007
|
+
} catch (e22) {
|
|
979
1008
|
errors.push(`${itemName} not found`);
|
|
980
1009
|
continue;
|
|
981
1010
|
}
|
|
@@ -983,7 +1012,7 @@ async function handleMoveStream(request) {
|
|
|
983
1012
|
await _fs.promises.access(newAbsolutePath);
|
|
984
1013
|
errors.push(`${itemName} already exists in destination`);
|
|
985
1014
|
continue;
|
|
986
|
-
} catch (
|
|
1015
|
+
} catch (e23) {
|
|
987
1016
|
}
|
|
988
1017
|
await _fs.promises.rename(absolutePath, newAbsolutePath);
|
|
989
1018
|
const stats = await _fs.promises.stat(newAbsolutePath);
|
|
@@ -996,7 +1025,7 @@ async function handleMoveStream(request) {
|
|
|
996
1025
|
await _fs.promises.mkdir(_path2.default.dirname(newThumbPath), { recursive: true });
|
|
997
1026
|
try {
|
|
998
1027
|
await _fs.promises.rename(oldThumbPath, newThumbPath);
|
|
999
|
-
} catch (
|
|
1028
|
+
} catch (e24) {
|
|
1000
1029
|
}
|
|
1001
1030
|
}
|
|
1002
1031
|
delete meta[oldKey];
|
|
@@ -1098,7 +1127,7 @@ async function handleSync(request) {
|
|
|
1098
1127
|
const originalLocalPath = _path2.default.join(process.cwd(), "public", imageKey);
|
|
1099
1128
|
try {
|
|
1100
1129
|
originalBuffer = await _fs.promises.readFile(originalLocalPath);
|
|
1101
|
-
} catch (
|
|
1130
|
+
} catch (e25) {
|
|
1102
1131
|
errors.push(`Original file not found: ${imageKey}`);
|
|
1103
1132
|
continue;
|
|
1104
1133
|
}
|
|
@@ -1126,7 +1155,7 @@ async function handleSync(request) {
|
|
|
1126
1155
|
})
|
|
1127
1156
|
);
|
|
1128
1157
|
urlsToPurge.push(`${publicUrl}${thumbPath}`);
|
|
1129
|
-
} catch (
|
|
1158
|
+
} catch (e26) {
|
|
1130
1159
|
}
|
|
1131
1160
|
}
|
|
1132
1161
|
}
|
|
@@ -1137,12 +1166,12 @@ async function handleSync(request) {
|
|
|
1137
1166
|
const localPath = _path2.default.join(process.cwd(), "public", thumbPath);
|
|
1138
1167
|
try {
|
|
1139
1168
|
await _fs.promises.unlink(localPath);
|
|
1140
|
-
} catch (
|
|
1169
|
+
} catch (e27) {
|
|
1141
1170
|
}
|
|
1142
1171
|
}
|
|
1143
1172
|
try {
|
|
1144
1173
|
await _fs.promises.unlink(originalLocalPath);
|
|
1145
|
-
} catch (
|
|
1174
|
+
} catch (e28) {
|
|
1146
1175
|
}
|
|
1147
1176
|
}
|
|
1148
1177
|
pushed.push(imageKey);
|
|
@@ -1188,7 +1217,7 @@ async function handleReprocess(request) {
|
|
|
1188
1217
|
const originalPath = _path2.default.join(process.cwd(), "public", imageKey);
|
|
1189
1218
|
try {
|
|
1190
1219
|
buffer = await _fs.promises.readFile(originalPath);
|
|
1191
|
-
} catch (
|
|
1220
|
+
} catch (e29) {
|
|
1192
1221
|
if (isInOurR2) {
|
|
1193
1222
|
buffer = await downloadFromCdn(imageKey);
|
|
1194
1223
|
const dir = _path2.default.dirname(originalPath);
|
|
@@ -1214,7 +1243,7 @@ async function handleReprocess(request) {
|
|
|
1214
1243
|
await deleteLocalThumbnails(imageKey);
|
|
1215
1244
|
try {
|
|
1216
1245
|
await _fs.promises.unlink(originalPath);
|
|
1217
|
-
} catch (
|
|
1246
|
+
} catch (e30) {
|
|
1218
1247
|
}
|
|
1219
1248
|
} else if (isRemote) {
|
|
1220
1249
|
}
|
|
@@ -1335,7 +1364,7 @@ async function handleProcessAllStream() {
|
|
|
1335
1364
|
await deleteLocalThumbnails(key);
|
|
1336
1365
|
try {
|
|
1337
1366
|
await _fs.promises.unlink(fullPath);
|
|
1338
|
-
} catch (
|
|
1367
|
+
} catch (e31) {
|
|
1339
1368
|
}
|
|
1340
1369
|
}
|
|
1341
1370
|
processed.push(key.slice(1));
|
|
@@ -1374,13 +1403,13 @@ async function handleProcessAllStream() {
|
|
|
1374
1403
|
}
|
|
1375
1404
|
}
|
|
1376
1405
|
}
|
|
1377
|
-
} catch (
|
|
1406
|
+
} catch (e32) {
|
|
1378
1407
|
}
|
|
1379
1408
|
}
|
|
1380
1409
|
const imagesDir = _path2.default.join(process.cwd(), "public", "images");
|
|
1381
1410
|
try {
|
|
1382
1411
|
await findOrphans(imagesDir);
|
|
1383
|
-
} catch (
|
|
1412
|
+
} catch (e33) {
|
|
1384
1413
|
}
|
|
1385
1414
|
async function removeEmptyDirs(dir) {
|
|
1386
1415
|
try {
|
|
@@ -1398,13 +1427,13 @@ async function handleProcessAllStream() {
|
|
|
1398
1427
|
await _fs.promises.rmdir(dir);
|
|
1399
1428
|
}
|
|
1400
1429
|
return isEmpty;
|
|
1401
|
-
} catch (
|
|
1430
|
+
} catch (e34) {
|
|
1402
1431
|
return true;
|
|
1403
1432
|
}
|
|
1404
1433
|
}
|
|
1405
1434
|
try {
|
|
1406
1435
|
await removeEmptyDirs(imagesDir);
|
|
1407
|
-
} catch (
|
|
1436
|
+
} catch (e35) {
|
|
1408
1437
|
}
|
|
1409
1438
|
await saveMeta(meta);
|
|
1410
1439
|
if (urlsToPurge.length > 0) {
|
|
@@ -1472,7 +1501,7 @@ async function handleScanStream() {
|
|
|
1472
1501
|
allFiles.push({ relativePath: relPath, fullPath });
|
|
1473
1502
|
}
|
|
1474
1503
|
}
|
|
1475
|
-
} catch (
|
|
1504
|
+
} catch (e36) {
|
|
1476
1505
|
}
|
|
1477
1506
|
}
|
|
1478
1507
|
const publicDir = _path2.default.join(process.cwd(), "public");
|
|
@@ -1532,7 +1561,7 @@ async function handleScanStream() {
|
|
|
1532
1561
|
h: metadata.height || 0,
|
|
1533
1562
|
b: blurhash
|
|
1534
1563
|
};
|
|
1535
|
-
} catch (
|
|
1564
|
+
} catch (e37) {
|
|
1536
1565
|
meta[imageKey] = { w: 0, h: 0 };
|
|
1537
1566
|
}
|
|
1538
1567
|
}
|
|
@@ -1572,13 +1601,13 @@ async function handleScanStream() {
|
|
|
1572
1601
|
}
|
|
1573
1602
|
}
|
|
1574
1603
|
}
|
|
1575
|
-
} catch (
|
|
1604
|
+
} catch (e38) {
|
|
1576
1605
|
}
|
|
1577
1606
|
}
|
|
1578
1607
|
const imagesDir = _path2.default.join(process.cwd(), "public", "images");
|
|
1579
1608
|
try {
|
|
1580
1609
|
await findOrphans(imagesDir);
|
|
1581
|
-
} catch (
|
|
1610
|
+
} catch (e39) {
|
|
1582
1611
|
}
|
|
1583
1612
|
await saveMeta(meta);
|
|
1584
1613
|
sendEvent({
|
|
@@ -1645,13 +1674,13 @@ async function handleDeleteOrphans(request) {
|
|
|
1645
1674
|
await _fs.promises.rmdir(dir);
|
|
1646
1675
|
}
|
|
1647
1676
|
return isEmpty;
|
|
1648
|
-
} catch (
|
|
1677
|
+
} catch (e40) {
|
|
1649
1678
|
return true;
|
|
1650
1679
|
}
|
|
1651
1680
|
}
|
|
1652
1681
|
try {
|
|
1653
1682
|
await removeEmptyDirs(imagesDir);
|
|
1654
|
-
} catch (
|
|
1683
|
+
} catch (e41) {
|
|
1655
1684
|
}
|
|
1656
1685
|
return _server.NextResponse.json({
|
|
1657
1686
|
success: true,
|