improve dnd; prevent large files early on upload

This commit is contained in:
2026-11-21 19:28:44 -05:00
parent 67849def05
commit 8fc87ab200
8 changed files with 64 additions and 15 deletions
+7 -1
View File
@@ -53,8 +53,14 @@ func UploadHandler(db *gorm.DB, cfg config.Config, p *pages.Pages) http.HandlerF
return
}
maxUploadSize := max(cfg.MaxFileBytes, cfg.MaxPasteBytes)
if r.ContentLength > maxUploadSize {
p.HTTPError(w, r, "upload too large", http.StatusRequestEntityTooLarge)
return
}
// use the largest of the sizes, and then do another size check per type down the line
r.Body = http.MaxBytesReader(w, r.Body, max(cfg.MaxFileBytes, cfg.MaxPasteBytes))
r.Body = http.MaxBytesReader(w, r.Body, maxUploadSize)
var err error
mediaType := "text/plain"