mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
49e61fa07f
* feat(updater): add web self-update endpoint and updater package * feat(selfupgrade): when url empty, using GetTestReleaseAPIURL for test . * feat(selfupgrade): only GetTestReleaseAPIURL . * feat(upgrade): cli $0 update work well! * fix(ci): fix ci err * fix(test): fix ci test * fix(ci): fix ci lint fmt err * test(updater): add test for updater * fix(ci): fix ci lint var copy err * fix(ci): retry ci * updater: require checksum verification, prefer API digest, verify SHA256, fix zip extraction, update tests * fix(lint): lint fixed * fix(lint): lint fixed2 * updater: stream download and verify sha256; add http client timeout and progress Avoid double-download by streaming asset into temp file while computing SHA256 and verifying against checksum; replace http.Get with shared httpClient (2m timeout) to prevent hangs; add simple stderr progress display; remove unused helpers.
101 lines
2.5 KiB
Go
101 lines
2.5 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"sync"
|
|
|
|
"github.com/sipeed/picoclaw/web/backend/launcherconfig"
|
|
)
|
|
|
|
// Handler serves HTTP API requests.
|
|
type Handler struct {
|
|
configPath string
|
|
serverPort int
|
|
serverPublic bool
|
|
serverPublicExplicit bool
|
|
serverCIDRs []string
|
|
debug bool
|
|
oauthMu sync.Mutex
|
|
oauthFlows map[string]*oauthFlow
|
|
oauthState map[string]string
|
|
weixinMu sync.Mutex
|
|
weixinFlows map[string]*weixinFlow
|
|
wecomMu sync.Mutex
|
|
wecomFlows map[string]*wecomFlow
|
|
}
|
|
|
|
// NewHandler creates an instance of the API handler.
|
|
func NewHandler(configPath string) *Handler {
|
|
return &Handler{
|
|
configPath: configPath,
|
|
serverPort: launcherconfig.DefaultPort,
|
|
oauthFlows: make(map[string]*oauthFlow),
|
|
oauthState: make(map[string]string),
|
|
weixinFlows: make(map[string]*weixinFlow),
|
|
wecomFlows: make(map[string]*wecomFlow),
|
|
}
|
|
}
|
|
|
|
// SetServerOptions stores current backend listen options for fallback behavior.
|
|
func (h *Handler) SetServerOptions(port int, public bool, publicExplicit bool, allowedCIDRs []string) {
|
|
h.serverPort = port
|
|
h.serverPublic = public
|
|
h.serverPublicExplicit = publicExplicit
|
|
h.serverCIDRs = append([]string(nil), allowedCIDRs...)
|
|
}
|
|
|
|
func (h *Handler) SetDebug(debug bool) {
|
|
h.debug = debug
|
|
}
|
|
|
|
// RegisterRoutes binds all API endpoint handlers to the ServeMux.
|
|
func (h *Handler) RegisterRoutes(mux *http.ServeMux) {
|
|
// Config CRUD
|
|
h.registerConfigRoutes(mux)
|
|
|
|
// Pico Channel (WebSocket chat)
|
|
h.registerPicoRoutes(mux)
|
|
|
|
// Gateway process lifecycle
|
|
h.registerGatewayRoutes(mux)
|
|
|
|
// Session history
|
|
h.registerSessionRoutes(mux)
|
|
|
|
// OAuth login and credential management
|
|
h.registerOAuthRoutes(mux)
|
|
|
|
// Model list management
|
|
h.registerModelRoutes(mux)
|
|
|
|
// Channel catalog (for frontend navigation/config pages)
|
|
h.registerChannelRoutes(mux)
|
|
|
|
// Skills and tools support/actions
|
|
h.registerSkillRoutes(mux)
|
|
h.registerToolRoutes(mux)
|
|
|
|
// OS startup / launch-at-login
|
|
h.registerStartupRoutes(mux)
|
|
|
|
// Launcher service parameters (port/public)
|
|
h.registerLauncherConfigRoutes(mux)
|
|
|
|
// Self-update endpoint (requires dashboard auth)
|
|
h.registerUpdateRoutes(mux)
|
|
|
|
// Runtime build/version metadata
|
|
h.registerVersionRoutes(mux)
|
|
|
|
// WeChat QR login flow
|
|
h.registerWeixinRoutes(mux)
|
|
|
|
// WeCom QR login flow
|
|
h.registerWecomRoutes(mux)
|
|
}
|
|
|
|
// Shutdown gracefully shuts down the handler, stopping the gateway if it was started by this handler.
|
|
func (h *Handler) Shutdown() {
|
|
h.StopGateway()
|
|
}
|