Skip to content

Commit

Permalink
fix: race condition on file upload/download state
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
pedrolamas committed May 31, 2024
1 parent df59f78 commit 9ae83b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/mixins/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export default class FilesMixin extends Vue {
...options,
signal: abortController.signal,
onDownloadProgress: (event: AxiosProgressEvent) => {
if (abortController.signal.aborted) {
return
}

const progress = event.progress ?? (
size > 0
? event.loaded / size
Expand All @@ -112,6 +116,8 @@ export default class FilesMixin extends Vue {
}
})

abortController.abort()

return response
} finally {
this.$store.dispatch('files/removeFileDownload')
Expand Down Expand Up @@ -192,6 +198,10 @@ export default class FilesMixin extends Vue {
...options,
signal: abortController.signal,
onUploadProgress: (event: AxiosProgressEvent) => {
if (abortController.signal.aborted) {
return
}

this.$store.dispatch('files/updateFileUpload', {
filepath,
loaded: event.loaded,
Expand All @@ -201,6 +211,8 @@ export default class FilesMixin extends Vue {
}
})

abortController.abort()

return response
} finally {
this.$store.dispatch('files/removeFileUpload', filepath)
Expand Down
13 changes: 3 additions & 10 deletions src/store/files/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,9 @@ export const mutations: MutationTree<FilesState> = {
},

setUpdateFileDownload (state, payload) {
if (
!state.download ||
state.download === null
) {
state.download = payload
} else {
state.download = {
...state.download,
...payload
}
state.download = {
...state.download,
...payload
}
},

Expand Down

0 comments on commit 9ae83b6

Please sign in to comment.