mirror of
https://github.com/stonith404/pingvin-share.git
synced 2025-01-15 01:14:27 -05:00
fix: share finishes before all files are uploaded
This commit is contained in:
parent
00d0df731b
commit
99de4e57e1
2 changed files with 12 additions and 11 deletions
|
@ -41,13 +41,11 @@ const Upload = () => {
|
|||
);
|
||||
share = await shareService.create(id, expiration, security);
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const progressCallBack = (bytesProgress: number) => {
|
||||
const progressCallBack = (progress: number) => {
|
||||
setFiles((files) => {
|
||||
return files.map((file, callbackIndex) => {
|
||||
if (i == callbackIndex) {
|
||||
file.uploadingProgress = Math.round(
|
||||
(100 * bytesProgress) / files[i].size
|
||||
);
|
||||
file.uploadingProgress = progress;
|
||||
}
|
||||
return file;
|
||||
});
|
||||
|
@ -77,7 +75,6 @@ const Upload = () => {
|
|||
(file) => file.uploadingProgress >= 100 || file.uploadingProgress == -1
|
||||
)
|
||||
) {
|
||||
console.log(files.length);
|
||||
const fileErrorCount = files.filter(
|
||||
(file) => file.uploadingProgress == -1
|
||||
).length;
|
||||
|
|
|
@ -75,12 +75,16 @@ const uploadFile = async (
|
|||
let formData = new FormData();
|
||||
formData.append("file", file);
|
||||
|
||||
return (
|
||||
await api.post(`shares/${shareId}/files`, formData, {
|
||||
onUploadProgress: (progressEvent) =>
|
||||
progressCallBack(progressEvent.loaded),
|
||||
})
|
||||
).data;
|
||||
const response = await api.post(`shares/${shareId}/files`, formData, {
|
||||
onUploadProgress: (progressEvent) => {
|
||||
const uploadingProgress = Math.round(
|
||||
(100 * progressEvent.loaded) / progressEvent.total
|
||||
);
|
||||
if (uploadingProgress < 100) progressCallBack(uploadingProgress);
|
||||
},
|
||||
});
|
||||
progressCallBack(100);
|
||||
return response;
|
||||
};
|
||||
|
||||
export default {
|
||||
|
|
Loading…
Add table
Reference in a new issue