@gallop.software/studio 0.1.108 → 0.1.110

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.
@@ -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 (e6) {
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 (e7) {
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 (e8) {
428
+ } catch (e9) {
406
429
  thumbnail = key;
407
430
  hasThumbnail = false;
408
431
  }
@@ -448,6 +471,21 @@ async function handleListFolders() {
448
471
  folderSet.add(current);
449
472
  }
450
473
  }
474
+ async function scanDir(dir, relativePath) {
475
+ try {
476
+ const entries = await _fs.promises.readdir(dir, { withFileTypes: true });
477
+ for (const entry of entries) {
478
+ if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "images") {
479
+ const folderRelPath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
480
+ folderSet.add(folderRelPath);
481
+ await scanDir(_path2.default.join(dir, entry.name), folderRelPath);
482
+ }
483
+ }
484
+ } catch (e10) {
485
+ }
486
+ }
487
+ const publicDir = _path2.default.join(process.cwd(), "public");
488
+ await scanDir(publicDir, "");
451
489
  const folders = [];
452
490
  folders.push({ path: "public", name: "public", depth: 0 });
453
491
  const sortedFolders = Array.from(folderSet).sort();
@@ -584,7 +622,7 @@ async function handleUpload(request) {
584
622
  w: metadata.width || 0,
585
623
  h: metadata.height || 0
586
624
  };
587
- } catch (e9) {
625
+ } catch (e11) {
588
626
  meta[imageKey] = { w: 0, h: 0 };
589
627
  }
590
628
  } else {
@@ -633,7 +671,7 @@ async function handleDelete(request) {
633
671
  const absoluteThumbPath = _path2.default.join(process.cwd(), "public", thumbPath);
634
672
  try {
635
673
  await _fs.promises.unlink(absoluteThumbPath);
636
- } catch (e10) {
674
+ } catch (e12) {
637
675
  }
638
676
  }
639
677
  }
@@ -649,14 +687,14 @@ async function handleDelete(request) {
649
687
  const absoluteThumbPath = _path2.default.join(process.cwd(), "public", thumbPath);
650
688
  try {
651
689
  await _fs.promises.unlink(absoluteThumbPath);
652
- } catch (e11) {
690
+ } catch (e13) {
653
691
  }
654
692
  }
655
693
  }
656
694
  delete meta[imageKey];
657
695
  }
658
696
  }
659
- } catch (e12) {
697
+ } catch (e14) {
660
698
  if (entry) {
661
699
  delete meta[imageKey];
662
700
  } else {
@@ -709,7 +747,7 @@ async function handleCreateFolder(request) {
709
747
  try {
710
748
  await _fs.promises.access(folderPath);
711
749
  return _server.NextResponse.json({ error: "A folder with this name already exists" }, { status: 400 });
712
- } catch (e13) {
750
+ } catch (e15) {
713
751
  }
714
752
  await _fs.promises.mkdir(folderPath, { recursive: true });
715
753
  return _server.NextResponse.json({ success: true, path: _path2.default.join(safePath, sanitizedName) });
@@ -737,13 +775,13 @@ async function handleRename(request) {
737
775
  }
738
776
  try {
739
777
  await _fs.promises.access(absoluteOldPath);
740
- } catch (e14) {
778
+ } catch (e16) {
741
779
  return _server.NextResponse.json({ error: "File or folder not found" }, { status: 404 });
742
780
  }
743
781
  try {
744
782
  await _fs.promises.access(absoluteNewPath);
745
783
  return _server.NextResponse.json({ error: "An item with this name already exists" }, { status: 400 });
746
- } catch (e15) {
784
+ } catch (e17) {
747
785
  }
748
786
  const stats = await _fs.promises.stat(absoluteOldPath);
749
787
  const isFile = stats.isFile();
@@ -765,7 +803,7 @@ async function handleRename(request) {
765
803
  await _fs.promises.mkdir(_path2.default.dirname(newThumbPath), { recursive: true });
766
804
  try {
767
805
  await _fs.promises.rename(oldThumbPath, newThumbPath);
768
- } catch (e16) {
806
+ } catch (e18) {
769
807
  }
770
808
  }
771
809
  delete meta[oldKey];
@@ -880,7 +918,7 @@ async function handleMoveStream(request) {
880
918
  await deleteFromCdn(oldKey, hasProcessedThumbnails);
881
919
  try {
882
920
  await _fs.promises.unlink(newAbsolutePath);
883
- } catch (e17) {
921
+ } catch (e19) {
884
922
  }
885
923
  if (hasProcessedThumbnails) {
886
924
  await deleteLocalThumbnails(newKey);
@@ -897,7 +935,7 @@ async function handleMoveStream(request) {
897
935
  }
898
936
  try {
899
937
  await _fs.promises.access(absolutePath);
900
- } catch (e18) {
938
+ } catch (e20) {
901
939
  errors.push(`${itemName} not found`);
902
940
  continue;
903
941
  }
@@ -905,7 +943,7 @@ async function handleMoveStream(request) {
905
943
  await _fs.promises.access(newAbsolutePath);
906
944
  errors.push(`${itemName} already exists in destination`);
907
945
  continue;
908
- } catch (e19) {
946
+ } catch (e21) {
909
947
  }
910
948
  await _fs.promises.rename(absolutePath, newAbsolutePath);
911
949
  const stats = await _fs.promises.stat(newAbsolutePath);
@@ -918,7 +956,7 @@ async function handleMoveStream(request) {
918
956
  await _fs.promises.mkdir(_path2.default.dirname(newThumbPath), { recursive: true });
919
957
  try {
920
958
  await _fs.promises.rename(oldThumbPath, newThumbPath);
921
- } catch (e20) {
959
+ } catch (e22) {
922
960
  }
923
961
  }
924
962
  delete meta[oldKey];
@@ -1038,7 +1076,7 @@ async function handleSync(request) {
1038
1076
  ContentType: getContentType(thumbPath)
1039
1077
  })
1040
1078
  );
1041
- } catch (e21) {
1079
+ } catch (e23) {
1042
1080
  }
1043
1081
  }
1044
1082
  entry.c = cdnIndex;
@@ -1046,12 +1084,12 @@ async function handleSync(request) {
1046
1084
  const localPath = _path2.default.join(process.cwd(), "public", thumbPath);
1047
1085
  try {
1048
1086
  await _fs.promises.unlink(localPath);
1049
- } catch (e22) {
1087
+ } catch (e24) {
1050
1088
  }
1051
1089
  }
1052
1090
  try {
1053
1091
  await _fs.promises.unlink(originalLocalPath);
1054
- } catch (e23) {
1092
+ } catch (e25) {
1055
1093
  }
1056
1094
  pushed.push(imageKey);
1057
1095
  } catch (error) {
@@ -1088,7 +1126,7 @@ async function handleReprocess(request) {
1088
1126
  const originalPath = _path2.default.join(process.cwd(), "public", imageKey);
1089
1127
  try {
1090
1128
  buffer = await _fs.promises.readFile(originalPath);
1091
- } catch (e24) {
1129
+ } catch (e26) {
1092
1130
  if (isPushedToCloud) {
1093
1131
  buffer = await downloadFromCdn(imageKey);
1094
1132
  const dir = _path2.default.dirname(originalPath);
@@ -1105,7 +1143,7 @@ async function handleReprocess(request) {
1105
1143
  await deleteLocalThumbnails(imageKey);
1106
1144
  try {
1107
1145
  await _fs.promises.unlink(originalPath);
1108
- } catch (e25) {
1146
+ } catch (e27) {
1109
1147
  }
1110
1148
  }
1111
1149
  meta[imageKey] = updatedEntry;
@@ -1205,7 +1243,7 @@ async function handleProcessAllStream() {
1205
1243
  await deleteLocalThumbnails(key);
1206
1244
  try {
1207
1245
  await _fs.promises.unlink(fullPath);
1208
- } catch (e26) {
1246
+ } catch (e28) {
1209
1247
  }
1210
1248
  }
1211
1249
  processed.push(key.slice(1));
@@ -1244,13 +1282,13 @@ async function handleProcessAllStream() {
1244
1282
  }
1245
1283
  }
1246
1284
  }
1247
- } catch (e27) {
1285
+ } catch (e29) {
1248
1286
  }
1249
1287
  }
1250
1288
  const imagesDir = _path2.default.join(process.cwd(), "public", "images");
1251
1289
  try {
1252
1290
  await findOrphans(imagesDir);
1253
- } catch (e28) {
1291
+ } catch (e30) {
1254
1292
  }
1255
1293
  async function removeEmptyDirs(dir) {
1256
1294
  try {
@@ -1268,13 +1306,13 @@ async function handleProcessAllStream() {
1268
1306
  await _fs.promises.rmdir(dir);
1269
1307
  }
1270
1308
  return isEmpty;
1271
- } catch (e29) {
1309
+ } catch (e31) {
1272
1310
  return true;
1273
1311
  }
1274
1312
  }
1275
1313
  try {
1276
1314
  await removeEmptyDirs(imagesDir);
1277
- } catch (e30) {
1315
+ } catch (e32) {
1278
1316
  }
1279
1317
  await saveMeta(meta);
1280
1318
  sendEvent({
@@ -1337,7 +1375,7 @@ async function handleScanStream() {
1337
1375
  allFiles.push({ relativePath: relPath, fullPath });
1338
1376
  }
1339
1377
  }
1340
- } catch (e31) {
1378
+ } catch (e33) {
1341
1379
  }
1342
1380
  }
1343
1381
  const publicDir = _path2.default.join(process.cwd(), "public");
@@ -1397,7 +1435,7 @@ async function handleScanStream() {
1397
1435
  h: metadata.height || 0,
1398
1436
  b: blurhash
1399
1437
  };
1400
- } catch (e32) {
1438
+ } catch (e34) {
1401
1439
  meta[imageKey] = { w: 0, h: 0 };
1402
1440
  }
1403
1441
  }