From 4ee86d0fc49148100e11cfcdfd7de009f820424c Mon Sep 17 00:00:00 2001 From: Bagas Aulia Rezki Date: Sun, 15 Sep 2024 17:41:33 +0700 Subject: [PATCH] Cancel file upload when session is terminated --- handler/file/upload/upload.go | 1 + public/main.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/handler/file/upload/upload.go b/handler/file/upload/upload.go index fc0d876..9bc35ed 100644 --- a/handler/file/upload/upload.go +++ b/handler/file/upload/upload.go @@ -93,5 +93,6 @@ func POST(w http.ResponseWriter, r *http.Request) { return } + w.WriteHeader(http.StatusAccepted) return } diff --git a/public/main.js b/public/main.js index 65b09be..7aaa08f 100644 --- a/public/main.js +++ b/public/main.js @@ -163,10 +163,17 @@ async function uploadChunks(name, size, chunks, chunkArray, FileID) { const startTime = performance.now(); try { - await fetch(`/file/${FileID}`, { + const request = await fetch(`/file/${FileID}`, { method: 'POST', body: formData }); + console.log(request.status) + if (request.status !== 202) { + ChangeModal("Error", "There was an issue with your upload. Please try again later or contact support if the problem persists.") + toggleModal(); + isFailed = true + break + } } catch (error) { ChangeModal("Error", "There was an issue with your upload. Please try again later or contact support if the problem persists.") toggleModal();