@gallop.software/studio 1.0.0 → 1.0.2

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.
@@ -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.isDirectory() && !entry.name.startsWith(".")) {
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
- for (const k of metaKeys) {
325
- if (k.startsWith(folderPrefix)) fileCount++;
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 (e6) {
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 (e7) {
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 (e8) {
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 (e9) {
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 (e10) {
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 (e11) {
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 (e12) {
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 (e13) {
759
+ } catch (e15) {
731
760
  }
732
761
  }
733
762
  }
734
763
  delete meta[imageKey];
735
764
  }
736
765
  }
737
- } catch (e14) {
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 (e15) {
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 (e16) {
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 (e17) {
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 (e18) {
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 (e19) {
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 (e20) {
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 (e21) {
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 (e22) {
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 (e23) {
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 (e24) {
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 (e25) {
1169
+ } catch (e27) {
1141
1170
  }
1142
1171
  }
1143
1172
  try {
1144
1173
  await _fs.promises.unlink(originalLocalPath);
1145
- } catch (e26) {
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 (e27) {
1220
+ } catch (e29) {
1192
1221
  if (isInOurR2) {
1193
1222
  buffer = await downloadFromCdn(imageKey);
1194
1223
  const dir = _path2.default.dirname(originalPath);
@@ -1205,6 +1234,7 @@ async function handleReprocess(request) {
1205
1234
  }
1206
1235
  }
1207
1236
  const updatedEntry = await processImage(buffer, imageKey);
1237
+ updatedEntry.p = 1;
1208
1238
  if (isInOurR2) {
1209
1239
  updatedEntry.c = existingCdnIndex;
1210
1240
  await uploadToCdn(imageKey);
@@ -1214,7 +1244,7 @@ async function handleReprocess(request) {
1214
1244
  await deleteLocalThumbnails(imageKey);
1215
1245
  try {
1216
1246
  await _fs.promises.unlink(originalPath);
1217
- } catch (e28) {
1247
+ } catch (e30) {
1218
1248
  }
1219
1249
  } else if (isRemote) {
1220
1250
  }
@@ -1335,7 +1365,7 @@ async function handleProcessAllStream() {
1335
1365
  await deleteLocalThumbnails(key);
1336
1366
  try {
1337
1367
  await _fs.promises.unlink(fullPath);
1338
- } catch (e29) {
1368
+ } catch (e31) {
1339
1369
  }
1340
1370
  }
1341
1371
  processed.push(key.slice(1));
@@ -1374,13 +1404,13 @@ async function handleProcessAllStream() {
1374
1404
  }
1375
1405
  }
1376
1406
  }
1377
- } catch (e30) {
1407
+ } catch (e32) {
1378
1408
  }
1379
1409
  }
1380
1410
  const imagesDir = _path2.default.join(process.cwd(), "public", "images");
1381
1411
  try {
1382
1412
  await findOrphans(imagesDir);
1383
- } catch (e31) {
1413
+ } catch (e33) {
1384
1414
  }
1385
1415
  async function removeEmptyDirs(dir) {
1386
1416
  try {
@@ -1398,13 +1428,13 @@ async function handleProcessAllStream() {
1398
1428
  await _fs.promises.rmdir(dir);
1399
1429
  }
1400
1430
  return isEmpty;
1401
- } catch (e32) {
1431
+ } catch (e34) {
1402
1432
  return true;
1403
1433
  }
1404
1434
  }
1405
1435
  try {
1406
1436
  await removeEmptyDirs(imagesDir);
1407
- } catch (e33) {
1437
+ } catch (e35) {
1408
1438
  }
1409
1439
  await saveMeta(meta);
1410
1440
  if (urlsToPurge.length > 0) {
@@ -1472,7 +1502,7 @@ async function handleScanStream() {
1472
1502
  allFiles.push({ relativePath: relPath, fullPath });
1473
1503
  }
1474
1504
  }
1475
- } catch (e34) {
1505
+ } catch (e36) {
1476
1506
  }
1477
1507
  }
1478
1508
  const publicDir = _path2.default.join(process.cwd(), "public");
@@ -1532,7 +1562,7 @@ async function handleScanStream() {
1532
1562
  h: metadata.height || 0,
1533
1563
  b: blurhash
1534
1564
  };
1535
- } catch (e35) {
1565
+ } catch (e37) {
1536
1566
  meta[imageKey] = { w: 0, h: 0 };
1537
1567
  }
1538
1568
  }
@@ -1572,13 +1602,13 @@ async function handleScanStream() {
1572
1602
  }
1573
1603
  }
1574
1604
  }
1575
- } catch (e36) {
1605
+ } catch (e38) {
1576
1606
  }
1577
1607
  }
1578
1608
  const imagesDir = _path2.default.join(process.cwd(), "public", "images");
1579
1609
  try {
1580
1610
  await findOrphans(imagesDir);
1581
- } catch (e37) {
1611
+ } catch (e39) {
1582
1612
  }
1583
1613
  await saveMeta(meta);
1584
1614
  sendEvent({
@@ -1645,13 +1675,13 @@ async function handleDeleteOrphans(request) {
1645
1675
  await _fs.promises.rmdir(dir);
1646
1676
  }
1647
1677
  return isEmpty;
1648
- } catch (e38) {
1678
+ } catch (e40) {
1649
1679
  return true;
1650
1680
  }
1651
1681
  }
1652
1682
  try {
1653
1683
  await removeEmptyDirs(imagesDir);
1654
- } catch (e39) {
1684
+ } catch (e41) {
1655
1685
  }
1656
1686
  return _server.NextResponse.json({
1657
1687
  success: true,