From d63a875b12e4bf370c31ec4ee4f1d79b74c8f0e8 Mon Sep 17 00:00:00 2001 From: luckman212 Date: Sat, 9 Oct 2021 11:36:53 -0400 Subject: [PATCH] add default expiry config parameter --- pages.go | 12 +++++++----- server.go | 3 +++ templates/index.html | 2 +- templates/paste.html | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pages.go b/pages.go index ae8de42..6492651 100644 --- a/pages.go +++ b/pages.go @@ -21,9 +21,10 @@ const ( func indexHandler(c web.C, w http.ResponseWriter, r *http.Request) { err := renderTemplate(Templates["index.html"], pongo2.Context{ - "maxsize": Config.maxSize, - "expirylist": listExpirationTimes(), - "forcerandom": Config.forceRandomFilename, + "maxsize": Config.maxSize, + "expirylist": listExpirationTimes(), + "expirydefault": Config.defaultExpiry, + "forcerandom": Config.forceRandomFilename, }, r, w) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -32,8 +33,9 @@ func indexHandler(c web.C, w http.ResponseWriter, r *http.Request) { func pasteHandler(c web.C, w http.ResponseWriter, r *http.Request) { err := renderTemplate(Templates["paste.html"], pongo2.Context{ - "expirylist": listExpirationTimes(), - "forcerandom": Config.forceRandomFilename, + "expirylist": listExpirationTimes(), + "expirydefault": Config.defaultExpiry, + "forcerandom": Config.forceRandomFilename, }, r, w) if err != nil { oopsHandler(c, w, r, RespHTML, "") diff --git a/server.go b/server.go index 82a72e3..41cd932 100644 --- a/server.go +++ b/server.go @@ -56,6 +56,7 @@ var Config struct { xFrameOptions string maxSize int64 maxExpiry uint64 + defaultExpiry uint64 realIp bool noLogs bool allowHotlink bool @@ -264,6 +265,8 @@ func main() { "maximum upload file size in bytes (default 4GB)") flag.Uint64Var(&Config.maxExpiry, "maxexpiry", 0, "maximum expiration time in seconds (default is 0, which is no expiry)") + flag.Uint64Var(&Config.defaultExpiry, "default-expiry", 86400, + "default expiration time in seconds (default is 86400, which is 1 day)") flag.StringVar(&Config.certFile, "certfile", "", "path to ssl certificate (for https)") flag.StringVar(&Config.keyFile, "keyfile", "", diff --git a/templates/index.html b/templates/index.html index 8060af2..3958788 100644 --- a/templates/index.html +++ b/templates/index.html @@ -28,7 +28,7 @@