@gallop.software/studio 2.2.4 → 2.2.5

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.
@@ -229,8 +229,14 @@ function isProcessed(entry) {
229
229
  async function purgeCloudflareCache(urls) {
230
230
  const zoneId = process.env.CLOUDFLARE_ZONE_ID;
231
231
  const apiToken = process.env.CLOUDFLARE_API_TOKEN;
232
- if (!zoneId || !apiToken || urls.length === 0) {
233
- return;
232
+ if (urls.length === 0) {
233
+ return { status: "success" };
234
+ }
235
+ if (!zoneId || !apiToken) {
236
+ return {
237
+ status: "not_configured",
238
+ message: "Cache purge skipped. To enable, add CLOUDFLARE_ZONE_ID and CLOUDFLARE_API_TOKEN to .env.studio"
239
+ };
234
240
  }
235
241
  try {
236
242
  const response = await fetch(
@@ -245,10 +251,20 @@ async function purgeCloudflareCache(urls) {
245
251
  }
246
252
  );
247
253
  if (!response.ok) {
248
- console.error("Cache purge failed:", await response.text());
254
+ const text = await response.text();
255
+ console.error("Cache purge failed:", text);
256
+ return {
257
+ status: "failed",
258
+ message: "Cache purge failed. Check CLOUDFLARE_ZONE_ID and CLOUDFLARE_API_TOKEN in .env.studio"
259
+ };
249
260
  }
261
+ return { status: "success", message: "Cache cleared successfully." };
250
262
  } catch (error) {
251
263
  console.error("Cache purge error:", error);
264
+ return {
265
+ status: "failed",
266
+ message: "Cache purge failed. Check your network connection."
267
+ };
252
268
  }
253
269
  }
254
270
  function getR2Client() {
@@ -1605,13 +1621,18 @@ async function handleSync(request) {
1605
1621
  for (const folder of sourceFolders) {
1606
1622
  await deleteEmptyFolders(folder);
1607
1623
  }
1624
+ let cacheMessage;
1608
1625
  if (urlsToPurge.length > 0) {
1609
- await purgeCloudflareCache(urlsToPurge);
1626
+ const cacheResult = await purgeCloudflareCache(urlsToPurge);
1627
+ if (cacheResult.message) {
1628
+ cacheMessage = cacheResult.message;
1629
+ }
1610
1630
  }
1611
1631
  return jsonResponse({
1612
1632
  success: true,
1613
1633
  pushed,
1614
- errors: errors.length > 0 ? errors : void 0
1634
+ errors: errors.length > 0 ? errors : void 0,
1635
+ cacheMessage
1615
1636
  });
1616
1637
  } catch (error) {
1617
1638
  console.error("Failed to push:", error);
@@ -1693,9 +1714,13 @@ async function handleUnprocessStream(request) {
1693
1714
  }
1694
1715
  sendEvent({ type: "cleanup", message: "Saving metadata..." });
1695
1716
  await saveMeta(meta);
1717
+ let cacheMessage = "";
1696
1718
  if (urlsToPurge.length > 0) {
1697
1719
  sendEvent({ type: "cleanup", message: "Purging CDN cache..." });
1698
- await purgeCloudflareCache(urlsToPurge);
1720
+ const cacheResult = await purgeCloudflareCache(urlsToPurge);
1721
+ if (cacheResult.message) {
1722
+ cacheMessage = ` ${cacheResult.message}`;
1723
+ }
1699
1724
  }
1700
1725
  sendEvent({ type: "cleanup", message: "Cleaning up empty folders..." });
1701
1726
  const imagesDir = getPublicPath("images");
@@ -1710,6 +1735,7 @@ async function handleUnprocessStream(request) {
1710
1735
  if (errors.length > 0) {
1711
1736
  message += ` ${errors.length} image${errors.length !== 1 ? "s" : ""} failed.`;
1712
1737
  }
1738
+ message += cacheMessage;
1713
1739
  sendEvent({
1714
1740
  type: "complete",
1715
1741
  processed: removed.length,
@@ -1841,14 +1867,19 @@ async function handleReprocessStream(request) {
1841
1867
  }
1842
1868
  sendEvent({ type: "cleanup", message: "Saving metadata..." });
1843
1869
  await saveMeta(meta);
1870
+ let cacheMessage = "";
1844
1871
  if (urlsToPurge.length > 0) {
1845
1872
  sendEvent({ type: "cleanup", message: "Purging CDN cache..." });
1846
- await purgeCloudflareCache(urlsToPurge);
1873
+ const cacheResult = await purgeCloudflareCache(urlsToPurge);
1874
+ if (cacheResult.message) {
1875
+ cacheMessage = ` ${cacheResult.message}`;
1876
+ }
1847
1877
  }
1848
1878
  let message = `Generated thumbnails for ${processed.length} image${processed.length !== 1 ? "s" : ""}.`;
1849
1879
  if (errors.length > 0) {
1850
1880
  message += ` ${errors.length} image${errors.length !== 1 ? "s" : ""} failed.`;
1851
1881
  }
1882
+ message += cacheMessage;
1852
1883
  sendEvent({
1853
1884
  type: "complete",
1854
1885
  processed: processed.length,
@@ -2062,9 +2093,17 @@ async function handlePushUpdatesStream(request) {
2062
2093
  await deleteEmptyFolders(path7.dirname(localPath));
2063
2094
  }
2064
2095
  await saveMeta(meta);
2096
+ let cacheMessage = "";
2065
2097
  if (urlsToPurge.length > 0) {
2066
2098
  sendEvent({ type: "cleanup", message: "Purging CDN cache..." });
2067
- await purgeCloudflareCache(urlsToPurge);
2099
+ const cacheResult = await purgeCloudflareCache(urlsToPurge);
2100
+ if (cacheResult.status === "not_configured") {
2101
+ cacheMessage = ` ${cacheResult.message}`;
2102
+ } else if (cacheResult.status === "failed") {
2103
+ cacheMessage = ` ${cacheResult.message}`;
2104
+ } else if (cacheResult.status === "success" && cacheResult.message) {
2105
+ cacheMessage = ` ${cacheResult.message}`;
2106
+ }
2068
2107
  }
2069
2108
  let message = `Pushed ${pushed.length} update${pushed.length !== 1 ? "s" : ""} to cloud.`;
2070
2109
  if (skipped.length > 0) {
@@ -2073,6 +2112,7 @@ async function handlePushUpdatesStream(request) {
2073
2112
  if (errors.length > 0) {
2074
2113
  message += ` ${errors.length} file${errors.length !== 1 ? "s" : ""} failed.`;
2075
2114
  }
2115
+ message += cacheMessage;
2076
2116
  sendEvent({
2077
2117
  type: "complete",
2078
2118
  pushed: pushed.length,