return file extension on upload; strip extension when returning upload
This commit is contained in:
+3
-1
@@ -42,6 +42,7 @@ type UploadResponse struct {
|
||||
Upload
|
||||
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 {
|
||||
@@ -220,6 +221,7 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user