@gallop.software/studio 1.3.4 → 1.3.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.
@@ -2122,33 +2122,83 @@ function StudioToolbar() {
2122
2122
  percent: 0,
2123
2123
  status: "processing"
2124
2124
  });
2125
- const selectedImageKeys = imagesToProcess.map((p) => p.replace(/^public\//, ""));
2126
- const response = await fetch("/api/studio/reprocess", {
2125
+ const selectedImageKeys = imagesToProcess.map((p) => {
2126
+ const key = p.replace(/^public\//, "");
2127
+ return key.startsWith("/") ? key : `/${key}`;
2128
+ });
2129
+ const response = await fetch("/api/studio/reprocess-stream", {
2127
2130
  method: "POST",
2128
2131
  headers: { "Content-Type": "application/json" },
2129
2132
  body: JSON.stringify({ imageKeys: selectedImageKeys }),
2130
2133
  signal
2131
2134
  });
2132
- const data = await response.json();
2133
- if (response.ok) {
2134
- setProgressState({
2135
- current: data.processed?.length || 0,
2136
- total: data.processed?.length || 0,
2137
- percent: 100,
2138
- status: "complete",
2139
- processed: data.processed?.length || 0,
2140
- errors: data.errors?.length || 0
2141
- });
2142
- clearSelection();
2143
- triggerRefresh();
2144
- } else {
2135
+ if (!response.ok) {
2136
+ const error = await response.json();
2145
2137
  setProgressState({
2146
2138
  current: 0,
2147
2139
  total: 0,
2148
2140
  percent: 0,
2149
2141
  status: "error",
2150
- message: data.error || "Unknown error"
2142
+ message: error.error || "Unknown error"
2151
2143
  });
2144
+ } else {
2145
+ const reader = response.body?.getReader();
2146
+ const decoder = new TextDecoder();
2147
+ if (reader) {
2148
+ let buffer = "";
2149
+ while (true) {
2150
+ const { done, value } = await reader.read();
2151
+ if (done) break;
2152
+ buffer += decoder.decode(value, { stream: true });
2153
+ const lines = buffer.split("\n");
2154
+ buffer = lines.pop() || "";
2155
+ for (const line of lines) {
2156
+ if (line.startsWith("data: ")) {
2157
+ try {
2158
+ const data = JSON.parse(line.slice(6));
2159
+ if (data.type === "start") {
2160
+ setProgressState((prev) => ({
2161
+ ...prev,
2162
+ total: data.total
2163
+ }));
2164
+ } else if (data.type === "progress") {
2165
+ setProgressState({
2166
+ current: data.current,
2167
+ total: data.total,
2168
+ percent: data.percent,
2169
+ status: "processing",
2170
+ message: data.message
2171
+ });
2172
+ } else if (data.type === "cleanup") {
2173
+ setProgressState((prev) => ({
2174
+ ...prev,
2175
+ status: "cleanup",
2176
+ message: data.message
2177
+ }));
2178
+ } else if (data.type === "complete") {
2179
+ setProgressState({
2180
+ current: data.processed,
2181
+ total: data.processed,
2182
+ percent: 100,
2183
+ status: data.errors > 0 ? "error" : "complete",
2184
+ processed: data.processed,
2185
+ message: data.message
2186
+ });
2187
+ clearSelection();
2188
+ triggerRefresh();
2189
+ } else if (data.type === "error") {
2190
+ setProgressState((prev) => ({
2191
+ ...prev,
2192
+ status: "error",
2193
+ message: data.message
2194
+ }));
2195
+ }
2196
+ } catch {
2197
+ }
2198
+ }
2199
+ }
2200
+ }
2201
+ }
2152
2202
  }
2153
2203
  }
2154
2204
  } catch (error) {
@@ -6111,4 +6161,4 @@ export {
6111
6161
  StudioUI,
6112
6162
  StudioUI_default as default
6113
6163
  };
6114
- //# sourceMappingURL=StudioUI-IHTWNJHB.mjs.map
6164
+ //# sourceMappingURL=StudioUI-DNDMPY7Q.mjs.map