Add admin config page and runtime-tunable upload/rate-limit settings
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"ResendIt/internal/config"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -26,11 +27,27 @@ func (h *Handler) UploadMulti(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "missing files"})
|
||||
return
|
||||
}
|
||||
if len(files) > 50 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "too many files (max 50)"})
|
||||
maxFiles := h.configService.GetIntDefault(config.KeyUploadMultiMaxFiles, config.DefaultUploadMultiMaxFiles)
|
||||
if len(files) > maxFiles {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "too many files"})
|
||||
return
|
||||
}
|
||||
|
||||
maxSize := h.configService.GetInt64Default(config.KeyUploadMaxFileSizeBytes, config.DefaultUploadMaxFileSizeBytes)
|
||||
var total int64
|
||||
for _, fh := range files {
|
||||
if fh.Size > maxSize {
|
||||
c.JSON(http.StatusRequestEntityTooLarge, gin.H{"error": "file too large"})
|
||||
return
|
||||
}
|
||||
total += fh.Size
|
||||
if total > maxSize {
|
||||
// crude guard against huge bundles; you can add a separate config later.
|
||||
c.JSON(http.StatusRequestEntityTooLarge, gin.H{"error": "bundle too large"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
once := c.PostForm("once") == "true"
|
||||
|
||||
durationStr := c.PostForm("duration")
|
||||
@@ -38,6 +55,10 @@ func (h *Handler) UploadMulti(c *gin.Context) {
|
||||
if err != nil || hours <= 0 {
|
||||
hours = 24
|
||||
}
|
||||
maxHours := h.configService.GetIntDefault(config.KeyUploadMaxHours, config.DefaultUploadMaxHours)
|
||||
if hours > maxHours {
|
||||
hours = maxHours
|
||||
}
|
||||
duration := time.Duration(hours) * time.Hour
|
||||
|
||||
record, err := h.service.UploadBundle(files, once, duration)
|
||||
|
||||
Reference in New Issue
Block a user