handle abort on upload store

This commit is contained in:
Ramires Viana 2025-08-05 18:01:17 -03:00
parent e7e46c91db
commit 2f3247874d
3 changed files with 14 additions and 4 deletions

View File

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

View File

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

View File

@ -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,
};
});