From e48235e395882268ebf537514ba20b058c8a3bfb Mon Sep 17 00:00:00 2001 From: Oleg Lobanov Date: Thu, 25 Apr 2024 01:21:49 +0200 Subject: [PATCH] Add server-side tus delete handler --- frontend/src/api/tus.ts | 25 ++----------------------- http/http.go | 1 + http/resource.go | 2 +- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/frontend/src/api/tus.ts b/frontend/src/api/tus.ts index a1e2d891..dd824357 100644 --- a/frontend/src/api/tus.ts +++ b/frontend/src/api/tus.ts @@ -200,35 +200,14 @@ function calcProgress(filePath: string) { fileData.lastProgressTimestamp = Date.now(); } -export async function abortAllUploads() { - const deletePromises = []; - +export function abortAllUploads() { 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) { - //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 + CURRENT_UPLOAD_LIST[filePath].upload.abort(true); } - - // 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/http/http.go b/http/http.go index f91ec426..620c43fd 100644 --- a/http/http.go +++ b/http/http.go @@ -69,6 +69,7 @@ func NewHandler( api.PathPrefix("/tus").Handler(monkey(tusPostHandler(), "/api/tus")).Methods("POST") api.PathPrefix("/tus").Handler(monkey(tusHeadHandler(), "/api/tus")).Methods("HEAD", "GET") api.PathPrefix("/tus").Handler(monkey(tusPatchHandler(), "/api/tus")).Methods("PATCH") + api.PathPrefix("/tus").Handler(monkey(resourceDeleteHandler(fileCache), "/api/tus")).Methods("DELETE") api.PathPrefix("/usage").Handler(monkey(diskUsage, "/api/usage")).Methods("GET") diff --git a/http/resource.go b/http/resource.go index 11fa2930..f03f17fb 100644 --- a/http/resource.go +++ b/http/resource.go @@ -87,7 +87,7 @@ func resourceDeleteHandler(fileCache FileCache) handleFunc { return errToStatus(err), err } - return http.StatusOK, nil + return http.StatusNoContent, nil }) }