58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package file
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// UploadMulti accepts up to 10 files, zips them server-side, and returns a single download/view key.
|
|
func (h *Handler) UploadMulti(c *gin.Context) {
|
|
if err := c.Request.ParseMultipartForm(0); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
form, err := c.MultipartForm()
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid multipart form"})
|
|
return
|
|
}
|
|
|
|
files := form.File["files"]
|
|
if len(files) == 0 {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "missing files"})
|
|
return
|
|
}
|
|
if len(files) > 10 {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "too many files (max 10)"})
|
|
return
|
|
}
|
|
|
|
once := c.PostForm("once") == "true"
|
|
|
|
durationStr := c.PostForm("duration")
|
|
hours, err := strconv.Atoi(durationStr)
|
|
if err != nil || hours <= 0 {
|
|
hours = 24
|
|
}
|
|
duration := time.Duration(hours) * time.Hour
|
|
|
|
record, err := h.service.UploadBundle(files, once, duration)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"id": record.ID,
|
|
"deletion_id": record.DeletionID,
|
|
"filename": record.Filename,
|
|
"size": record.Size,
|
|
"expires_at": record.ExpiresAt,
|
|
"view_key": record.ViewID,
|
|
})
|
|
}
|