Skip to content

Commit

Permalink
fix: share finishes before all files are uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Oct 31, 2022
1 parent 00d0df7 commit 99de4e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
7 changes: 2 additions & 5 deletions frontend/src/pages/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 10 additions & 6 deletions frontend/src/services/share.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 99de4e5

Please sign in to comment.