From 3a336b79c8efef3ba8621c0cc4d4e1b9b6c12db1 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Tue, 10 Nov 2026 21:12:34 -0500 Subject: [PATCH] return file extension on upload; strip extension when returning upload --- handlers.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/handlers.go b/handlers.go index 10ae25e..f165d63 100644 --- a/handlers.go +++ b/handlers.go @@ -40,8 +40,9 @@ type UploadInput struct { } type UploadResponse struct { Upload - SHA256 string `json:"sha256"` - DeleteToken string `json:"deleteToken"` + SHA256 string `json:"sha256"` + DeleteToken string `json:"deleteToken"` + FileExtension string `json:"extension"` // useful for things like sharex to append the extension } func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc { @@ -217,9 +218,10 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) if err := json.NewEncoder(w).Encode(UploadResponse{ - Upload: upload, - SHA256: hex.EncodeToString(upload.SHA256), - DeleteToken: upload.DeleteToken, + Upload: upload, + SHA256: hex.EncodeToString(upload.SHA256), + DeleteToken: upload.DeleteToken, + FileExtension: filepath.Ext(upload.Filename), }); err != nil { log.Println("failed to encode response:", err) } @@ -228,7 +230,7 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc { func contentHandler(db *gorm.DB, cfg Config) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - id := r.PathValue("id") + id, _, _ := strings.Cut(r.PathValue("id"), ".") // remove any extension via strings.Cut if !validPasteId(id) { http.NotFound(w, r)