From 2c57a77b987da9ea05bc8676fd45a9813f223389 Mon Sep 17 00:00:00 2001
From: Justin Hawkins
Date: Sun, 26 Sep 2021 12:33:31 +0930
Subject: [PATCH] Make the index page dynamic
---
main.go | 10 ++++++++--
web/index.html | 40 ++++++++++++++++++++++++++++++----------
2 files changed, 38 insertions(+), 12 deletions(-)
diff --git a/main.go b/main.go
index 71dea07..0507d7a 100644
--- a/main.go
+++ b/main.go
@@ -81,7 +81,8 @@ func main() {
r := mux.NewRouter()
r.HandleFunc("/", HomeHandler)
r.HandleFunc("/fetch", FetchHandler)
- r.HandleFunc("/fetch/info/{id}", FetchInfoHandler)
+ r.HandleFunc("/fetch/info", FetchInfoHandler)
+ r.HandleFunc("/fetch/info/{id}", FetchInfoOneHandler)
http.Handle("/", r)
@@ -126,7 +127,7 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) {
}
-func FetchInfoHandler(w http.ResponseWriter, r *http.Request) {
+func FetchInfoOneHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
idString := vars["id"]
if idString != "" {
@@ -148,6 +149,11 @@ func FetchInfoHandler(w http.ResponseWriter, r *http.Request) {
}
}
+func FetchInfoHandler(w http.ResponseWriter, r *http.Request) {
+ b, _ := json.Marshal(downloads)
+ w.Write(b)
+}
+
func FetchHandler(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
diff --git a/web/index.html b/web/index.html
index 2b88232..d8047ab 100644
--- a/web/index.html
+++ b/web/index.html
@@ -6,7 +6,7 @@
-
+
@@ -14,16 +14,21 @@
+
+
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+
+
+
+
+
{{ range $k, $v := .Downloads }}
-
- {{ $v.Id }} |
- {{ range $_, $f := $v.Files }}{{ $f }} {{ end }} |
- link |
- {{ $v.State }} |
- {{ $v.Percent }} |
- {{ $v.Eta }} |
- {{ $v.Finished }} |
-
{{ end }}
@@ -31,4 +36,19 @@
{{ end }}
{{ define "js" }}
+
{{ end }}
\ No newline at end of file