From a404fb043da2573bf04385863b2d34b1f918b8e1 Mon Sep 17 00:00:00 2001 From: M A E R Y O Date: Mon, 28 Aug 2023 06:59:49 +0900 Subject: [PATCH] feat: implement abort upload functionality (#2673) --- frontend/src/api/tus.js | 22 ++++++++++++++++++ .../src/components/prompts/UploadFiles.vue | 23 +++++++++++++++++-- frontend/src/i18n/en.json | 3 +++ frontend/src/store/getters.js | 6 ++--- frontend/src/store/mutations.js | 7 ++++++ 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/frontend/src/api/tus.js b/frontend/src/api/tus.js index bda4f40c..f2e613e2 100644 --- a/frontend/src/api/tus.js +++ b/frontend/src/api/tus.js @@ -6,6 +6,7 @@ import { fetchURL } from "./utils"; const RETRY_BASE_DELAY = 1000; const RETRY_MAX_DELAY = 20000; +const CURRENT_UPLOAD_LIST = {}; export async function upload( filePath, @@ -34,6 +35,7 @@ export async function upload( "X-Auth": store.state.jwt, }, onError: function (error) { + delete CURRENT_UPLOAD_LIST[filePath]; reject("Upload failed: " + error); }, onProgress: function (bytesUploaded) { @@ -44,10 +46,12 @@ export async function upload( } }, onSuccess: function () { + delete CURRENT_UPLOAD_LIST[filePath]; resolve(); }, }); upload.start(); + CURRENT_UPLOAD_LIST[filePath] = upload; }); } @@ -88,3 +92,21 @@ export async function useTus(content) { function isTusSupported() { return tus.isSupported === true; } + +export function abortUpload(filePath) { + const upload = CURRENT_UPLOAD_LIST[filePath]; + if (upload) { + upload.abort(); + delete CURRENT_UPLOAD_LIST[filePath]; + } +} + +export function abortAllUploads() { + for (let filePath in CURRENT_UPLOAD_LIST) { + const upload = CURRENT_UPLOAD_LIST[filePath]; + if (upload) { + upload.abort(); + delete CURRENT_UPLOAD_LIST[filePath]; + } + } +} \ No newline at end of file diff --git a/frontend/src/components/prompts/UploadFiles.vue b/frontend/src/components/prompts/UploadFiles.vue index 37ea3a36..b9336c9a 100644 --- a/frontend/src/components/prompts/UploadFiles.vue +++ b/frontend/src/components/prompts/UploadFiles.vue @@ -7,7 +7,14 @@

{{ $t("prompts.uploadFiles", { files: filesInUploadCount }) }}

- +