Download history to client

This commit is contained in:
Magnus Åhall 2026-06-06 14:29:22 +02:00
parent 65a0225d74
commit 9506b89453
5 changed files with 249 additions and 75 deletions

26
main.go
View file

@ -25,7 +25,7 @@ import (
const VERSION = "v11"
const CONTEXT_USER = 1
const SYNC_PAGINATION = 200
const SYNC_PAGINATION = 20
var (
FlagGenerate bool
@ -140,6 +140,7 @@ func main() { // {{{
http.HandleFunc("/sync/to_server", authenticated(actionSyncToServer))
http.HandleFunc("/node/retrieve/{uuid}", authenticated(actionNodeRetrieve))
http.HandleFunc("/node/history/retrieve/{uuid}/{offset}", authenticated(actionNodeHistoryRetrieve))
http.HandleFunc("/service_worker.js", pageServiceWorker)
@ -328,6 +329,29 @@ func actionNodeRetrieve(w http.ResponseWriter, r *http.Request) { // {{{
"Node": node,
})
} // }}}
func actionNodeHistoryRetrieve(w http.ResponseWriter, r *http.Request) { // {{{
user := getUser(r)
var err error
uuid := r.PathValue("uuid")
offset, err := strconv.Atoi(r.PathValue("offset"))
if err != nil {
responseError(w, err)
return
}
nodes, hasMore, err := RetrieveNodeHistory(user.UserID, uuid, offset)
if err != nil {
responseError(w, err)
return
}
responseData(w, map[string]any{
"OK": true,
"Nodes": nodes,
"HasMore": hasMore,
})
} // }}}
func actionSyncToServer(w http.ResponseWriter, r *http.Request) { // {{{
user := getUser(r)