Compare commits

...

2 Commits

Author SHA1 Message Date
Johnpaul Chiwetelu
fb559ac5ac Merge branch 'main' into fix/coderabbit-issue-9226 2026-03-10 02:21:27 +01:00
CodeRabbit Fixer
c971cb5646 fix: Add timeout and abort mechanism for image upload (#9226)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 17:49:33 +01:00
2 changed files with 14 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ import { api } from '@/scripts/api'
import { useAssetsStore } from '@/stores/assetsStore'
const PASTED_IMAGE_EXPIRY_MS = 2000
const UPLOAD_TIMEOUT_MS = 120_000
interface ImageUploadFormFields {
/**
@@ -28,11 +29,17 @@ const uploadFile = async (
if (isPasted) body.append('subfolder', 'pasted')
if (formFields.type) body.append('type', formFields.type)
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), UPLOAD_TIMEOUT_MS)
const resp = await api.fetchApi('/upload/image', {
method: 'POST',
body
body,
signal: controller.signal
})
clearTimeout(timeoutId)
if (resp.status !== 200) {
useToastStore().addAlert(resp.status + ' - ' + resp.statusText)
return
@@ -88,7 +95,11 @@ export const useNodeImageUpload = (
if (!path) return
return path
} catch (error) {
useToastStore().addAlert(String(error))
if (error instanceof DOMException && error.name === 'AbortError') {
useToastStore().addAlert(t('g.uploadTimedOut'))
} else {
useToastStore().addAlert(String(error))
}
}
}

View File

@@ -176,6 +176,7 @@
"control_before_generate": "control before generate",
"choose_file_to_upload": "choose file to upload",
"uploadAlreadyInProgress": "Upload already in progress",
"uploadTimedOut": "Upload timed out. Please try again.",
"capture": "capture",
"nodes": "Nodes",
"nodesCount": "{count} node | {count} nodes",