From 4bf0e22bc228d851e52df40b911f7f106d8c2353 Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Tue, 22 Oct 2024 15:22:32 +0700 Subject: [PATCH] feat: add abort upload and upload progress handler --- src/stores/utils/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/stores/utils/index.ts b/src/stores/utils/index.ts index 6e376bc0..70aa2cde 100644 --- a/src/stores/utils/index.ts +++ b/src/stores/utils/index.ts @@ -356,15 +356,20 @@ export function manageFile( parentId: string; fileId: string; file: File; + onUploadProgress?: (e: AxiosProgressEvent) => void; + abortController?: AbortController; }) => { const res = await api.put( `/${base}/${opts.parentId}/file-${opts.group}/${opts.fileId}`, opts.file, { headers: { 'Content-Type': opts.file.type }, - onUploadProgress: option?.onUploadProgress - ? option.onUploadProgress - : (e) => console.log(e), + onUploadProgress: opts.onUploadProgress + ? opts.onUploadProgress + : option?.onUploadProgress + ? option.onUploadProgress + : (e) => console.log(e), + signal: opts.abortController?.signal, }, ); if (res.status < 400) return true;