From 4c25a66f0f03c7a1ab07bf23394b9a96865cb498 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Tue, 10 Nov 2026 12:05:33 -0500 Subject: [PATCH] delete token & upload response struct to return delete token and sha256 as hex --- database.go | 1 + handlers.go | 15 ++++++++++++--- templates/home.html | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/database.go b/database.go index 62f61db..62d02d2 100644 --- a/database.go +++ b/database.go @@ -25,6 +25,7 @@ type Upload struct { CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime" json:"created_at"` ExpiresAt *int64 `gorm:"column:expires_at;index" json:"expires_at"` // null means no expiration LastAccessedAt int64 `gorm:"column:last_accessed_at;not null;autoCreateTime;index" json:"last_accessed_at"` + DeleteToken string `gorm:"column:delete_token;not null" json:"-"` } func initDatabase(path string) (*gorm.DB, error) { diff --git a/handlers.go b/handlers.go index df41ac2..1239755 100644 --- a/handlers.go +++ b/handlers.go @@ -34,6 +34,11 @@ type uploadInput struct { MIMEType string Type ContentType } +type UploadResponse struct { + Upload + SHA256 string `json:"sha256"` + DeleteToken string `json:"deleteToken"` +} func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -56,7 +61,7 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc { idLength = 10 } - var input uploadInput + var input UploadInput switch mediaType { case "multipart/form-data": // file uploads r.Body = http.MaxBytesReader(w, r.Body, cfg.MaxFileBytes) @@ -115,7 +120,7 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc { return } - input = uploadInput{ + input = UploadInput{ Reader: strings.NewReader(content), Filename: "paste.txt", MIMEType: "text/plain; charset=utf-8", @@ -196,7 +201,11 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc { saved = true w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) - if err := json.NewEncoder(w).Encode(upload); err != nil { + if err := json.NewEncoder(w).Encode(UploadResponse{ + Upload: upload, + SHA256: hex.EncodeToString(upload.SHA256), + DeleteToken: upload.DeleteToken, + }); err != nil { log.Println("failed to encode response:", err) } } diff --git a/templates/home.html b/templates/home.html index 2502d36..c57c529 100644 --- a/templates/home.html +++ b/templates/home.html @@ -8,13 +8,13 @@

{{.Title}}

{{.Description}}

-
+
-
+