Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Upload] fix uploadAllFilesInOneRequest and requestMethod #1587

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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