|
|
@ -60,43 +60,53 @@ const AddFileForm: FC<AddFileFormProps> = (props) => { |
|
|
|
}, {}), |
|
|
|
}, {}), |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
files.forEach(({ file, name, uuid }) => { |
|
|
|
const promises = files.reduce<Promise<void>[]>( |
|
|
|
if (!file) return; |
|
|
|
(chain, { file, name, uuid }) => { |
|
|
|
|
|
|
|
if (!file) return chain; |
|
|
|
|
|
|
|
|
|
|
|
const data = new FormData(); |
|
|
|
const data = new FormData(); |
|
|
|
|
|
|
|
|
|
|
|
data.append('file', new File([file], name, { ...file })); |
|
|
|
data.append('file', new File([file], name, { ...file })); |
|
|
|
|
|
|
|
|
|
|
|
api |
|
|
|
const promise = api |
|
|
|
.post('/file', data, { |
|
|
|
.post('/file', data, { |
|
|
|
headers: { |
|
|
|
headers: { |
|
|
|
'Content-Type': 'multipart/form-data', |
|
|
|
'Content-Type': 'multipart/form-data', |
|
|
|
}, |
|
|
|
}, |
|
|
|
onUploadProgress: ( |
|
|
|
onUploadProgress: ( |
|
|
|
(fileUuid: string) => |
|
|
|
(fileUuid: string) => |
|
|
|
({ loaded, total }) => { |
|
|
|
({ loaded, total }) => { |
|
|
|
setUploads((previous) => |
|
|
|
setUploads((previous) => |
|
|
|
setUploadProgress( |
|
|
|
setUploadProgress( |
|
|
|
previous, |
|
|
|
previous, |
|
|
|
fileUuid, |
|
|
|
fileUuid, |
|
|
|
Math.round( |
|
|
|
Math.round( |
|
|
|
(loaded / total) * REQUEST_INCOMPLETE_UPLOAD_LIMIT, |
|
|
|
(loaded / total) * REQUEST_INCOMPLETE_UPLOAD_LIMIT, |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
)(uuid), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.then( |
|
|
|
|
|
|
|
((fileUuid: string) => () => { |
|
|
|
|
|
|
|
setUploads((previous) => |
|
|
|
|
|
|
|
setUploadProgress(previous, fileUuid, 100), |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
})(uuid), |
|
|
|
)(uuid), |
|
|
|
); |
|
|
|
}) |
|
|
|
|
|
|
|
.then( |
|
|
|
chain.push(promise); |
|
|
|
((fileUuid: string) => () => { |
|
|
|
|
|
|
|
setUploads((previous) => |
|
|
|
return chain; |
|
|
|
setUploadProgress(previous, fileUuid, 100), |
|
|
|
}, |
|
|
|
); |
|
|
|
[], |
|
|
|
})(uuid), |
|
|
|
); |
|
|
|
) |
|
|
|
|
|
|
|
.catch((error) => { |
|
|
|
Promise.all(promises).catch((error) => { |
|
|
|
handleAPIError(error); |
|
|
|
const emsg = handleAPIError(error); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
emsg.children = <>Failed to add file. {emsg.children}</>; |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
validationSchema: fileListSchema, |
|
|
|
validationSchema: fileListSchema, |
|
|
|