Skip to content

Commit

Permalink
feat(web): upload, uploadAllFilesInOneRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepluo committed Sep 3, 2023
1 parent 9cfa842 commit 7632211
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions js/upload/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,19 @@ function updateUploadedFiles(uploadFiles: UploadFile[], resultFiles: UploadFile[
(item.raw && item.raw === file.raw) || (item.name && item.name === file.name)
));
const tmpFile = index >= 0 ? { ...uploadFiles[index], ...file } : file;
if (uploadFiles[index]) {
uploadFiles[index].status = tmpFile.status;
uploadFiles[index].percent = tmpFile.percent;
} else {
log.error('Upload', 'some files upload failed');
}
newFiles.push(tmpFile);
}
for (let i = 0, len = uploadFiles.length; i < len; i++) {
if (uploadFiles[i].status !== 'success') {
uploadFiles[i].status = 'fail';
}
}
return newFiles;
}

Expand All @@ -268,12 +279,13 @@ Promise<UploadRequestReturn> {
// 所有文件一次性上传
if (uploadAllFilesInOneRequest || !params.multiple) {
uploadOneRequest(params).then((r) => {
let files = r.data?.files || r.data?.response?.files || [];
if (r.status === 'success') {
r.data.files = isBatchUpload || !params.multiple
? r.data.files
: updateUploadedFiles(uploadedFiles, r.data.files);
files = isBatchUpload || !params.multiple
? files
: updateUploadedFiles(uploadedFiles, files);
}
const failedFiles = r.status === 'fail' ? r.data.files : [];
const failedFiles = r.status === 'fail' ? files : [];
resolve({ ...r, failedFiles });
});
return;
Expand Down

0 comments on commit 7632211

Please sign in to comment.