From 7c1d11298f9be43926938dcfce38f3eee4869bf9 Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Sun, 26 Sep 2021 12:48:42 +0930 Subject: [PATCH] Clean up and better error checking --- main.go | 16 ++++++++++++---- web/index.html | 7 +++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 0507d7a..eb188ae 100644 --- a/main.go +++ b/main.go @@ -157,12 +157,21 @@ func FetchInfoHandler(w http.ResponseWriter, r *http.Request) { func FetchHandler(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() - url, present := query["url"] //filters=["color", "price", "brand"] + url, present := query["url"] if !present { - fmt.Fprint(w, "something") + w.WriteHeader(400) + fmt.Fprint(w, "No url supplied") + return } else { + // check the URL for a sudden but inevitable betrayal + if strings.Contains(url[0], address) { + w.WriteHeader(400) + fmt.Fprint(w, "you musn't gropple your gropple :-)") + return + } + // create the record // XXX should be atomic! downloadId++ @@ -183,6 +192,7 @@ func FetchHandler(w http.ResponseWriter, r *http.Request) { go func() { queue(&newDownload) }() + t, err := template.ParseFS(webFS, "web/layout.tmpl", "web/popup.html") if err != nil { panic(err) @@ -191,8 +201,6 @@ func FetchHandler(w http.ResponseWriter, r *http.Request) { if err != nil { panic(err) } - - // fmt.Fprintf(w, "Started DL %d!", downloadId) } } diff --git a/web/index.html b/web/index.html index d8047ab..33c6a15 100644 --- a/web/index.html +++ b/web/index.html @@ -18,7 +18,7 @@ - + link @@ -44,7 +44,10 @@ fetch('/fetch/info') .then(response => response.json()) .then(info => { - this.items = info; + // will be null if no downloads yet + if (info) { + this.items = info; + } setTimeout(() => { this.fetch_data() }, 1000); }) },