From f36ed4a4c727994f32cf435780093083880ab177 Mon Sep 17 00:00:00 2001 From: Daan Sprenkels Date: Sun, 22 Sep 2019 13:40:33 +0200 Subject: [PATCH] Only provide deleteToken if requested by user --- assets/templates/html/index.html.tmpl | 5 ++++- assets/templates/txt/index.txt.tmpl | 5 ++++- assets/templates/txt/newRedirectPasteSuccess.txt.tmpl | 6 +++++- handlers/handlers.go | 1 - 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/assets/templates/html/index.html.tmpl b/assets/templates/html/index.html.tmpl index 1f46dc8..eef52ba 100644 --- a/assets/templates/html/index.html.tmpl +++ b/assets/templates/html/index.html.tmpl @@ -9,6 +9,9 @@ the command line. ## USAGE # Shorten a URL - curl -F'shorten=http://example.com/some/long/url' https://hashru.link + curl -F'shorten=http://example.com/some/long/url' {{Request.Host}} + + # Shorten a URL with a token to delete it later + curl -F'shorten=http://example.com/some/long/url' -F'deleteToken=' {{Request.Host}} {{end}} \ No newline at end of file diff --git a/assets/templates/txt/index.txt.tmpl b/assets/templates/txt/index.txt.tmpl index 052f227..f589108 100644 --- a/assets/templates/txt/index.txt.tmpl +++ b/assets/templates/txt/index.txt.tmpl @@ -7,4 +7,7 @@ the command line. ## USAGE # Shorten a URL - curl -F'shorten=http://example.com/some/long/url' https://hashru.link + curl -F'shorten=http://example.com/some/long/url' {{Request.Host}} + + # Shorten a URL with a token to delete it later + curl -F'shorten=http://example.com/some/long/url' -F'deleteToken=' {{Request.Host}} \ No newline at end of file diff --git a/assets/templates/txt/newRedirectPasteSuccess.txt.tmpl b/assets/templates/txt/newRedirectPasteSuccess.txt.tmpl index bc3e192..c02e1d8 100644 --- a/assets/templates/txt/newRedirectPasteSuccess.txt.tmpl +++ b/assets/templates/txt/newRedirectPasteSuccess.txt.tmpl @@ -1 +1,5 @@ -{{.Request.Host}}/{{.Paste.Key}}?deleteToken={{.Paste.DeleteToken}} +{{- if .Request.PostForm.deleteToken -}} +{{.Request.Host}}/{{.Paste.Key}}?deleteToken={{.Paste.DeleteToken | urlquery}} +{{else -}} +{{.Request.Host}}/{{.Paste.Key}} +{{end -}} diff --git a/handlers/handlers.go b/handlers/handlers.go index a9d241c..491cfc7 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -227,7 +227,6 @@ func newRedirectPasteHandler(w http.ResponseWriter, r *http.Request) { // Delete a URL from the database func deletePasteHandler(w http.ResponseWriter, r *http.Request) { - // TODO(dsprenkels) LEFT HERE; this functionality still untested vars := mux.Vars(r) key := vars["key"]