mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-11 00:22:56 -05:00
Add an MCP Streamable HTTP server with token authentication, screenshot capture, keyboard, and mouse tools. Introduce shared control-mode and input-control coordination so MCP, PicoClaw, and local HID paths serialize ownership safely. Integrate PicoClaw gateway/runtime control handoff with PID-managed startup and focused unit coverage.
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package router
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"NanoKVM-Server/service/controlmode"
|
|
"NanoKVM-Server/service/picoclaw"
|
|
|
|
"github.com/gin-gonic/contrib/static"
|
|
"github.com/gin-gonic/gin"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func Init(r *gin.Engine) {
|
|
web(r)
|
|
server(r)
|
|
log.Debugf("router init done")
|
|
}
|
|
|
|
func web(r *gin.Engine) {
|
|
execPath, err := os.Executable()
|
|
if err != nil {
|
|
panic("invalid executable path")
|
|
}
|
|
|
|
execDir := filepath.Dir(execPath)
|
|
webPath := fmt.Sprintf("%s/web", execDir)
|
|
|
|
r.Use(static.Serve("/", static.LocalFile(webPath, true)))
|
|
}
|
|
|
|
func server(r *gin.Engine) {
|
|
control := controlmode.GetManager()
|
|
picoclawService := picoclaw.NewService(control)
|
|
|
|
authRouter(r)
|
|
applicationRouter(r)
|
|
vmRouter(r)
|
|
streamRouter(r)
|
|
storageRouter(r)
|
|
networkRouter(r)
|
|
hidRouter(r)
|
|
controlRouter(r, control, picoclawService)
|
|
mcpRouter(r, control, picoclawService)
|
|
picoclawRouter(r, picoclawService)
|
|
wsRouter(r)
|
|
downloadRouter(r)
|
|
extensionsRouter(r)
|
|
}
|
|
|
|
func LoopbackHTTPAllowedPaths() []string {
|
|
paths := PicoclawLoopbackHTTPAllowedPaths()
|
|
paths = append(paths, HIDLoopbackHTTPAllowedPaths()...)
|
|
return paths
|
|
}
|