Commit f46b01b2 authored by Artemis's avatar Artemis

Added multiple possible expiration times

parent dec3ed61
......@@ -46,7 +46,7 @@ func (h Handlers) HandleNewPaste(w http.ResponseWriter, req *http.Request) {
return
}
if len(req.Form["paste"]) == 0 {
if len(req.Form["paste"]) == 0 || len(req.Form["time"]) == 0 {
// Required value
w.WriteHeader(400)
_ = h.Templates.ExecuteTemplate(w, "homepage", &Content{Error: "You must provide a value"})
......@@ -61,6 +61,25 @@ func (h Handlers) HandleNewPaste(w http.ResponseWriter, req *http.Request) {
return
}
var keepaliveTime = time.Hour
switch timeValue := req.Form["time"][0]; timeValue {
case "1h": // nothing, already handled in variable init
case "6h":
keepaliveTime *= 6
case "12h":
keepaliveTime *= 12
case "24h":
keepaliveTime *= 24
default:
// Required value, which must be either 1, 6, 12 or 24
w.WriteHeader(400)
_ = h.Templates.ExecuteTemplate(w, "homepage", &Content{
Error: "You must choose between 1, 6, 12 or 24 hours",
Value: pasteValue,
})
return
}
err, key := GetNewKey()
if err != nil {
......@@ -69,7 +88,7 @@ func (h Handlers) HandleNewPaste(w http.ResponseWriter, req *http.Request) {
return
}
res := h.Backend.Set(key, pasteValue, time.Hour)
res := h.Backend.Set(key, pasteValue, keepaliveTime)
if err := res.Err(); err != nil {
w.WriteHeader(500)
fmt.Println(err)
......
......@@ -3,6 +3,6 @@
<footer>
<a href="https://gitlab.com/Artemix/paste" target="_blank">Source code</a>
| <a href="/templates/privacy.html" target="_blank">Privacy Policy</a>
| <a href="/privacy.html" target="_blank">Privacy Policy</a>
</footer>
{{end}}
......@@ -17,12 +17,21 @@
<label for="paste">Your document</label>
<textarea name="paste" id="paste" rows="15" required autofocus>{{.Value}}</textarea>
</fieldset>
<fieldset>
<label for="time">Store duration</label>
<select name="time" id="time">
<option value="1h" selected>1 hour</option>
<option value="6h">6 hours</option>
<option value="12h">12 hours</option>
<option value="24h">1 day (24 hours)</option>
</select>
</fieldset>
<fieldset>
<button type="submit">Store</button>
</fieldset>
</form>
<p>Pastes are stored for 1 hour or until next server restart, whichever comes first.</p>
<p>Pastes are stored for the selected duration (maximum of 24h) or until next server restart, whichever comes first.</p>
</section>
{{template "footer"}}
......
......@@ -12,8 +12,8 @@
<h2>Paste storing</h2>
<p>Every paste is stored in RAM (through Redis, configured to not persist anything), with an auto-expiry set to 1 hour.</p>
<p>In that sense, we don't persist anything, and once the expiry time is passed, everything is forgotten.</p>
<p>Every paste is stored in RAM (through Redis, configured to not persist anything), with an auto-expiry set to either 1, 6, 12, or 24 hours.</p>
<p>In that sense, we don't persist anything, and once the expiry time is passed, or the server rebooted, everything is forgotten.</p>
</body>
</html>
{{end}}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment