🐛 fix(upload): 小文件分片不超过实际文件大小

This commit is contained in:
orion committed 2026-09-18 16:21:41 +08:00
1 parent f2461378ef
commit a962f7aec7
2 files changed
+7 -1

No files matched your search

+1 -1
View File
@@ -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
})
@@ -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}
})