OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.
TypeScript
fix(kieai): cancel actually aborts submission, retry works after poller failures
lvalicse093bee447cb
diff --git a/apps/web/src/components/editor/kieai/KieAIImageDialog.tsx b/apps/web/src/components/editor/kieai/KieAIImageDialog.tsxindex d9536774..7b53a22f 100644--- a/apps/web/src/components/editor/kieai/KieAIImageDialog.tsx+++ b/apps/web/src/components/editor/kieai/KieAIImageDialog.tsx@@ -120,6 +120,7 @@ export function KieAIImageDialog({ open, onClose, sourceFile, previewUrl }: Propif (needsUpload) {const uploaded = await uploadFileStream(sourceFile);+ if (ac.signal.aborted) return;console.log("[KieAI] upload response:", uploaded);// KieAI API may return url under different field namesuploadedUrl =@@ -132,6 +133,8 @@ export function KieAIImageDialog({ open, onClose, sourceFile, previewUrl }: Prop}}+ if (ac.signal.aborted) return;+// Build model-specific inputlet input: Parameters<typeof createImageTask>[1];switch (selectedModel) {@@ -160,6 +163,9 @@ export function KieAIImageDialog({ open, onClose, sourceFile, previewUrl }: Propconsole.log("[KieAI] createTask payload:", { model: selectedModel, input });const taskId = await createImageTask(selectedModel, input);+ // Bail out if the user cancelled while the request was in flight+ if (ac.signal.aborted) return;+// Create a placeholder in the media library immediatelyconst ext = "png"; // optimistic; poller will use actual blob mimeconst base = sourceFile.name.replace(/\.[^.]+$/, "");diff --git a/apps/web/src/hooks/useKieAIPoller.ts b/apps/web/src/hooks/useKieAIPoller.tsindex 8e8a9076..19fb0ea0 100644--- a/apps/web/src/hooks/useKieAIPoller.ts+++ b/apps/web/src/hooks/useKieAIPoller.ts@@ -96,7 +96,7 @@ export function useKieAIPoller() {const record = await pollTaskOnce(task.taskId);if (record.state === "success") {- // API says done — always remove the task, even if download fails+ // API says done — remove on success, mark failed on download error (retryable)try {const url = getResultUrl(record);@@ -115,17 +115,17 @@ export function useKieAIPoller() {}await replacePlaceholderRef.current(task.mediaId, blob, task.suggestedName);+ removeTask(task.taskId);} catch (downloadErr) {console.error(`[KieAIPoller] download failed for ${task.taskId}:`, downloadErr);+ markFailed(task.taskId);setKieAIItemStateRef.current(task.mediaId, false, true);- } finally {- removeTask(task.taskId);}} else if (record.state === "fail") {console.warn(`[KieAIPoller] task ${task.taskId} failed: ${record.failMsg}`);setKieAIItemStateRef.current(task.mediaId, false, true);- removeTask(task.taskId);+ markFailed(task.taskId);} else {// Still generating — schedule next poll@@ -136,8 +136,8 @@ export function useKieAIPoller() {// Auth error — give up immediately, don't count as a retryif (err instanceof KieAIError && err.code === 401) {console.warn("[KieAIPoller] auth error — stopping poll for", task.taskId);+ markFailed(task.taskId);setKieAIItemStateRef.current(task.mediaId, false, true);- removeTask(task.taskId);return;}diff --git a/apps/web/src/stores/kieai-store.ts b/apps/web/src/stores/kieai-store.tsindex ce60c802..7e1fca6e 100644--- a/apps/web/src/stores/kieai-store.ts+++ b/apps/web/src/stores/kieai-store.ts@@ -5,7 +5,8 @@* dialog closes and page refreshes (tasks live on KieAI servers for ~3 days).** Task lifecycle:- * pending → (poll ok) → removed (success / API fail)+ * pending → (poll ok + download ok) → removed (success)+ * pending → (poll ok + download fail / API fail / auth fail) → failed ← user can retry* pending → (10 poll errors) → failed ← user can retry* failed → (user clicks retry) → pending (retries reset)*/