Skip to content

Commit

Permalink
Add server-side tus delete handler
Browse files Browse the repository at this point in the history
  • Loading branch information
o1egl committed Apr 24, 2024
1 parent e34c1d5 commit e48235e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 24 deletions.
25 changes: 2 additions & 23 deletions frontend/src/api/tus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

1 change: 1 addition & 0 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion http/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func resourceDeleteHandler(fileCache FileCache) handleFunc {
return errToStatus(err), err
}

return http.StatusOK, nil
return http.StatusNoContent, nil
})
}

Expand Down

0 comments on commit e48235e

Please sign in to comment.