From a962f7aec7c222b1545ecb3774e95d534b1219e9 Mon Sep 17 00:00:00 2001 From: Orion Date: Fri, 18 Sep 2026 16:21:41 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(upload):=20=E5=B0=8F?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=88=86=E7=89=87=E4=B8=8D=E8=B6=85=E8=BF=87?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/upload-strategy.ts | 2 +- tests/uploadStrategy.integration.test.mjs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/services/upload-strategy.ts b/src/services/upload-strategy.ts index 8969086..5273812 100644 --- a/src/services/upload-strategy.ts +++ b/src/services/upload-strategy.ts @@ -59,7 +59,7 @@ export const uploadChunkedFile = async ( const initResponse = await FileService.initChunkUpload({ file_name: file.name, file_size: file.size, - chunk_size: CHUNK_SIZE, + chunk_size: Math.min(CHUNK_SIZE, file.size), file_hash: fileHash }) diff --git a/tests/uploadStrategy.integration.test.mjs b/tests/uploadStrategy.integration.test.mjs index 29d5c45..0c4ad87 100644 --- a/tests/uploadStrategy.integration.test.mjs +++ b/tests/uploadStrategy.integration.test.mjs @@ -22,3 +22,9 @@ test('manual retry after lost completion response reuses upload id and never ret assert.equal(result.detail.code,'ORIGINAL');assert.equal(inits,1);assert.equal(chunks,1);assert.equal(completions,5) }finally{service.initChunkUpload=originals.init;service.uploadChunk=originals.chunk;service.completeChunkUpload=originals.complete;globalThis.window=previousWindow} }) +test('small file initialization never requests a chunk bigger than the file',async()=>{ + const originalInit=service.initChunkUpload;let size + const previousWindow=globalThis.window;globalThis.window={isSecureContext:true} + service.initChunkUpload=async request=>{size=request.chunk_size;return {code:200,detail:{existed:true,code:'existing'}}} + try{await upload(new File(['small'],'a.txt'),{expireValue:1,expireStyle:'day'});assert.equal(size,5)}finally{service.initChunkUpload=originalInit;globalThis.window=previousWindow} +})