diff --git a/db.go b/db.go
index d6b60b7..a156541 100644
--- a/db.go
+++ b/db.go
@@ -35,7 +35,7 @@ func insertPaste(key string, content string, secret string, ttl time.Duration) {
}
err = db.HSet(ctx, key, "secret", hash.secret)
if ttl > -1 {
- db.Do(ctx, key, ttl)
+ db.Expire(ctx, key, ttl)
}
}
diff --git a/main.go b/main.go
index 2fdec8a..3064b46 100644
--- a/main.go
+++ b/main.go
@@ -8,6 +8,7 @@ import (
"log"
"net/http"
"strings"
+ "time"
)
var currentConfig Config
@@ -60,7 +61,18 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
secret := GenerateSecret()
url := "/" + GenerateUrl()
content := r.FormValue("content")
- insertPaste(url, content, secret, -1)
+ rawExpiration := r.FormValue("exp")
+ expiration, err := ParseExpiration(rawExpiration)
+ if err != nil {
+ log.Println(err)
+ } else if expiration == 0 {
+ insertPaste(url, content, secret, -1)
+ } else if expiration == -1 {
+ w.WriteHeader(http.StatusBadRequest)
+ } else {
+ insertPaste(url, content, secret, time.Duration(expiration*int(time.Second)))
+ }
+
http.Redirect(w, r, url, http.StatusSeeOther)
} else {
w.WriteHeader(http.StatusMethodNotAllowed)
diff --git a/static/index.html b/static/index.html
index 40eb943..dfaa289 100644
--- a/static/index.html
+++ b/static/index.html
@@ -27,7 +27,7 @@
-
+