@gallop.software/studio 1.5.4 → 1.5.6

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.
@@ -1883,6 +1883,102 @@ async function handleProcessAllStream() {
1883
1883
  }
1884
1884
  });
1885
1885
  }
1886
+ async function handleDownloadStream(request) {
1887
+ const { imageKeys } = await request.json();
1888
+ if (!imageKeys || !Array.isArray(imageKeys) || imageKeys.length === 0) {
1889
+ return _server.NextResponse.json({ error: "No image keys provided" }, { status: 400 });
1890
+ }
1891
+ const stream = new ReadableStream({
1892
+ async start(controller) {
1893
+ const encoder = new TextEncoder();
1894
+ const sendEvent = (data) => {
1895
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify(data)}
1896
+
1897
+ `));
1898
+ };
1899
+ sendEvent({ type: "start", total: imageKeys.length });
1900
+ const downloaded = [];
1901
+ const skipped = [];
1902
+ const errors = [];
1903
+ try {
1904
+ const meta = await loadMeta();
1905
+ for (let i = 0; i < imageKeys.length; i++) {
1906
+ const imageKey = imageKeys[i];
1907
+ const entry = getMetaEntry(meta, imageKey);
1908
+ if (!entry || entry.c === void 0) {
1909
+ skipped.push(imageKey);
1910
+ sendEvent({
1911
+ type: "progress",
1912
+ current: i + 1,
1913
+ total: imageKeys.length,
1914
+ message: `Skipped ${imageKey} (not on cloud)`
1915
+ });
1916
+ continue;
1917
+ }
1918
+ try {
1919
+ const imageBuffer = await downloadFromCdn(imageKey);
1920
+ const localPath = _path2.default.join(process.cwd(), "public", imageKey.replace(/^\//, ""));
1921
+ await _fs.promises.mkdir(_path2.default.dirname(localPath), { recursive: true });
1922
+ await _fs.promises.writeFile(localPath, imageBuffer);
1923
+ await deleteThumbnailsFromCdn(imageKey);
1924
+ const wasProcessed = _chunkVI6QG6WTjs.isProcessed.call(void 0, entry);
1925
+ delete entry.c;
1926
+ if (wasProcessed) {
1927
+ const processedEntry = await processImage(imageBuffer, imageKey);
1928
+ entry.sm = processedEntry.sm;
1929
+ entry.md = processedEntry.md;
1930
+ entry.lg = processedEntry.lg;
1931
+ entry.f = processedEntry.f;
1932
+ }
1933
+ downloaded.push(imageKey);
1934
+ sendEvent({
1935
+ type: "progress",
1936
+ current: i + 1,
1937
+ total: imageKeys.length,
1938
+ message: `Downloaded ${imageKey}`
1939
+ });
1940
+ } catch (error) {
1941
+ console.error(`Failed to download ${imageKey}:`, error);
1942
+ errors.push(imageKey);
1943
+ sendEvent({
1944
+ type: "progress",
1945
+ current: i + 1,
1946
+ total: imageKeys.length,
1947
+ message: `Failed to download ${imageKey}`
1948
+ });
1949
+ }
1950
+ }
1951
+ await saveMeta(meta);
1952
+ let message = `Downloaded ${downloaded.length} image${downloaded.length !== 1 ? "s" : ""}.`;
1953
+ if (skipped.length > 0) {
1954
+ message += ` ${skipped.length} image${skipped.length !== 1 ? "s were" : " was"} not on cloud.`;
1955
+ }
1956
+ if (errors.length > 0) {
1957
+ message += ` ${errors.length} image${errors.length !== 1 ? "s" : ""} failed.`;
1958
+ }
1959
+ sendEvent({
1960
+ type: "complete",
1961
+ downloaded: downloaded.length,
1962
+ skipped: skipped.length,
1963
+ errors: errors.length,
1964
+ message
1965
+ });
1966
+ } catch (error) {
1967
+ console.error("Download stream error:", error);
1968
+ sendEvent({ type: "error", message: "Failed to download images" });
1969
+ } finally {
1970
+ controller.close();
1971
+ }
1972
+ }
1973
+ });
1974
+ return new Response(stream, {
1975
+ headers: {
1976
+ "Content-Type": "text/event-stream",
1977
+ "Cache-Control": "no-cache",
1978
+ "Connection": "keep-alive"
1979
+ }
1980
+ });
1981
+ }
1886
1982
 
1887
1983
  // src/handlers/scan.ts
1888
1984
 
@@ -2403,6 +2499,9 @@ async function POST(request) {
2403
2499
  if (route === "process-all") {
2404
2500
  return handleProcessAllStream();
2405
2501
  }
2502
+ if (route === "download-stream") {
2503
+ return handleDownloadStream(request);
2504
+ }
2406
2505
  if (route === "create-folder") {
2407
2506
  return handleCreateFolder(request);
2408
2507
  }