add default expiry config parameter

This commit is contained in:
luckman212 2021-10-09 11:36:53 -04:00
parent 084ac233ff
commit d63a875b12
No known key found for this signature in database
GPG Key ID: 4F32ABD351804286
4 changed files with 12 additions and 7 deletions

View File

@ -21,9 +21,10 @@ const (
func indexHandler(c web.C, w http.ResponseWriter, r *http.Request) { func indexHandler(c web.C, w http.ResponseWriter, r *http.Request) {
err := renderTemplate(Templates["index.html"], pongo2.Context{ err := renderTemplate(Templates["index.html"], pongo2.Context{
"maxsize": Config.maxSize, "maxsize": Config.maxSize,
"expirylist": listExpirationTimes(), "expirylist": listExpirationTimes(),
"forcerandom": Config.forceRandomFilename, "expirydefault": Config.defaultExpiry,
"forcerandom": Config.forceRandomFilename,
}, r, w) }, r, w)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) 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) { func pasteHandler(c web.C, w http.ResponseWriter, r *http.Request) {
err := renderTemplate(Templates["paste.html"], pongo2.Context{ err := renderTemplate(Templates["paste.html"], pongo2.Context{
"expirylist": listExpirationTimes(), "expirylist": listExpirationTimes(),
"forcerandom": Config.forceRandomFilename, "expirydefault": Config.defaultExpiry,
"forcerandom": Config.forceRandomFilename,
}, r, w) }, r, w)
if err != nil { if err != nil {
oopsHandler(c, w, r, RespHTML, "") oopsHandler(c, w, r, RespHTML, "")

View File

@ -56,6 +56,7 @@ var Config struct {
xFrameOptions string xFrameOptions string
maxSize int64 maxSize int64
maxExpiry uint64 maxExpiry uint64
defaultExpiry uint64
realIp bool realIp bool
noLogs bool noLogs bool
allowHotlink bool allowHotlink bool
@ -264,6 +265,8 @@ func main() {
"maximum upload file size in bytes (default 4GB)") "maximum upload file size in bytes (default 4GB)")
flag.Uint64Var(&Config.maxExpiry, "maxexpiry", 0, flag.Uint64Var(&Config.maxExpiry, "maxexpiry", 0,
"maximum expiration time in seconds (default is 0, which is no expiry)") "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", "", flag.StringVar(&Config.certFile, "certfile", "",
"path to ssl certificate (for https)") "path to ssl certificate (for https)")
flag.StringVar(&Config.keyFile, "keyfile", "", flag.StringVar(&Config.keyFile, "keyfile", "",

View File

@ -28,7 +28,7 @@
<label>File expiry: <label>File expiry:
<select name="expires" id="expires"> <select name="expires" id="expires">
{% for expiry in expirylist %} {% for expiry in expirylist %}
<option value="{{ expiry.Seconds }}" {% if forloop.Last %} selected{% endif %}> <option value="{{ expiry.Seconds }}" {% if (expiry.Seconds == expirydefault) %} selected {% endif %}>
{{ expiry.Human }}</option> {{ expiry.Human }}</option>
{% endfor %} {% endfor %}
</select> </select>

View File

@ -22,7 +22,7 @@
<select id="expiry" name="expires"> <select id="expiry" name="expires">
<option disabled>Expires:</option> <option disabled>Expires:</option>
{% for expiry in expirylist %} {% for expiry in expirylist %}
<option value="{{ expiry.Seconds }}" {% if forloop.Last %} selected{% endif %}>{{ expiry.Human }} <option value="{{ expiry.Seconds }}" {% if (expiry.Seconds == expirydefault) %} selected {% endif %}>{{ expiry.Human }}
</option> </option>
{% endfor %} {% endfor %}
</select> </select>