handle abort on upload store
This commit is contained in:
parent
e7e46c91db
commit
2f3247874d
@ -52,6 +52,10 @@ export async function upload(
|
|||||||
onError: function (error: Error | tus.DetailedError) {
|
onError: function (error: Error | tus.DetailedError) {
|
||||||
delete CURRENT_UPLOAD_LIST[filePath];
|
delete CURRENT_UPLOAD_LIST[filePath];
|
||||||
|
|
||||||
|
if (error.message === "Upload aborted") {
|
||||||
|
return reject(error);
|
||||||
|
}
|
||||||
|
|
||||||
const message =
|
const message =
|
||||||
error instanceof tus.DetailedError
|
error instanceof tus.DetailedError
|
||||||
? error.originalResponse === null
|
? error.originalResponse === null
|
||||||
|
|||||||
@ -70,7 +70,6 @@ import { useFileStore } from "@/stores/file";
|
|||||||
import { useUploadStore } from "@/stores/upload";
|
import { useUploadStore } from "@/stores/upload";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import { computed, ref, watch } from "vue";
|
import { computed, ref, watch } from "vue";
|
||||||
import { abortAllUploads } from "@/api/tus";
|
|
||||||
import buttons from "@/utils/buttons";
|
import buttons from "@/utils/buttons";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { partial } from "filesize";
|
import { partial } from "filesize";
|
||||||
@ -181,10 +180,9 @@ const toggle = () => {
|
|||||||
|
|
||||||
const abortAll = () => {
|
const abortAll = () => {
|
||||||
if (confirm(t("upload.abortUpload"))) {
|
if (confirm(t("upload.abortUpload"))) {
|
||||||
abortAllUploads();
|
|
||||||
buttons.done("upload");
|
buttons.done("upload");
|
||||||
open.value = false;
|
open.value = false;
|
||||||
uploadStore.reset(); // Resetting the upload store state
|
uploadStore.abort();
|
||||||
fileStore.reload = true; // Trigger reload in the file store
|
fileStore.reload = true; // Trigger reload in the file store
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { useFileStore } from "./file";
|
|||||||
import { files as api } from "@/api";
|
import { files as api } from "@/api";
|
||||||
import buttons from "@/utils/buttons";
|
import buttons from "@/utils/buttons";
|
||||||
import { inject, markRaw, ref } from "vue";
|
import { inject, markRaw, ref } from "vue";
|
||||||
|
import * as tus from "@/api/tus";
|
||||||
|
|
||||||
// TODO: make this into a user setting
|
// TODO: make this into a user setting
|
||||||
const UPLOADS_LIMIT = 5;
|
const UPLOADS_LIMIT = 5;
|
||||||
@ -64,6 +65,12 @@ export const useUploadStore = defineStore("upload", () => {
|
|||||||
processUploads();
|
processUploads();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const abort = () => {
|
||||||
|
// Resets the state by preventing the processing of the remaning uploads
|
||||||
|
lastUpload.value = Infinity;
|
||||||
|
tus.abortAllUploads();
|
||||||
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// PRIVATE FUNCTIONS
|
// PRIVATE FUNCTIONS
|
||||||
//
|
//
|
||||||
@ -101,7 +108,7 @@ export const useUploadStore = defineStore("upload", () => {
|
|||||||
|
|
||||||
await api
|
await api
|
||||||
.post(upload.path, upload.file!, upload.overwrite, onUpload)
|
.post(upload.path, upload.file!, upload.overwrite, onUpload)
|
||||||
.catch($showError);
|
.catch((err) => err.message !== "Upload aborted" && $showError(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
finishUpload(upload);
|
finishUpload(upload);
|
||||||
@ -154,5 +161,6 @@ export const useUploadStore = defineStore("upload", () => {
|
|||||||
|
|
||||||
// ACTIONS
|
// ACTIONS
|
||||||
upload,
|
upload,
|
||||||
|
abort,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user