@gallop.software/studio 2.3.16 → 2.3.18

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.
@@ -1119,6 +1119,7 @@ async function handleDelete(request) {
1119
1119
  sourceFolders.add(path6.dirname(absolutePath));
1120
1120
  const entry = meta[imageKey];
1121
1121
  const isPushedToCloud = entry?.c !== void 0;
1122
+ const hasThumbnails = entry ? isProcessed(entry) : false;
1122
1123
  try {
1123
1124
  const stats = await fs6.stat(absolutePath);
1124
1125
  if (stats.isDirectory()) {
@@ -1127,7 +1128,13 @@ async function handleDelete(request) {
1127
1128
  for (const key of Object.keys(meta)) {
1128
1129
  if (key.startsWith(prefix) || key === imageKey) {
1129
1130
  const keyEntry = meta[key];
1130
- if (keyEntry && keyEntry.c === void 0) {
1131
+ const keyHasThumbnails = keyEntry ? isProcessed(keyEntry) : false;
1132
+ if (keyEntry?.c !== void 0) {
1133
+ try {
1134
+ await deleteFromCdn(key, keyHasThumbnails);
1135
+ } catch {
1136
+ }
1137
+ } else {
1131
1138
  for (const thumbPath of getAllThumbnailPaths(key)) {
1132
1139
  const absoluteThumbPath = getPublicPath(thumbPath);
1133
1140
  try {
@@ -1143,7 +1150,12 @@ async function handleDelete(request) {
1143
1150
  await fs6.unlink(absolutePath);
1144
1151
  const isInImagesFolder = itemPath.startsWith("public/images/");
1145
1152
  if (!isInImagesFolder && entry) {
1146
- if (!isPushedToCloud) {
1153
+ if (isPushedToCloud) {
1154
+ try {
1155
+ await deleteFromCdn(imageKey, hasThumbnails);
1156
+ } catch {
1157
+ }
1158
+ } else {
1147
1159
  for (const thumbPath of getAllThumbnailPaths(imageKey)) {
1148
1160
  const absoluteThumbPath = getPublicPath(thumbPath);
1149
1161
  try {
@@ -1157,12 +1169,26 @@ async function handleDelete(request) {
1157
1169
  }
1158
1170
  } catch {
1159
1171
  if (entry) {
1172
+ if (isPushedToCloud) {
1173
+ try {
1174
+ await deleteFromCdn(imageKey, hasThumbnails);
1175
+ } catch {
1176
+ }
1177
+ }
1160
1178
  delete meta[imageKey];
1161
1179
  } else {
1162
1180
  const prefix = imageKey + "/";
1163
1181
  let foundAny = false;
1164
1182
  for (const key of Object.keys(meta)) {
1165
1183
  if (key.startsWith(prefix)) {
1184
+ const keyEntry = meta[key];
1185
+ const keyHasThumbnails = keyEntry ? isProcessed(keyEntry) : false;
1186
+ if (keyEntry?.c !== void 0) {
1187
+ try {
1188
+ await deleteFromCdn(key, keyHasThumbnails);
1189
+ } catch {
1190
+ }
1191
+ }
1166
1192
  delete meta[key];
1167
1193
  foundAny = true;
1168
1194
  }
@@ -1840,13 +1866,17 @@ async function handleDownloadStream(request) {
1840
1866
  if (!imageKeys || !Array.isArray(imageKeys) || imageKeys.length === 0) {
1841
1867
  return jsonResponse({ error: "No image keys provided" }, { status: 400 });
1842
1868
  }
1869
+ const abortSignal = request.signal;
1843
1870
  const stream = new ReadableStream({
1844
1871
  async start(controller) {
1845
1872
  const encoder = new TextEncoder();
1846
1873
  const sendEvent = (data) => {
1847
- controller.enqueue(encoder.encode(`data: ${JSON.stringify(data)}
1874
+ try {
1875
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify(data)}
1848
1876
 
1849
1877
  `));
1878
+ } catch {
1879
+ }
1850
1880
  };
1851
1881
  sendEvent({ type: "start", total: imageKeys.length });
1852
1882
  const downloaded = [];
@@ -1855,6 +1885,16 @@ async function handleDownloadStream(request) {
1855
1885
  try {
1856
1886
  const meta = await loadMeta();
1857
1887
  for (let i = 0; i < imageKeys.length; i++) {
1888
+ if (abortSignal?.aborted) {
1889
+ await saveMeta(meta);
1890
+ sendEvent({
1891
+ type: "stopped",
1892
+ downloaded: downloaded.length,
1893
+ message: `Stopped. ${downloaded.length} image${downloaded.length !== 1 ? "s" : ""} downloaded.`
1894
+ });
1895
+ controller.close();
1896
+ return;
1897
+ }
1858
1898
  const imageKey = imageKeys[i];
1859
1899
  const entry = getMetaEntry(meta, imageKey);
1860
1900
  if (!entry || entry.c === void 0) {
@@ -1869,6 +1909,16 @@ async function handleDownloadStream(request) {
1869
1909
  }
1870
1910
  try {
1871
1911
  const imageBuffer = await downloadFromCdn(imageKey);
1912
+ if (abortSignal?.aborted) {
1913
+ await saveMeta(meta);
1914
+ sendEvent({
1915
+ type: "stopped",
1916
+ downloaded: downloaded.length,
1917
+ message: `Stopped. ${downloaded.length} image${downloaded.length !== 1 ? "s" : ""} downloaded.`
1918
+ });
1919
+ controller.close();
1920
+ return;
1921
+ }
1872
1922
  const localPath = getPublicPath(imageKey.replace(/^\//, ""));
1873
1923
  await fs7.mkdir(path7.dirname(localPath), { recursive: true });
1874
1924
  await fs7.writeFile(localPath, imageBuffer);