1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-06-30 06:30:11 +02:00

fix: share finishes before all files are uploaded

This commit is contained in:
Elias Schneider 2022-10-31 10:28:29 +01:00
parent 00d0df731b
commit 99de4e57e1
2 changed files with 12 additions and 11 deletions

View File

@ -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;

View File

@ -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 {