Rewrite DurationFromExpiry function
This commit is contained in:
parent
20e636620d
commit
5242324a60
|
@ -449,14 +449,14 @@
|
|||
<option value="sls">YAML+Jinja</option>
|
||||
<option value="zephir">Zephir</option>
|
||||
</select>
|
||||
|
||||
<select id="expiry" name="expiry" class="form-control">
|
||||
<option value="5 minutes">5 minutes</option>
|
||||
<option value="1 hour">1 hour</option>
|
||||
<option value="1 day">1 day</option>
|
||||
<option value="1 week">1 week</option>
|
||||
<option value="1 month">1 month</option>
|
||||
<option value="1 year">1 year</option>
|
||||
<option value="" selected="selected">Forever</option>
|
||||
<option value="1">1 hour</option>
|
||||
<option value="24">1 day</option>
|
||||
<option value="24 * 7">1 week</option>
|
||||
<option value="24 * 30">1 month</option>
|
||||
<option value="24 * 365">1 year</option>
|
||||
<option value="24 * (20 * 365)" selected>Forever</option>
|
||||
</select>
|
||||
|
||||
<button type="submit" class="btn btn-raised btn-primary">Submit<div class="ripple-container"></div></button>
|
||||
|
|
|
@ -450,13 +450,12 @@
|
|||
</select>
|
||||
|
||||
<select id="expiry" name="expiry" class="form-control">
|
||||
<option value="5 minutes">5 minutes</option>
|
||||
<option value="1 hour">1 hour</option>
|
||||
<option value="1 day">1 day</option>
|
||||
<option value="1 week">1 week</option>
|
||||
<option value="1 month">1 month</option>
|
||||
<option value="1 year">1 year</option>
|
||||
<option value="" selected="selected">Forever</option>
|
||||
<option value="1">1 hour</option>
|
||||
<option value="24">1 day</option>
|
||||
<option value="24 * 7">1 week</option>
|
||||
<option value="24 * 30">1 month</option>
|
||||
<option value="24 * 365">1 year</option>
|
||||
<option value="24 * (20 * 365)" selected>Forever</option>
|
||||
</select>
|
||||
<button type="submit" class="btn btn-raised btn-primary">Submit<div class="ripple-container"></div></button>
|
||||
</div>
|
||||
|
|
|
@ -4,6 +4,6 @@ CREATE TABLE `pastebin` (
|
|||
`hash` char(40) default NULL,
|
||||
`data` longtext,
|
||||
`delkey` char(40) default NULL,
|
||||
`expiry` TIMESTAMP,
|
||||
`expiry` DATETIME,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
|
21
pastebin.go
21
pastebin.go
|
@ -14,6 +14,7 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
// uniuri is used for easy random string generation
|
||||
|
@ -107,23 +108,9 @@ func Sha1(paste string) string {
|
|||
// DurationFromExpiry takes the expiry in string format and returns the duration
|
||||
// that the paste will exist for
|
||||
func DurationFromExpiry(expiry string) time.Duration {
|
||||
switch expiry {
|
||||
case "5 minutes":
|
||||
return time.Minute * 5
|
||||
case "1 hour":
|
||||
return time.Hour + 1 // XXX: did you mean '*'?
|
||||
case "1 day":
|
||||
return time.Hour * 24
|
||||
case "1 week":
|
||||
return time.Hour * 24 * 7
|
||||
case "1 month":
|
||||
return time.Hour * 24 * 30
|
||||
case "1 year":
|
||||
return time.Hour * 24 * 365
|
||||
case "forever":
|
||||
return time.Hour * 24 * (365 * 20)
|
||||
}
|
||||
return time.Hour * 24 * (365 * 20)
|
||||
i, err := strconv.ParseInt(expiry, 10, 64)
|
||||
Check(err)
|
||||
return time.Hour * time.Duration(i)
|
||||
}
|
||||
|
||||
// Save function handles the saving of each paste.
|
||||
|
|
Loading…
Reference in New Issue