diff --git a/cmd/clitest/main.go b/cmd/clitest/main.go index ed5175a..985d13c 100644 --- a/cmd/clitest/main.go +++ b/cmd/clitest/main.go @@ -53,44 +53,28 @@ func main() { if *httpOutput != "" { foo := func(w http.ResponseWriter, r *http.Request) { - if strings.HasPrefix(r.URL.Path, "/api") { - switch r.URL.Path { - case "/api/transactions": - reqF := f - if queryF := r.URL.Query().Get("f"); queryF != "" { - reqF, err = ledger.NewFiles(queryF) - if err != nil { - panic(err) - } - } - deltas, err := reqF.Deltas() + if !strings.HasPrefix(r.URL.Path, "/api") { + http.FileServer(http.Dir("./public")).ServeHTTP(w, r) + return + } + + switch r.URL.Path { + case "/api/transactions": + reqF := f + if queryF := r.URL.Query().Get("f"); queryF != "" { + reqF, err = ledger.NewFiles(queryF) if err != nil { panic(err) } - json.NewEncoder(w).Encode(map[string]any{ - "deltas": deltas.Like(ledger.LikeAfter(time.Now().Add(-1 * time.Hour * 24 * 365 / 2).Format("2006-01"))), - "balances": deltas.Balances().Like("^AssetAccount:").WithBPIs(bpis), - }) - return } - } else if strings.HasPrefix(r.URL.Path, "/transactions") { - f, err := os.Open("./public/transactions.html") + deltas, err := reqF.Deltas() if err != nil { panic(err) } - defer f.Close() - io.Copy(w, f) - return - } else if strings.HasPrefix(r.URL.Path, "/graph") || r.URL.Path == "/" { - f, err := os.Open("./public/index.html") - if err != nil { - panic(err) - } - defer f.Close() - io.Copy(w, f) - return - } else { - http.NotFound(w, r) + json.NewEncoder(w).Encode(map[string]any{ + "deltas": deltas.Like(ledger.LikeAfter(time.Now().Add(-1 * time.Hour * 24 * 365 / 2).Format("2006-01"))), + "balances": deltas.Balances().Like("^AssetAccount:").WithBPIs(bpis), + }) return } diff --git a/cmd/clitest/public/explore.html b/cmd/clitest/public/explore.html new file mode 100644 index 0000000..74bf6c8 --- /dev/null +++ b/cmd/clitest/public/explore.html @@ -0,0 +1,92 @@ + +
+ + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/cmd/clitest/public/index.html b/cmd/clitest/public/index.html index 74bf6c8..674a0ad 100644 --- a/cmd/clitest/public/index.html +++ b/cmd/clitest/public/index.html @@ -1,91 +1,15 @@
- - +
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
+

Moolah2 Hub

+