From c4e8011e994cc1cc2e3a6075cb3855a245b3a1d0 Mon Sep 17 00:00:00 2001 From: Alex Yong Date: Fri, 12 Apr 2024 19:03:48 +0000 Subject: [PATCH] Fixed an issue where aborting an upload would not delete the partial upload from the server. Also fixed an issue where the abortAll function wasn't resetting and reloading the frontend properly --- frontend/src/api/tus.ts | 25 +++++++++++++++++-- .../src/components/prompts/UploadFiles.vue | 6 ++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/frontend/src/api/tus.ts b/frontend/src/api/tus.ts index dd824357..a1e2d891 100644 --- a/frontend/src/api/tus.ts +++ b/frontend/src/api/tus.ts @@ -200,14 +200,35 @@ function calcProgress(filePath: string) { fileData.lastProgressTimestamp = Date.now(); } -export function abortAllUploads() { +export async function abortAllUploads() { + const deletePromises = []; + for (const filePath in CURRENT_UPLOAD_LIST) { if (CURRENT_UPLOAD_LIST[filePath].interval) { clearInterval(CURRENT_UPLOAD_LIST[filePath].interval); } if (CURRENT_UPLOAD_LIST[filePath].upload) { - CURRENT_UPLOAD_LIST[filePath].upload.abort(true); + //setting to false since the current tus method tries to delete against a non-existent endpoint + CURRENT_UPLOAD_LIST[filePath].upload.abort(false); //TODO figure out how to do this properly through tus } + + // Make a DELETE request to remove the file from the server + // TODO figure out how to do this properly through tus + const deleteUrl = `${baseURL}/api/resources/${filePath}`; + const deletePromise = fetchURL(deleteUrl, { + method: "DELETE" + }).then(response => { + if (response.status !== 200) { + console.error(`Failed to delete file: ${response.status} ${response.statusText}`); + } + }).catch(error => { + console.error(`Error deleting file: ${error.message}`); + }); + + deletePromises.push(deletePromise); delete CURRENT_UPLOAD_LIST[filePath]; } + + await Promise.all(deletePromises); } + diff --git a/frontend/src/components/prompts/UploadFiles.vue b/frontend/src/components/prompts/UploadFiles.vue index d3a96bc5..88a0b607 100644 --- a/frontend/src/components/prompts/UploadFiles.vue +++ b/frontend/src/components/prompts/UploadFiles.vue @@ -74,7 +74,6 @@ export default { "getETA", ]), ...mapWritableState(useFileStore, ["reload"]), - ...mapActions(useUploadStore, ["reset"]), formattedETA() { if (!this.getETA || this.getETA === Infinity) { return "--:--:--"; @@ -92,6 +91,7 @@ export default { }, }, methods: { + ...mapActions(useUploadStore, ["reset"]), // Mapping reset action from upload store toggle: function () { this.open = !this.open; }, @@ -100,8 +100,8 @@ export default { abortAllUploads(); buttons.done("upload"); this.open = false; - this.reset(); - this.reload = true; + this.reset(); // Resetting the upload store state + this.reload = true; // Trigger reload in the file store } }, },