feat: complete 2.0.7.12 platform overhaul

This commit is contained in:
2026-08-16 19:33:03 +08:00
parent 73555cd04c
commit c9fa6f7a88
159 changed files with 13243 additions and 2539 deletions
@@ -1,20 +1,55 @@
package health
import (
"sync"
"time"
"ymhut-box/server/unified-management/internal/config"
"ymhut-box/server/unified-management/internal/db"
)
func Snapshot(cfg *config.Config, store *db.Store) map[string]any {
type Service struct {
cfg *config.Config
store *db.Store
mu sync.RWMutex
checks []config.Check
checkedAt time.Time
}
func NewService(cfg *config.Config, store *db.Store) *Service {
service := &Service{cfg: cfg, store: store}
service.RefreshPreflight()
return service
}
func (s *Service) RefreshPreflight() []config.Check {
checks := config.Preflight(s.cfg)
s.mu.Lock()
s.checks = append([]config.Check(nil), checks...)
s.checkedAt = time.Now().UTC()
s.mu.Unlock()
return checks
}
func (s *Service) Snapshot() map[string]any {
s.mu.RLock()
checks := append([]config.Check(nil), s.checks...)
checkedAt := s.checkedAt
s.mu.RUnlock()
return map[string]any{
"ok": true,
"version": config.Version,
"service": map[string]any{
"name": "YMhut Unified Management",
"baseUrl": cfg.BaseURL,
"cdnBaseUrl": cfg.CDNBaseURL,
"baseUrl": s.cfg.BaseURL,
"cdnBaseUrl": s.cfg.CDNBaseURL,
},
"database": store.Status(),
"preflight": config.Preflight(cfg),
"database": s.store.Status(),
"preflight": checks,
"preflightCheckedAt": checkedAt.Format(time.RFC3339),
}
}
func Snapshot(cfg *config.Config, store *db.Store) map[string]any {
return NewService(cfg, store).Snapshot()
}
@@ -0,0 +1,38 @@
package health
import (
"os"
"path/filepath"
"testing"
"ymhut-box/server/unified-management/internal/config"
"ymhut-box/server/unified-management/internal/db"
)
func TestSnapshotReadsCachedPreflightUntilManualRefresh(t *testing.T) {
root := t.TempDir()
cfg := &config.Config{
BaseDir: root, StorageDir: filepath.Join(root, "storage"), DataDir: filepath.Join(root, "data"),
UpdatePublicDir: filepath.Join(root, "data", "update", "public"), UpdateNoticeDir: filepath.Join(root, "data", "notices"),
DownloadsDir: filepath.Join(root, "data", "update", "public", "downloads"), AdminWebDir: filepath.Join(root, "admin"),
PortalWebDir: filepath.Join(root, "portal"), SetupWebDir: filepath.Join(root, "setup"), AdminAssetMode: "disk",
Database: config.DatabaseConfig{Provider: "sqlite", SQLitePath: filepath.Join(root, "storage", "health.sqlite"), HealthIntervalSec: 3600},
}
store, err := db.Open(cfg)
if err != nil {
t.Fatal(err)
}
defer store.Close()
service := NewService(cfg, store)
if err := os.RemoveAll(cfg.DownloadsDir); err != nil {
t.Fatal(err)
}
_ = service.Snapshot()
if _, err := os.Stat(cfg.DownloadsDir); !os.IsNotExist(err) {
t.Fatalf("cached snapshot unexpectedly reran filesystem preflight: %v", err)
}
service.RefreshPreflight()
if _, err := os.Stat(cfg.DownloadsDir); err != nil {
t.Fatalf("manual refresh did not recreate downloads directory: %v", err)
}
}