All checks were successful
Beta Release / beta (push) Successful in 39s
- Terminal: multi-tab sessions, SSH connections, shell detection (zsh/bash/fish/wsl/powershell) - Config: inline profile & provider editing, system update management - Dashboard: grid layout with inline tools/notifications/workflows sections - Add lucide-react icons, i18n keys (FR/EN), and new CSS components 💾 Generated with Crush Assisted-by: GLM-5-Turbo via Crush <crush@charm.land>
65 lines
2.0 KiB
Go
65 lines
2.0 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/muyue/muyue/internal/config"
|
|
"github.com/muyue/muyue/internal/scanner"
|
|
)
|
|
|
|
type Server struct {
|
|
config *config.MuyueConfig
|
|
scanResult *scanner.ScanResult
|
|
mux *http.ServeMux
|
|
}
|
|
|
|
func NewServer(cfg *config.MuyueConfig) *Server {
|
|
s := &Server{
|
|
config: cfg,
|
|
mux: http.NewServeMux(),
|
|
}
|
|
s.scanResult = scanner.ScanSystem()
|
|
s.routes()
|
|
return s
|
|
}
|
|
|
|
func (s *Server) routes() {
|
|
s.mux.HandleFunc("/api/info", s.handleInfo)
|
|
s.mux.HandleFunc("/api/system", s.handleSystem)
|
|
s.mux.HandleFunc("/api/tools", s.handleTools)
|
|
s.mux.HandleFunc("/api/config", s.handleConfig)
|
|
s.mux.HandleFunc("/api/providers", s.handleProviders)
|
|
s.mux.HandleFunc("/api/skills", s.handleSkills)
|
|
s.mux.HandleFunc("/api/lsp", s.handleLSP)
|
|
s.mux.HandleFunc("/api/mcp", s.handleMCP)
|
|
s.mux.HandleFunc("/api/updates", s.handleUpdates)
|
|
s.mux.HandleFunc("/api/install", s.handleInstall)
|
|
s.mux.HandleFunc("/api/scan", s.handleScan)
|
|
s.mux.HandleFunc("/api/preferences", s.handleUpdatePreferences)
|
|
s.mux.HandleFunc("/api/terminal", s.handleTerminal)
|
|
s.mux.HandleFunc("/api/ws/terminal", s.handleTerminalWS)
|
|
s.mux.HandleFunc("/api/terminal/sessions", s.handleTerminalSessions)
|
|
s.mux.HandleFunc("/api/terminal/sessions/", s.handleTerminalSessionsDelete)
|
|
s.mux.HandleFunc("/api/mcp/configure", s.handleMCPConfigure)
|
|
s.mux.HandleFunc("/api/config/profile", s.handleSaveProfile)
|
|
s.mux.HandleFunc("/api/config/provider", s.handleSaveProvider)
|
|
s.mux.HandleFunc("/api/update/run", s.handleRunUpdate)
|
|
}
|
|
|
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
if strings.HasPrefix(r.URL.Path, "/api/ws/") {
|
|
s.mux.ServeHTTP(w, r)
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS")
|
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
|
if r.Method == "OPTIONS" {
|
|
w.WriteHeader(http.StatusOK)
|
|
return
|
|
}
|
|
s.mux.ServeHTTP(w, r)
|
|
}
|