From e51eb1d86cca77c7fdd85ac0abfeacc1b8406d2b Mon Sep 17 00:00:00 2001 From: Kwonunn Date: Sun, 16 Jun 2024 14:39:09 +0200 Subject: [PATCH] Delete guest tokens after usage --- internal/webserver/fileupload/FileUpload.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/webserver/fileupload/FileUpload.go b/internal/webserver/fileupload/FileUpload.go index 1d345e3..43fb3e9 100644 --- a/internal/webserver/fileupload/FileUpload.go +++ b/internal/webserver/fileupload/FileUpload.go @@ -1,15 +1,17 @@ package fileupload import ( + "io" + "net/http" + "strconv" + "time" + "github.com/forceu/gokapi/internal/configuration" "github.com/forceu/gokapi/internal/configuration/database" "github.com/forceu/gokapi/internal/models" "github.com/forceu/gokapi/internal/storage" "github.com/forceu/gokapi/internal/storage/chunking" - "io" - "net/http" - "strconv" - "time" + "github.com/forceu/gokapi/internal/webserver/guestupload" ) // Process processes a file upload request @@ -83,6 +85,13 @@ func CompleteChunk(w http.ResponseWriter, r *http.Request, isApiCall bool) error return err } _, _ = io.WriteString(w, result.ToJsonResult(config.ExternalUrl)) + + // If an UploadToken was used, delete it + tokens, ok := r.URL.Query()["token"] + if ok && guestupload.IsValidUploadToken(tokens[0]) { + guestupload.DeleteUploadToken(tokens[0]) + } + return nil }