Line data Source code
1 : import type { UploadImageResponse } from '@comfyorg/ingest-types'
2 :
3 : import { useToast } from '@/components/ui/toast/toastStore'
4 : import { t } from '@/i18n'
5 : import { api } from '@/scripts/api'
6 :
7 : type TempFileUpload =
8 : | { ok: true; file: UploadImageResponse }
9 : | { ok: false; reason: string }
10 :
11 12 : export async function uploadTempFile(
12 : file: File,
13 : subfolder: string
14 : ): Promise<TempFileUpload> {
15 12 : const body = new FormData()
16 12 : body.append('image', file)
17 12 : body.append('subfolder', subfolder)
18 12 : body.append('type', 'temp')
19 :
20 12 : const resp = await api.fetchApi('/upload/image', { method: 'POST', body })
21 12 : if (resp.status !== 200) {
22 1 : const reason = `${resp.status} - ${resp.statusText}`
23 1 : useToast().warning(t('g.uploadFailed', { reason }))
24 1 : return { ok: false, reason }
25 : }
26 11 : return { file: await resp.json(), ok: true }
27 : }
|