Merge pull request #10 from luckman212/add-default-expiry
add default expiry config parameter
This commit is contained in:
commit
3f503442f1
2
pages.go
2
pages.go
|
@ -23,6 +23,7 @@ func indexHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
|||
err := renderTemplate(Templates["index.html"], pongo2.Context{
|
||||
"maxsize": Config.maxSize,
|
||||
"expirylist": listExpirationTimes(),
|
||||
"expirydefault": Config.defaultExpiry,
|
||||
"forcerandom": Config.forceRandomFilename,
|
||||
}, r, w)
|
||||
if err != nil {
|
||||
|
@ -33,6 +34,7 @@ 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(),
|
||||
"expirydefault": Config.defaultExpiry,
|
||||
"forcerandom": Config.forceRandomFilename,
|
||||
}, r, w)
|
||||
if err != nil {
|
||||
|
|
|
@ -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", "",
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<label>File expiry:
|
||||
<select name="expires" id="expires">
|
||||
{% 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>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<select id="expiry" name="expires">
|
||||
<option disabled>Expires:</option>
|
||||
{% 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>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
|
|
@ -405,11 +405,11 @@ func barePlusExt(filename string) (barename, extension string) {
|
|||
|
||||
func parseExpiry(expStr string) time.Duration {
|
||||
if expStr == "" {
|
||||
return time.Duration(Config.maxExpiry) * time.Second
|
||||
return time.Duration(Config.defaultExpiry) * time.Second
|
||||
} else {
|
||||
fileExpiry, err := strconv.ParseUint(expStr, 10, 64)
|
||||
if err != nil {
|
||||
return time.Duration(Config.maxExpiry) * time.Second
|
||||
return time.Duration(Config.defaultExpiry) * time.Second
|
||||
} else {
|
||||
if Config.maxExpiry > 0 && (fileExpiry > Config.maxExpiry || fileExpiry == 0) {
|
||||
fileExpiry = Config.maxExpiry
|
||||
|
|
Loading…
Reference in New Issue