This commit is contained in:
Magnus Åhall 2024-11-29 09:15:42 +01:00
parent bd4a475923
commit 9a164b984a
36 changed files with 2500 additions and 77 deletions

22
main.go
View file

@ -163,6 +163,10 @@ func rootHandler(w http.ResponseWriter, r *http.Request) { // {{{
Webengine.StaticResource(w, r)
} // }}}
func httpError(w http.ResponseWriter, err error) {// {{{
j, _ := json.Marshal(struct { OK bool; Error string }{false, err.Error()})
w.Write(j)
}// }}}
func pageServiceWorker(w http.ResponseWriter, r *http.Request) { // {{{
w.Header().Add("Content-Type", "text/javascript; charset=utf-8")
@ -209,13 +213,19 @@ func pageNotes2(w http.ResponseWriter, r *http.Request) { // {{{
} // }}}
func actionNodeTree(w http.ResponseWriter, r *http.Request) { // {{{
user, _ := r.Context().Value(CONTEXT_USER).(User)
user := getUser(r)
nodes, err := NodeTree(user.ID, 0)
if err != nil {
httpError(w, err)
return
}
j, _ := json.Marshal(struct {
OK bool
Foo string
User User
}{true, "FOO", user})
Nodes []Node
}{true, nodes})
Log.Debug("tree", "nodes", nodes)
w.Write(j)
} // }}}
@ -261,3 +271,7 @@ func changePassword(username string) { // {{{
fmt.Printf("\nPassword changed\n")
} // }}}
func getUser(r *http.Request) User { // {{{
user, _ := r.Context().Value(CONTEXT_USER).(User)
return user
} // }}}