From e216e2a1b583ebef0bd6296f85073c488f2008b0 Mon Sep 17 00:00:00 2001 From: jabuxas Date: Tue, 29 Oct 2024 17:51:27 -0300 Subject: [PATCH] feat: add longer url if "secret" field is present --- handlers.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/handlers.go b/handlers.go index d674385..f225b23 100644 --- a/handlers.go +++ b/handlers.go @@ -160,6 +160,10 @@ func (app *Application) formHandler(w http.ResponseWriter, r *http.Request) { filename := app.publicURL(file, ".txt") + if len(r.Form["secret"]) == 0 { + filename = filename[:8] + } + // reopening file because hash consumes it file, err = os.Open("/tmp/file.txt") if err != nil { @@ -196,6 +200,10 @@ func (app *Application) curlHandler(w http.ResponseWriter, r *http.Request) { filename := app.publicURL(file, filepath.Ext(handler.Filename)) + if len(r.Form["secret"]) == 0 { + filename = filename[:8] + } + // reopen the file for copying, as the hash process consumed the file reader file, _, err = r.FormFile("file") if err != nil { @@ -204,8 +212,7 @@ func (app *Application) curlHandler(w http.ResponseWriter, r *http.Request) { } defer file.Close() - err = SaveFile(app.lastUploadedFile, file) - if err != nil { + if err = SaveFile(app.lastUploadedFile, file); err != nil { fmt.Fprintf(w, "Error parsing file: %s", err.Error()) }