return file extension on upload; strip extension when returning upload

This commit is contained in:
2026-11-10 21:12:34 -05:00
parent a59c32e503
commit 3a336b79c8
+8 -6
View File
@@ -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)