From 1567035954d3dd5206e042daa9c88a2719bf308d Mon Sep 17 00:00:00 2001 From: balki <3070606-balki@users.noreply.gitlab.com> Date: Thu, 14 Jul 2022 14:39:59 -0400 Subject: [PATCH] temp bs --- db/db.go | 5 +- main.go | 3 +- templates/index.html | 169 ++++++++++++++++++++++++++----------------- 3 files changed, 108 insertions(+), 69 deletions(-) diff --git a/db/db.go b/db/db.go index 1be722f..6d583e3 100644 --- a/db/db.go +++ b/db/db.go @@ -31,6 +31,7 @@ type Item struct { } type Jdb struct { + Foo string `json:"-"` Items []Item `json:"items"` } @@ -72,7 +73,7 @@ func (d *Db) Transact(id int, persist bool, f func(*Item)) error { } func (d *Db) save() error { - data, err := json.Marshal(Jdb{d.items}) + data, err := json.Marshal(Jdb{"", d.items}) if err != nil { return err } @@ -82,7 +83,7 @@ func (d *Db) save() error { func (d *Db) Run(f func(*Jdb)) { d.mutex.Lock() defer d.mutex.Unlock() - f(&Jdb{d.items}) + f(&Jdb{"", d.items}) } func (d *Db) Save() error { diff --git a/main.go b/main.go index 8a99612..b9094d3 100644 --- a/main.go +++ b/main.go @@ -70,9 +70,11 @@ func main() { log.Panic(err) } defer d.Save() + http.Handle("/assets/", http.FileServer(http.Dir("./"))) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodGet { d.Run(func(d *db.Jdb) { + d.Foo = "Hello" if err := tmpl.Execute(w, d); err != nil { log.Panic(err) } @@ -106,7 +108,6 @@ func main() { w.WriteHeader(http.StatusInternalServerError) return } - fmt.Println("path is", p, "id is", id) var sc <-chan string d.Transact(id, false, func(i *db.Item) { pt := i.Pt diff --git a/templates/index.html b/templates/index.html index 8ded8dd..25e1355 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,82 +1,119 @@ + + Youtube Downloader UI + -
- - -
- - - - - - - - - - - - {{ range .Items }} - - - - - - - {{ end }} - -
Vidoes
DateURLTitleLink
{{ .Date }}{{ .URL }} - {{ if eq .Title "Loading" }} - Loading... - {{ else }} - {{ .Title }} - {{ end }} - - {{ if eq .Status "Done" }} - Watch - {{ else if eq .Status "InProgress" }} - In Progress - {{ else }} - {{ .Status }} - {{ end }} -
+

{{ .Foo }}

+
+
+
+ + +
+
+
+ {{ range .Items }} +
+
+
+
+ {{ if eq .Title "Loading" }} + Loading... + {{ else }} + {{ .Title }} + {{ end }} +
+
On {{ .Date }}
+ Youtube Link + {{ if eq .Status "Done" }} + Watch + {{ else if eq .Status "InProgress" }} + In Progress + {{ else }} + {{ .Status }} + {{ end }} +
+
+
+ {{ end }} +
+ + + + + + + + + + + + {{ range .Items }} + + + + + + + {{ end }} + +
All Vidoes
DateURLTitleLink
{{ .Date }}{{ .URL }} + {{ if eq .Title "Loading" }} + Loading... + {{ else }} + {{ .Title }} + {{ end }} + + {{ if eq .Status "Done" }} + Watch + {{ else if eq .Status "InProgress" }} + In Progress + {{ else }} + {{ .Status }} + {{ end }} +
+