@gallop.software/studio 0.1.90 → 0.1.92

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.
@@ -1,4 +1,4 @@
1
- import { F as FileItem } from '../types-DzM_J-55.mjs';
1
+ import { F as FileItem } from '../types-C4hCz2w8.mjs';
2
2
  import { NextRequest, NextResponse } from 'next/server';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { F as FileItem } from '../types-DzM_J-55.js';
1
+ import { F as FileItem } from '../types-C4hCz2w8.js';
2
2
  import { NextRequest, NextResponse } from 'next/server';
3
3
 
4
4
  /**
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
- var _chunkJWAAU3NNjs = require('../chunk-JWAAU3NN.js');
4
+ var _chunkL36EH3PMjs = require('../chunk-L36EH3PM.js');
5
5
 
6
6
  // src/handlers/index.ts
7
7
  var _server = require('next/server');
@@ -156,7 +156,7 @@ async function uploadToCdn(imageKey) {
156
156
  const bucketName = process.env.CLOUDFLARE_R2_BUCKET_NAME;
157
157
  if (!bucketName) throw new Error("R2 bucket not configured");
158
158
  const r2 = getR2Client();
159
- for (const thumbPath of _chunkJWAAU3NNjs.getAllThumbnailPaths.call(void 0, imageKey)) {
159
+ for (const thumbPath of _chunkL36EH3PMjs.getAllThumbnailPaths.call(void 0, imageKey)) {
160
160
  const localPath = _path2.default.join(process.cwd(), "public", thumbPath);
161
161
  try {
162
162
  const fileBuffer = await _fs.promises.readFile(localPath);
@@ -173,7 +173,7 @@ async function uploadToCdn(imageKey) {
173
173
  }
174
174
  }
175
175
  async function deleteLocalThumbnails(imageKey) {
176
- for (const thumbPath of _chunkJWAAU3NNjs.getAllThumbnailPaths.call(void 0, imageKey)) {
176
+ for (const thumbPath of _chunkL36EH3PMjs.getAllThumbnailPaths.call(void 0, imageKey)) {
177
177
  const localPath = _path2.default.join(process.cwd(), "public", thumbPath);
178
178
  try {
179
179
  await _fs.promises.unlink(localPath);
@@ -222,13 +222,13 @@ async function handleList(request) {
222
222
  } else {
223
223
  const fileName = remaining;
224
224
  const isImage = isImageFile(fileName);
225
- const isSynced = entry.c === 1;
225
+ const isPushedToCloud = entry.c === 1;
226
226
  let thumbnail;
227
227
  let hasThumbnail = false;
228
228
  let fileSize;
229
229
  if (isImage && (entry.w || entry.b)) {
230
- const thumbPath = _chunkJWAAU3NNjs.getThumbnailPath.call(void 0, key, "sm");
231
- if (isSynced) {
230
+ const thumbPath = _chunkL36EH3PMjs.getThumbnailPath.call(void 0, key, "sm");
231
+ if (isPushedToCloud) {
232
232
  const cdnUrl = process.env.CLOUDFLARE_R2_PUBLIC_URL || process.env.NEXT_PUBLIC_CLOUDFLARE_R2_PUBLIC_URL;
233
233
  if (cdnUrl) {
234
234
  thumbnail = `${cdnUrl}${thumbPath}`;
@@ -249,7 +249,7 @@ async function handleList(request) {
249
249
  thumbnail = key;
250
250
  hasThumbnail = false;
251
251
  }
252
- if (!isSynced) {
252
+ if (!isPushedToCloud) {
253
253
  try {
254
254
  const filePath = _path2.default.join(process.cwd(), "public", key);
255
255
  const stats = await _fs.promises.stat(filePath);
@@ -264,7 +264,8 @@ async function handleList(request) {
264
264
  size: fileSize,
265
265
  thumbnail,
266
266
  hasThumbnail,
267
- cdnSynced: isSynced,
267
+ isProcessed: entry.p === 1,
268
+ cdnPushed: isPushedToCloud,
268
269
  dimensions: entry.w && entry.h ? { width: entry.w, height: entry.h } : void 0
269
270
  });
270
271
  }
@@ -289,12 +290,12 @@ async function handleSearch(request) {
289
290
  const fileName = _path2.default.basename(key);
290
291
  const relativePath = key.slice(1);
291
292
  const isImage = isImageFile(fileName);
292
- const isSynced = entry.c === 1;
293
+ const isPushedToCloud = entry.c === 1;
293
294
  let thumbnail;
294
295
  let hasThumbnail = false;
295
296
  if (isImage && (entry.w || entry.b)) {
296
- const thumbPath = _chunkJWAAU3NNjs.getThumbnailPath.call(void 0, key, "sm");
297
- if (isSynced) {
297
+ const thumbPath = _chunkL36EH3PMjs.getThumbnailPath.call(void 0, key, "sm");
298
+ if (isPushedToCloud) {
298
299
  const cdnUrl = process.env.CLOUDFLARE_R2_PUBLIC_URL || process.env.NEXT_PUBLIC_CLOUDFLARE_R2_PUBLIC_URL;
299
300
  if (cdnUrl) {
300
301
  thumbnail = `${cdnUrl}${thumbPath}`;
@@ -321,7 +322,8 @@ async function handleSearch(request) {
321
322
  type: "file",
322
323
  thumbnail,
323
324
  hasThumbnail,
324
- cdnSynced: isSynced,
325
+ isProcessed: entry.p === 1,
326
+ cdnPushed: isPushedToCloud,
325
327
  dimensions: entry.w && entry.h ? { width: entry.w, height: entry.h } : void 0
326
328
  });
327
329
  }
@@ -513,7 +515,7 @@ async function handleDelete(request) {
513
515
  const absolutePath = _path2.default.join(process.cwd(), itemPath);
514
516
  const imageKey = "/" + itemPath.replace(/^public\//, "");
515
517
  const entry = meta[imageKey];
516
- const isSynced = _optionalChain([entry, 'optionalAccess', _5 => _5.c]) === 1;
518
+ const isPushedToCloud = _optionalChain([entry, 'optionalAccess', _5 => _5.c]) === 1;
517
519
  try {
518
520
  const stats = await _fs.promises.stat(absolutePath);
519
521
  if (stats.isDirectory()) {
@@ -522,7 +524,7 @@ async function handleDelete(request) {
522
524
  for (const key of Object.keys(meta)) {
523
525
  if (key.startsWith(prefix) || key === imageKey) {
524
526
  if (!meta[key].c) {
525
- for (const thumbPath of _chunkJWAAU3NNjs.getAllThumbnailPaths.call(void 0, key)) {
527
+ for (const thumbPath of _chunkL36EH3PMjs.getAllThumbnailPaths.call(void 0, key)) {
526
528
  const absoluteThumbPath = _path2.default.join(process.cwd(), "public", thumbPath);
527
529
  try {
528
530
  await _fs.promises.unlink(absoluteThumbPath);
@@ -537,8 +539,8 @@ async function handleDelete(request) {
537
539
  await _fs.promises.unlink(absolutePath);
538
540
  const isInImagesFolder = itemPath.startsWith("public/images/");
539
541
  if (!isInImagesFolder && entry) {
540
- if (!isSynced) {
541
- for (const thumbPath of _chunkJWAAU3NNjs.getAllThumbnailPaths.call(void 0, imageKey)) {
542
+ if (!isPushedToCloud) {
543
+ for (const thumbPath of _chunkL36EH3PMjs.getAllThumbnailPaths.call(void 0, imageKey)) {
542
544
  const absoluteThumbPath = _path2.default.join(process.cwd(), "public", thumbPath);
543
545
  try {
544
546
  await _fs.promises.unlink(absoluteThumbPath);
@@ -650,8 +652,8 @@ async function handleRename(request) {
650
652
  const newKey = "/" + newRelativePath;
651
653
  if (meta[oldKey]) {
652
654
  const entry = meta[oldKey];
653
- const oldThumbPaths = _chunkJWAAU3NNjs.getAllThumbnailPaths.call(void 0, oldKey);
654
- const newThumbPaths = _chunkJWAAU3NNjs.getAllThumbnailPaths.call(void 0, newKey);
655
+ const oldThumbPaths = _chunkL36EH3PMjs.getAllThumbnailPaths.call(void 0, oldKey);
656
+ const newThumbPaths = _chunkL36EH3PMjs.getAllThumbnailPaths.call(void 0, newKey);
655
657
  for (let i = 0; i < oldThumbPaths.length; i++) {
656
658
  const oldThumbPath = _path2.default.join(process.cwd(), "public", oldThumbPaths[i]);
657
659
  const newThumbPath = _path2.default.join(process.cwd(), "public", newThumbPaths[i]);
@@ -730,8 +732,8 @@ async function handleMove(request) {
730
732
  const newKey = "/" + newRelativePath;
731
733
  if (meta[oldKey]) {
732
734
  const entry = meta[oldKey];
733
- const oldThumbPaths = _chunkJWAAU3NNjs.getAllThumbnailPaths.call(void 0, oldKey);
734
- const newThumbPaths = _chunkJWAAU3NNjs.getAllThumbnailPaths.call(void 0, newKey);
735
+ const oldThumbPaths = _chunkL36EH3PMjs.getAllThumbnailPaths.call(void 0, oldKey);
736
+ const newThumbPaths = _chunkL36EH3PMjs.getAllThumbnailPaths.call(void 0, newKey);
735
737
  for (let i = 0; i < oldThumbPaths.length; i++) {
736
738
  const oldThumbPath = _path2.default.join(process.cwd(), "public", oldThumbPaths[i]);
737
739
  const newThumbPath = _path2.default.join(process.cwd(), "public", newThumbPaths[i]);
@@ -793,7 +795,7 @@ async function handleSync(request) {
793
795
  endpoint: `https://${accountId}.r2.cloudflarestorage.com`,
794
796
  credentials: { accessKeyId, secretAccessKey }
795
797
  });
796
- const synced = [];
798
+ const pushed = [];
797
799
  const errors = [];
798
800
  for (const imageKey of imageKeys) {
799
801
  const entry = meta[imageKey];
@@ -802,7 +804,11 @@ async function handleSync(request) {
802
804
  continue;
803
805
  }
804
806
  if (entry.c) {
805
- synced.push(imageKey);
807
+ pushed.push(imageKey);
808
+ continue;
809
+ }
810
+ if (!entry.p) {
811
+ errors.push(`Image not processed: ${imageKey}. Run Process Images first.`);
806
812
  continue;
807
813
  }
808
814
  try {
@@ -821,7 +827,7 @@ async function handleSync(request) {
821
827
  errors.push(`Original file not found: ${imageKey}`);
822
828
  continue;
823
829
  }
824
- for (const thumbPath of _chunkJWAAU3NNjs.getAllThumbnailPaths.call(void 0, imageKey)) {
830
+ for (const thumbPath of _chunkL36EH3PMjs.getAllThumbnailPaths.call(void 0, imageKey)) {
825
831
  const localPath = _path2.default.join(process.cwd(), "public", thumbPath);
826
832
  try {
827
833
  const fileBuffer = await _fs.promises.readFile(localPath);
@@ -837,7 +843,7 @@ async function handleSync(request) {
837
843
  }
838
844
  }
839
845
  entry.c = 1;
840
- for (const thumbPath of _chunkJWAAU3NNjs.getAllThumbnailPaths.call(void 0, imageKey)) {
846
+ for (const thumbPath of _chunkL36EH3PMjs.getAllThumbnailPaths.call(void 0, imageKey)) {
841
847
  const localPath = _path2.default.join(process.cwd(), "public", thumbPath);
842
848
  try {
843
849
  await _fs.promises.unlink(localPath);
@@ -848,16 +854,16 @@ async function handleSync(request) {
848
854
  await _fs.promises.unlink(originalLocalPath);
849
855
  } catch (e22) {
850
856
  }
851
- synced.push(imageKey);
857
+ pushed.push(imageKey);
852
858
  } catch (error) {
853
- console.error(`Failed to sync ${imageKey}:`, error);
854
- errors.push(`Failed to sync: ${imageKey}`);
859
+ console.error(`Failed to push ${imageKey}:`, error);
860
+ errors.push(`Failed to push: ${imageKey}`);
855
861
  }
856
862
  }
857
863
  await saveMeta(meta);
858
864
  return _server.NextResponse.json({
859
865
  success: true,
860
- synced,
866
+ pushed,
861
867
  errors: errors.length > 0 ? errors : void 0
862
868
  });
863
869
  } catch (error) {
@@ -878,12 +884,12 @@ async function handleReprocess(request) {
878
884
  try {
879
885
  let buffer;
880
886
  const entry = meta[imageKey];
881
- const isSynced = _optionalChain([entry, 'optionalAccess', _6 => _6.c]) === 1;
887
+ const isPushedToCloud = _optionalChain([entry, 'optionalAccess', _6 => _6.c]) === 1;
882
888
  const originalPath = _path2.default.join(process.cwd(), "public", imageKey);
883
889
  try {
884
890
  buffer = await _fs.promises.readFile(originalPath);
885
891
  } catch (e23) {
886
- if (isSynced) {
892
+ if (isPushedToCloud) {
887
893
  buffer = await downloadFromCdn(imageKey);
888
894
  const dir = _path2.default.dirname(originalPath);
889
895
  await _fs.promises.mkdir(dir, { recursive: true });
@@ -893,7 +899,7 @@ async function handleReprocess(request) {
893
899
  }
894
900
  }
895
901
  const updatedEntry = await processImage(buffer, imageKey);
896
- if (isSynced) {
902
+ if (isPushedToCloud) {
897
903
  updatedEntry.c = 1;
898
904
  await uploadToCdn(imageKey);
899
905
  await deleteLocalThumbnails(imageKey);
@@ -934,20 +940,23 @@ async function handleProcessAllStream() {
934
940
  const processed = [];
935
941
  const errors = [];
936
942
  const orphansRemoved = [];
943
+ let alreadyProcessed = 0;
937
944
  const imagesToProcess = [];
938
945
  for (const [key, entry] of Object.entries(meta)) {
939
- if (entry.c) continue;
940
946
  const fileName = _path2.default.basename(key);
941
947
  if (!isImageFile(fileName)) continue;
942
- if (!entry.b) {
948
+ if (!entry.p) {
943
949
  imagesToProcess.push({ key, entry });
950
+ } else {
951
+ alreadyProcessed++;
944
952
  }
945
953
  }
946
954
  const total = imagesToProcess.length;
947
955
  sendEvent({ type: "start", total });
948
956
  for (let i = 0; i < imagesToProcess.length; i++) {
949
- const { key } = imagesToProcess[i];
957
+ const { key, entry } = imagesToProcess[i];
950
958
  const fullPath = _path2.default.join(process.cwd(), "public", key);
959
+ const isInCloud = entry.c === 1;
951
960
  sendEvent({
952
961
  type: "progress",
953
962
  current: i + 1,
@@ -957,7 +966,15 @@ async function handleProcessAllStream() {
957
966
  // Remove leading /
958
967
  });
959
968
  try {
960
- const buffer = await _fs.promises.readFile(fullPath);
969
+ let buffer;
970
+ if (isInCloud) {
971
+ buffer = await downloadFromCdn(key);
972
+ const dir = _path2.default.dirname(fullPath);
973
+ await _fs.promises.mkdir(dir, { recursive: true });
974
+ await _fs.promises.writeFile(fullPath, buffer);
975
+ } else {
976
+ buffer = await _fs.promises.readFile(fullPath);
977
+ }
961
978
  const ext = _path2.default.extname(key).toLowerCase();
962
979
  const isSvg = ext === ".svg";
963
980
  if (isSvg) {
@@ -968,13 +985,27 @@ async function handleProcessAllStream() {
968
985
  const destPath = _path2.default.join(imagesPath, fileName);
969
986
  await _fs.promises.writeFile(destPath, buffer);
970
987
  meta[key] = {
988
+ ...entry,
971
989
  w: 0,
972
990
  h: 0,
973
- b: ""
991
+ b: "",
992
+ p: 1
974
993
  };
975
994
  } else {
976
995
  const processedEntry = await processImage(buffer, key);
977
- meta[key] = processedEntry;
996
+ meta[key] = {
997
+ ...processedEntry,
998
+ p: 1,
999
+ ...isInCloud ? { c: 1 } : {}
1000
+ };
1001
+ }
1002
+ if (isInCloud) {
1003
+ await uploadToCdn(key);
1004
+ await deleteLocalThumbnails(key);
1005
+ try {
1006
+ await _fs.promises.unlink(fullPath);
1007
+ } catch (e25) {
1008
+ }
978
1009
  }
979
1010
  processed.push(key.slice(1));
980
1011
  } catch (error) {
@@ -986,7 +1017,7 @@ async function handleProcessAllStream() {
986
1017
  const trackedPaths = /* @__PURE__ */ new Set();
987
1018
  for (const imageKey of Object.keys(meta)) {
988
1019
  if (!meta[imageKey].c) {
989
- for (const thumbPath of _chunkJWAAU3NNjs.getAllThumbnailPaths.call(void 0, imageKey)) {
1020
+ for (const thumbPath of _chunkL36EH3PMjs.getAllThumbnailPaths.call(void 0, imageKey)) {
990
1021
  trackedPaths.add(thumbPath);
991
1022
  }
992
1023
  }
@@ -1012,13 +1043,13 @@ async function handleProcessAllStream() {
1012
1043
  }
1013
1044
  }
1014
1045
  }
1015
- } catch (e25) {
1046
+ } catch (e26) {
1016
1047
  }
1017
1048
  }
1018
1049
  const imagesDir = _path2.default.join(process.cwd(), "public", "images");
1019
1050
  try {
1020
1051
  await findOrphans(imagesDir);
1021
- } catch (e26) {
1052
+ } catch (e27) {
1022
1053
  }
1023
1054
  async function removeEmptyDirs(dir) {
1024
1055
  try {
@@ -1036,18 +1067,19 @@ async function handleProcessAllStream() {
1036
1067
  await _fs.promises.rmdir(dir);
1037
1068
  }
1038
1069
  return isEmpty;
1039
- } catch (e27) {
1070
+ } catch (e28) {
1040
1071
  return true;
1041
1072
  }
1042
1073
  }
1043
1074
  try {
1044
1075
  await removeEmptyDirs(imagesDir);
1045
- } catch (e28) {
1076
+ } catch (e29) {
1046
1077
  }
1047
1078
  await saveMeta(meta);
1048
1079
  sendEvent({
1049
1080
  type: "complete",
1050
1081
  processed: processed.length,
1082
+ alreadyProcessed,
1051
1083
  orphansRemoved: orphansRemoved.length,
1052
1084
  errors: errors.length
1053
1085
  });
@@ -1102,7 +1134,7 @@ async function handleScanStream() {
1102
1134
  allFiles.push({ relativePath: relPath, fullPath });
1103
1135
  }
1104
1136
  }
1105
- } catch (e29) {
1137
+ } catch (e30) {
1106
1138
  }
1107
1139
  }
1108
1140
  const publicDir = _path2.default.join(process.cwd(), "public");
@@ -1158,7 +1190,7 @@ async function handleScanStream() {
1158
1190
  w: metadata.width || 0,
1159
1191
  h: metadata.height || 0
1160
1192
  };
1161
- } catch (e30) {
1193
+ } catch (e31) {
1162
1194
  meta[imageKey] = { w: 0, h: 0 };
1163
1195
  }
1164
1196
  }