Files
DCCONSTRUCTIONS a49fb00b8e feat(routers): integrate Banana Pi Client API and onboard LibreSpeed measurements
Discover Ethernet routers under the board, map physical SIM slots, expose vendor controls and real telemetry, and provide packaged VPS speed tests with a live monochrome gauge. Enforce compact typography across Core and Node UI.
2026-11-11 23:53:46 +03:00

62 lines
1.9 KiB
Go

package node
import (
"encoding/json"
"net/http"
"nodedc.local/mission-core/node-agent/internal/routers"
)
func (p *Pairing) applyRouterCommands(raw json.RawMessage) {
if p.Routers == nil || len(raw) > 32768 {
return
}
var commands []routers.Command
if json.Unmarshal(raw, &commands) != nil || len(commands) > 2 {
return
}
for _, command := range commands {
_ = p.Routers.Submit(command)
}
}
func (s *Server) routerRoutes(mux *http.ServeMux) {
mux.HandleFunc("GET /api/routers", func(w http.ResponseWriter, r *http.Request) {
if !s.authorized(w, r) {
return
}
w.Header().Set("Cache-Control", "no-store")
w.Header().Set("Content-Type", "application/json")
if s.Pairing == nil || s.Pairing.Routers == nil {
json.NewEncoder(w).Encode(map[string]any{"available": false, "items": []any{}})
return
}
json.NewEncoder(w).Encode(s.Pairing.Routers.Snapshot())
})
submit := func(kind string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if !s.authorized(w, r) {
return
}
var command routers.Command
if !decode(w, r, &command) {
return
}
if (!routerRouteMatches(kind, command)) || s.Pairing == nil || s.Pairing.Routers == nil || s.Pairing.Routers.Submit(command) != nil {
http.Error(w, "Router unavailable", http.StatusConflict)
return
}
w.Header().Set("Cache-Control", "no-store")
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(routers.Result{ID: command.ID, State: "queued"})
}
}
mux.HandleFunc("POST /api/routers/access", submit("access"))
mux.HandleFunc("POST /api/routers/control", submit("control"))
mux.HandleFunc("POST /api/routers/inspect", submit("inspect"))
}
func routerRouteMatches(kind string, command routers.Command) bool {
return ((kind != "access") == (command.Action != "")) && ((kind == "inspect") == (command.Query != nil))
}