feat: 完整游戏运维功能

This commit is contained in:
npc0-hue
2026-07-18 09:04:01 +08:00
parent f3b14b7945
commit 48b8ad8d6c
187 changed files with 16607 additions and 1140 deletions
+40 -4
View File
@@ -3,6 +3,7 @@ package api
import (
"fmt"
"net/http"
"path/filepath"
"strings"
"browser.local/platform/config"
@@ -27,18 +28,53 @@ func NewRouterFromConfig(cfg config.Config) (http.Handler, error) {
if err != nil {
return nil, err
}
core := service.NewCoreServiceWithLogStore(store, logStore)
if err := core.SeedLocalPlatformAdmin(); err != nil {
artifactDir := strings.TrimSpace(cfg.ArtifactDir)
if artifactDir == "" {
if strings.TrimSpace(cfg.DataDir) != "" {
artifactDir = filepath.Join(cfg.DataDir, "artifacts")
} else {
artifactDir = filepath.Join(filepath.Dir(cfg.MetadataPath), "artifacts")
}
}
artifactStore, err := service.NewFileArtifactBodyStore(artifactDir)
if err != nil {
return nil, err
}
return NewRouterWithCore(core), nil
core, err := service.NewCoreServiceWithDurableStores(store, logStore, artifactStore)
if err != nil {
return nil, err
}
if err := core.ConfigureSecretEnvelopeKey(cfg.SecretEnvelopeKey); err != nil {
return nil, err
}
if strings.TrimSpace(cfg.BootstrapAdminPassword) != "" {
if err := core.SeedPlatformAdmin(cfg.BootstrapAdminEmail, cfg.BootstrapAdminPassword); err != nil {
return nil, err
}
}
return NewAuthorizedRouterWithCore(core), nil
}
func NewRouterWithCore(core service.Core) http.Handler {
handlers := newCoreHandlers(core)
return newRouterWithCore(core, true)
}
func NewAuthorizedRouterWithCore(core service.Core) http.Handler {
return newRouterWithCore(core, true)
}
func NewTestRouterWithCore(core service.Core) http.Handler {
return newRouterWithCore(core, false)
}
func newRouterWithCore(core service.Core, enforceAuthorization bool) http.Handler {
handlers := newCoreHandlers(core, enforceAuthorization)
mux := http.NewServeMux()
mux.HandleFunc("/healthz", HealthHandler)
handlers.register(mux)
if enforceAuthorization {
return handlers.requireAuthorizedAPI(mux)
}
return mux
}