This commit is contained in:
Magnus Åhall 2025-08-07 19:25:05 +02:00
parent 38eef01e34
commit df4cee56af
7 changed files with 292 additions and 74 deletions

View file

@ -41,6 +41,7 @@ func initWebserver() (err error) {
http.HandleFunc("/nodes/move", actionNodeMove)
http.HandleFunc("/nodes/search", actionNodeSearch)
http.HandleFunc("/nodes/connect", actionNodeConnect)
http.HandleFunc("/nodes/hook", actionNodeHook)
http.HandleFunc("/types/{typeID}", actionType)
http.HandleFunc("/types/", actionTypesAll)
http.HandleFunc("/types/create", actionTypeCreate)
@ -374,6 +375,37 @@ func actionNodeConnect(w http.ResponseWriter, r *http.Request) { // {{{
j, _ := json.Marshal(res)
w.Write(j)
} // }}}
func actionNodeHook(w http.ResponseWriter, r *http.Request) { // {{{
var req struct {
NodeID int
ScriptID int
}
body, _ := io.ReadAll(r.Body)
err := json.Unmarshal(body, &req)
if err != nil {
err = werr.Wrap(err)
httpError(w, err)
return
}
err = HookScript(req.NodeID, req.ScriptID)
if err != nil {
pqErr, ok := err.(*pq.Error)
if ok && pqErr.Code == "23505" {
err = errors.New("This script is already hooked.")
} else {
err = werr.Wrap(err)
}
httpError(w, err)
return
}
res := struct{ OK bool }{true}
j, _ := json.Marshal(res)
w.Write(j)
} // }}}
func actionType(w http.ResponseWriter, r *http.Request) { // {{{