delete token & upload response struct to return delete token and sha256 as hex

This commit is contained in:
2026-11-10 12:05:33 -05:00
parent 33b1b579d6
commit 4c25a66f0f
3 changed files with 15 additions and 5 deletions
+12 -3
View File
@@ -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)
}
}