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:
+20
@@ -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(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user