implement expiry!!!

oh my fucking GOD bro, i've seen expiry SO SO SO much it idek if i've been spelling it right at this point, please let me be done with this
This commit is contained in:
2026-11-10 22:15:20 -05:00
parent 3a336b79c8
commit 9bda8bc93d
3 changed files with 110 additions and 0 deletions
+20
View File
@@ -70,6 +70,17 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc {
redirect = true
}
expLabel := r.URL.Query().Get("expiry")
if expLabel == "" {
expLabel = cfg.Expiries[0].Label
}
selected, found := findExpiry(cfg.Expiries, expLabel)
if !found {
http.Error(w, "invalid expiry", http.StatusBadRequest)
return
}
var input UploadInput
switch mediaType {
case "multipart/form-data": // file uploads
@@ -182,6 +193,14 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc {
return
}
createdAt := time.Now().UTC().Unix()
expires, err := selected.ExpiresFrom(time.Now().UTC())
if err != nil {
log.Println("calc expiry:", err) // im just using slang
http.Error(w, "internal server error", http.StatusInternalServerError)
return
}
expiresAt := expires.Unix()
if utf8.RuneCountInString(input.Filename) > 255 {
name := []rune(input.Filename)
ext := []rune(filepath.Ext(input.Filename))
@@ -199,6 +218,7 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc {
Size: size,
SHA256: hasher.Sum(nil),
CreatedAt: createdAt,
ExpiresAt: &expiresAt,
LastAccessedAt: createdAt,
DeleteToken: rand.Text(),
}