This commit is contained in:
Magnus Åhall 2024-12-03 06:53:31 +01:00
parent 42b66714aa
commit ac8b334eee
35 changed files with 541 additions and 675 deletions

21
main.go
View file

@ -106,10 +106,11 @@ func main() { // {{{
http.HandleFunc("/", rootHandler)
http.HandleFunc("/notes2", pageNotes2)
http.HandleFunc("/login", pageLogin)
http.HandleFunc("/sync", pageSync)
http.HandleFunc("/user/authenticate", AuthManager.AuthenticationHandler)
http.HandleFunc("/node/tree", authenticated(actionNodeTree))
http.HandleFunc("/node/tree/{timestamp}", authenticated(actionNodeTree))
http.HandleFunc("/node/retrieve/{id}", authenticated(actionNodeRetrieve))
http.HandleFunc("/service_worker.js", pageServiceWorker)
@ -212,20 +213,32 @@ func pageNotes2(w http.ResponseWriter, r *http.Request) { // {{{
return
}
} // }}}
func pageSync(w http.ResponseWriter, r *http.Request) { // {{{
page := NewPage("sync")
err := Webengine.Render(page, w, r)
if err != nil {
w.Write([]byte(err.Error()))
return
}
} // }}}
func actionNodeTree(w http.ResponseWriter, r *http.Request) { // {{{
user := getUser(r)
changedFrom, _ := strconv.Atoi(r.PathValue("timestamp"))
nodes, err := NodeTree(user.ID, 0)
nodes, maxSeq, err := NodeTree(user.ID, uint64(changedFrom))
if err != nil {
Log.Error("/node/tree", "error", err)
httpError(w, err)
return
}
j, _ := json.Marshal(struct {
OK bool
Nodes []Node
}{true, nodes})
Nodes []TreeNode
MaxSeq uint64
}{true, nodes, maxSeq})
Log.Debug("tree", "nodes", nodes)
w.Write(j)
} // }}}