From 2f3247874dffaf74175f79501abc57e2621cfd3a Mon Sep 17 00:00:00 2001 From: Ramires Viana <59319979+ramiresviana@users.noreply.github.com> Date: Tue, 5 Aug 2025 18:01:17 -0300 Subject: [PATCH] handle abort on upload store --- frontend/src/api/tus.ts | 4 ++++ frontend/src/components/prompts/UploadFiles.vue | 4 +--- frontend/src/stores/upload.ts | 10 +++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/frontend/src/api/tus.ts b/frontend/src/api/tus.ts index 2609d258..d6601166 100644 --- a/frontend/src/api/tus.ts +++ b/frontend/src/api/tus.ts @@ -52,6 +52,10 @@ export async function upload( onError: function (error: Error | tus.DetailedError) { delete CURRENT_UPLOAD_LIST[filePath]; + if (error.message === "Upload aborted") { + return reject(error); + } + const message = error instanceof tus.DetailedError ? error.originalResponse === null diff --git a/frontend/src/components/prompts/UploadFiles.vue b/frontend/src/components/prompts/UploadFiles.vue index 3e382472..1cb9982c 100644 --- a/frontend/src/components/prompts/UploadFiles.vue +++ b/frontend/src/components/prompts/UploadFiles.vue @@ -70,7 +70,6 @@ import { useFileStore } from "@/stores/file"; import { useUploadStore } from "@/stores/upload"; import { storeToRefs } from "pinia"; import { computed, ref, watch } from "vue"; -import { abortAllUploads } from "@/api/tus"; import buttons from "@/utils/buttons"; import { useI18n } from "vue-i18n"; import { partial } from "filesize"; @@ -181,10 +180,9 @@ const toggle = () => { const abortAll = () => { if (confirm(t("upload.abortUpload"))) { - abortAllUploads(); buttons.done("upload"); open.value = false; - uploadStore.reset(); // Resetting the upload store state + uploadStore.abort(); fileStore.reload = true; // Trigger reload in the file store } }; diff --git a/frontend/src/stores/upload.ts b/frontend/src/stores/upload.ts index 1349ecfe..023b3808 100644 --- a/frontend/src/stores/upload.ts +++ b/frontend/src/stores/upload.ts @@ -3,6 +3,7 @@ import { useFileStore } from "./file"; import { files as api } from "@/api"; import buttons from "@/utils/buttons"; import { inject, markRaw, ref } from "vue"; +import * as tus from "@/api/tus"; // TODO: make this into a user setting const UPLOADS_LIMIT = 5; @@ -64,6 +65,12 @@ export const useUploadStore = defineStore("upload", () => { processUploads(); }; + const abort = () => { + // Resets the state by preventing the processing of the remaning uploads + lastUpload.value = Infinity; + tus.abortAllUploads(); + }; + // // PRIVATE FUNCTIONS // @@ -101,7 +108,7 @@ export const useUploadStore = defineStore("upload", () => { await api .post(upload.path, upload.file!, upload.overwrite, onUpload) - .catch($showError); + .catch((err) => err.message !== "Upload aborted" && $showError(err)); } finishUpload(upload); @@ -154,5 +161,6 @@ export const useUploadStore = defineStore("upload", () => { // ACTIONS upload, + abort, }; });