From 40691095097a5afc19a5fcab5606da4beaf0017a Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Mon, 25 Oct 2021 22:45:56 +1030 Subject: [PATCH] Make it possible to reload the popup window without initiating a new download --- main.go | 27 +++++++++++++++++++++++++++ web/index.html | 2 +- web/popup.html | 5 ++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 89268c9..cf90f23 100644 --- a/main.go +++ b/main.go @@ -55,6 +55,7 @@ func main() { r.HandleFunc("/", homeHandler) r.HandleFunc("/config", configHandler) r.HandleFunc("/fetch", fetchHandler) + r.HandleFunc("/fetch/{id}", fetchHandler) // info for the list r.HandleFunc("/rest/fetch", fetchInfoRESTHandler) @@ -241,6 +242,32 @@ func fetchInfoRESTHandler(w http.ResponseWriter, r *http.Request) { func fetchHandler(w http.ResponseWriter, r *http.Request) { + // if they refreshed the popup, just load the existing object, don't + // create a new one + vars := mux.Vars(r) + idString := vars["id"] + + idInt, err := strconv.ParseInt(idString, 10, 32) + if err == nil && idInt > 0 { + for _, dl := range downloads { + if dl.Id == int(idInt) { + t, err := template.ParseFS(webFS, "web/layout.tmpl", "web/popup.html") + if err != nil { + panic(err) + } + + templateData := map[string]interface{}{"dl": dl, "config": conf} + + err = t.ExecuteTemplate(w, "layout", templateData) + if err != nil { + panic(err) + } + return + } + } + + } + query := r.URL.Query() url, present := query["url"] diff --git a/web/index.html b/web/index.html index 3a5c11e..a951efd 100644 --- a/web/index.html +++ b/web/index.html @@ -81,4 +81,4 @@ } } -{{ end }} \ No newline at end of file +{{ end }} diff --git a/web/popup.html b/web/popup.html index 99801b2..c103c61 100644 --- a/web/popup.html +++ b/web/popup.html @@ -30,11 +30,11 @@ {{ define "js" }}