download link added

This commit is contained in:
Özgür Kesim 2019-06-14 11:21:20 +02:00
parent 4d20598a28
commit 7e4fa87020
2 changed files with 5 additions and 4 deletions

View File

@ -155,7 +155,7 @@ window.onhashchange = hashloc;
function run() { function run() {
var data = editor.getValue().trim(); var data = editor.getValue().trim();
if (!data) return; if (!data) return;
link.innerHtml = ""; link.innerHTML = "";
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.open("POST", "/{{$name}}/c", false); req.open("POST", "/{{$name}}/c", false);
req.onreadystatechange = function() { req.onreadystatechange = function() {
@ -182,7 +182,8 @@ function share() {
req.onreadystatechange = function() { req.onreadystatechange = function() {
switch (req.status) { switch (req.status) {
case 200: case 200:
link.innerHTML = "<i>saved as</i> <a href=\"/{{$name}}/#"+req.responseText+"!\">#"+req.responseText+"!</a>"; link.innerHTML = "<i>saved as</i> <a href=\"/{{$name}}/#"+req.responseText+"!\">#"+req.responseText+"!</a>" +
" or <a href=\"/{{$name}}/d/"+req.responseText+"\">download</a>";
document.title= "{{$name}}#"+req.responseText; document.title= "{{$name}}#"+req.responseText;
document.location.hash=req.responseText+"!"; document.location.hash=req.responseText+"!";
break; break;

View File

@ -92,7 +92,7 @@ func (t *Tool) compile() func(http.ResponseWriter, *http.Request) {
} }
} }
func (t *Tool) svg() func(http.ResponseWriter, *http.Request) { func (t *Tool) download() func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
name := filepath.Base(r.URL.Path) name := filepath.Base(r.URL.Path)
if file, err := os.Open(filepath.Join(*savedir, name+t.Suffix)); err != nil { if file, err := os.Open(filepath.Join(*savedir, name+t.Suffix)); err != nil {
@ -184,7 +184,7 @@ func main() {
http.HandleFunc(pre+"c", tool.compile()) http.HandleFunc(pre+"c", tool.compile())
http.HandleFunc(pre+"s", tool.save()) http.HandleFunc(pre+"s", tool.save())
http.HandleFunc(pre+"l/", tool.load()) http.HandleFunc(pre+"l/", tool.load())
http.HandleFunc(pre+"svg/", tool.svg()) http.HandleFunc(pre+"d/", tool.download())
http.HandleFunc(pre, tool.index(tmpl, tools)) http.HandleFunc(pre, tool.index(tmpl, tools))
log.Println("handler for", pre, "registered") log.Println("handler for", pre, "registered")
} }