🐛 修复上传阶段状态与重试进度
补齐预签名和分片上传的初始化、上传、确认、成功与失败状态回调,使用实际上传对象的进度字节避免 ZIP 选中文件计数失真,并在新提交前清理旧错误状态。 - 空提交校验不再进入 uploading 状态,失败保留文件以便重试 - 完成架构检查、类型检查和生产构建验证
This commit is contained in:
1 parent
84ddf92b20
commit
43ebc8c1b2
4 files changed
+32
-14
No files matched your search
@@ -14,6 +14,7 @@ type ChunkedUploadOptions = {
|
||||
chunkFailed?: (index: number) => string
|
||||
completeFailed?: string
|
||||
}
|
||||
onStatus?: (status: 'initializing' | 'uploading' | 'confirming' | 'success' | 'error') => void
|
||||
}
|
||||
|
||||
type ChunkedUploadResult = ChunkUploadInitResponse | FileUploadResponse
|
||||
@@ -29,6 +30,7 @@ export const uploadChunkedFile = async (
|
||||
file: File,
|
||||
options: ChunkedUploadOptions
|
||||
): Promise<ApiResponse<ChunkedUploadResult>> => {
|
||||
options.onStatus?.('initializing')
|
||||
const fileHash = await calculateFileHash(file)
|
||||
options.onHashCalculated?.(fileHash)
|
||||
|
||||
@@ -55,6 +57,7 @@ export const uploadChunkedFile = async (
|
||||
}
|
||||
|
||||
const uploadedChunks = new Set(initDetail.uploaded_chunks || [])
|
||||
options.onStatus?.('uploading')
|
||||
for (let index = 0; index < chunks; index++) {
|
||||
if (uploadedChunks.has(index)) {
|
||||
continue
|
||||
@@ -84,14 +87,17 @@ export const uploadChunkedFile = async (
|
||||
uploadedChunks.add(index)
|
||||
}
|
||||
|
||||
options.onStatus?.('confirming')
|
||||
const completeResponse = await FileService.completeChunkUpload(uploadId, {
|
||||
expire_value: options.expireValue,
|
||||
expire_style: options.expireStyle
|
||||
})
|
||||
|
||||
if (completeResponse.code !== 200) {
|
||||
options.onStatus?.('error')
|
||||
throw new Error(options.messages?.completeFailed || 'Complete chunk upload failed')
|
||||
}
|
||||
|
||||
options.onStatus?.('success')
|
||||
return completeResponse
|
||||
}
|
||||
Reference in new issue
Block a user