mirror of
https://github.com/stonith404/pingvin-share.git
synced 2025-01-29 01:28:59 -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);
|
share = await shareService.create(id, expiration, security);
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
const progressCallBack = (bytesProgress: number) => {
|
const progressCallBack = (progress: number) => {
|
||||||
setFiles((files) => {
|
setFiles((files) => {
|
||||||
return files.map((file, callbackIndex) => {
|
return files.map((file, callbackIndex) => {
|
||||||
if (i == callbackIndex) {
|
if (i == callbackIndex) {
|
||||||
file.uploadingProgress = Math.round(
|
file.uploadingProgress = progress;
|
||||||
(100 * bytesProgress) / files[i].size
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
});
|
});
|
||||||
|
@ -77,7 +75,6 @@ const Upload = () => {
|
||||||
(file) => file.uploadingProgress >= 100 || file.uploadingProgress == -1
|
(file) => file.uploadingProgress >= 100 || file.uploadingProgress == -1
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
console.log(files.length);
|
|
||||||
const fileErrorCount = files.filter(
|
const fileErrorCount = files.filter(
|
||||||
(file) => file.uploadingProgress == -1
|
(file) => file.uploadingProgress == -1
|
||||||
).length;
|
).length;
|
||||||
|
|
|
@ -75,12 +75,16 @@ const uploadFile = async (
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append("file", file);
|
formData.append("file", file);
|
||||||
|
|
||||||
return (
|
const response = await api.post(`shares/${shareId}/files`, formData, {
|
||||||
await api.post(`shares/${shareId}/files`, formData, {
|
onUploadProgress: (progressEvent) => {
|
||||||
onUploadProgress: (progressEvent) =>
|
const uploadingProgress = Math.round(
|
||||||
progressCallBack(progressEvent.loaded),
|
(100 * progressEvent.loaded) / progressEvent.total
|
||||||
})
|
);
|
||||||
).data;
|
if (uploadingProgress < 100) progressCallBack(uploadingProgress);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
progressCallBack(100);
|
||||||
|
return response;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
Loading…
Add table
Reference in a new issue