Clean up and better error checking
This commit is contained in:
parent
2c57a77b98
commit
7c1d11298f
16
main.go
16
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
<tr>
|
||||
<td x-text="item.id"></td>
|
||||
<td x-text="item.files"></td>
|
||||
<td x-text="item.url"></td>
|
||||
<td><a x-bind:href="item.url">link</a></td>
|
||||
<td x-text="item.state"></td>
|
||||
<td x-text="item.percent"></td>
|
||||
<td x-text="item.eta"></td>
|
||||
@ -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);
|
||||
})
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user