@gallop.software/studio 1.3.1 → 1.3.3

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.
@@ -5505,42 +5505,100 @@ function useStudioActions({
5505
5505
  message: "Processing images..."
5506
5506
  }
5507
5507
  }));
5508
+ abortControllerRef.current = new AbortController();
5509
+ const signal = abortControllerRef.current.signal;
5508
5510
  try {
5509
- const response = await fetch("/api/studio/reprocess", {
5511
+ const response = await fetch("/api/studio/reprocess-stream", {
5510
5512
  method: "POST",
5511
5513
  headers: { "Content-Type": "application/json" },
5512
- body: JSON.stringify({ imageKeys })
5514
+ body: JSON.stringify({ imageKeys }),
5515
+ signal
5513
5516
  });
5514
- const data = await response.json();
5515
5517
  if (!response.ok) {
5518
+ const error = await response.json();
5516
5519
  setProgressState({
5517
5520
  current: 0,
5518
5521
  total: imageKeys.length,
5519
5522
  percent: 0,
5520
5523
  status: "error",
5521
- message: data.error || "Processing failed"
5524
+ message: error.error || "Processing failed"
5522
5525
  });
5523
5526
  return;
5524
5527
  }
5525
- const processed = data.processed?.length || 0;
5526
- const errors = data.errors?.length || 0;
5527
- setProgressState({
5528
- current: processed,
5529
- total: imageKeys.length,
5530
- percent: 100,
5531
- status: errors > 0 ? "error" : "complete",
5532
- message: `Processed ${processed} image${processed !== 1 ? "s" : ""}${errors > 0 ? `, ${errors} error${errors !== 1 ? "s" : ""}` : ""}`
5533
- });
5534
- triggerRefresh();
5528
+ const reader = response.body?.getReader();
5529
+ const decoder = new TextDecoder();
5530
+ if (reader) {
5531
+ let buffer = "";
5532
+ while (true) {
5533
+ const { done, value } = await reader.read();
5534
+ if (done) break;
5535
+ buffer += decoder.decode(value, { stream: true });
5536
+ const lines = buffer.split("\n");
5537
+ buffer = lines.pop() || "";
5538
+ for (const line of lines) {
5539
+ if (line.startsWith("data: ")) {
5540
+ try {
5541
+ const data = JSON.parse(line.slice(6));
5542
+ if (data.type === "start") {
5543
+ setProgressState((prev) => ({
5544
+ ...prev,
5545
+ total: data.total
5546
+ }));
5547
+ } else if (data.type === "progress") {
5548
+ setProgressState({
5549
+ current: data.current,
5550
+ total: data.total,
5551
+ percent: data.percent,
5552
+ status: "processing",
5553
+ message: data.message
5554
+ });
5555
+ } else if (data.type === "cleanup") {
5556
+ setProgressState((prev) => ({
5557
+ ...prev,
5558
+ status: "cleanup",
5559
+ message: data.message
5560
+ }));
5561
+ } else if (data.type === "complete") {
5562
+ setProgressState({
5563
+ current: data.processed,
5564
+ total: data.processed,
5565
+ percent: 100,
5566
+ status: data.errors > 0 ? "error" : "complete",
5567
+ message: data.message
5568
+ });
5569
+ triggerRefresh();
5570
+ } else if (data.type === "error") {
5571
+ setProgressState((prev) => ({
5572
+ ...prev,
5573
+ status: "error",
5574
+ message: data.message
5575
+ }));
5576
+ }
5577
+ } catch {
5578
+ }
5579
+ }
5580
+ }
5581
+ }
5582
+ }
5535
5583
  } catch (error) {
5536
- console.error("Processing error:", error);
5537
- setProgressState({
5538
- current: 0,
5539
- total: imageKeys.length,
5540
- percent: 0,
5541
- status: "error",
5542
- message: "Processing failed. Check console for details."
5543
- });
5584
+ if (signal.aborted) {
5585
+ setProgressState((prev) => ({
5586
+ ...prev,
5587
+ status: "stopped",
5588
+ message: "Processing stopped by user"
5589
+ }));
5590
+ } else {
5591
+ console.error("Processing error:", error);
5592
+ setProgressState({
5593
+ current: 0,
5594
+ total: imageKeys.length,
5595
+ percent: 0,
5596
+ status: "error",
5597
+ message: "Processing failed. Check console for details."
5598
+ });
5599
+ }
5600
+ } finally {
5601
+ abortControllerRef.current = null;
5544
5602
  }
5545
5603
  }, [actionState.actionPaths, triggerRefresh, setProgressState]);
5546
5604
  const deleteOrphans = useCallback5(async () => {
@@ -6053,4 +6111,4 @@ export {
6053
6111
  StudioUI,
6054
6112
  StudioUI_default as default
6055
6113
  };
6056
- //# sourceMappingURL=StudioUI-NREPJZTK.mjs.map
6114
+ //# sourceMappingURL=StudioUI-IHTWNJHB.mjs.map