From 8e9435ee7d986d157e8bdde616b5909825623f74 Mon Sep 17 00:00:00 2001 From: Zhou Weidong <502333560@qq.com> Date: Mon, 19 Oct 2026 18:38:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(web):=20=E4=BF=AE=E5=A4=8D=E5=88=86?= =?UTF-8?q?=E7=89=87=E4=B8=8A=E4=BC=A0=20chunkSize=20=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E6=8B=BC=E6=8E=A5=E5=AF=BC=E8=87=B4=E5=A4=A7=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=B6=85=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/uploader.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/utils/uploader.ts b/src/utils/uploader.ts index 4e026b0..2bbddbb 100644 --- a/src/utils/uploader.ts +++ b/src/utils/uploader.ts @@ -32,8 +32,9 @@ export async function uploadFile(file: File, options: UploadFileOptions = {}): P bizType }) const info = initRes.data + const chunkSize = Number(info.chunkSize) options.onSession?.(info.uploadId) - const total = Math.max(info.totalChunks, 1) + const total = Math.max(Number(info.totalChunks), 1) const pending: number[] = Array.from({ length: total }, (_, index) => index) let finished = 0 @@ -41,8 +42,8 @@ export async function uploadFile(file: File, options: UploadFileOptions = {}): P for (;;) { const index = pending.shift() if (index === undefined) return - const start = index * info.chunkSize - const chunk = file.slice(start, Math.min(start + info.chunkSize, file.size)) + const start = index * chunkSize + const chunk = file.slice(start, Math.min(start + chunkSize, file.size)) await uploadChunkApi(info.uploadId, index, chunk, file.name) finished += 1 onProgress?.(Math.min(95, Math.round((finished / total) * 95))) @@ -68,7 +69,8 @@ export async function resumeUpload( ): Promise { const { concurrency = 3, onProgress } = options const progress = (await getUploadProgressApi(uploadId)).data - const total = Math.max(progress.totalChunks, 1) + const chunkSize = Number(progress.chunkSize) + const total = Math.max(Number(progress.totalChunks), 1) const received = Math.min(progress.receivedChunks || 0, total) const pending: number[] = [] for (let index = received; index < total; index += 1) { @@ -81,8 +83,8 @@ export async function resumeUpload( for (;;) { const index = pending.shift() if (index === undefined) return - const start = index * progress.chunkSize - const chunk = file.slice(start, Math.min(start + progress.chunkSize, file.size)) + const start = index * chunkSize + const chunk = file.slice(start, Math.min(start + chunkSize, file.size)) await uploadChunkApi(uploadId, index, chunk, file.name) finished += 1 onProgress?.(Math.min(95, Math.round((finished / total) * 95)))