feat: complete 2.0.7.12 platform overhaul
This commit is contained in:
@@ -4,9 +4,9 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"ymhut-box/server/unified-management/internal/adminassets"
|
||||
webassets "ymhut-box/server/unified-management/web"
|
||||
)
|
||||
|
||||
@@ -46,45 +46,37 @@ func Preflight(cfg *Config) []Check {
|
||||
checkSeedFile("legacy update-info", filepath.Join(cfg.UpdatePublicDir, "update-info.json"), []byte(defaultUpdateInfoJSON)),
|
||||
checkSeedFile("legacy media-types", filepath.Join(cfg.UpdatePublicDir, "media-types.json"), []byte(defaultMediaTypesJSON)),
|
||||
checkNoticeIndex("version notice index", filepath.Join(cfg.UpdateNoticeDir, "total.json")),
|
||||
checkAdminWebBuild("admin web dist", cfg.AdminWebDir, "admin/dist"),
|
||||
checkAdminWebBuild("admin web dist", cfg),
|
||||
checkWebBuild("portal web dist", cfg.PortalWebDir, "portal/dist"),
|
||||
checkWebBuild("setup web dist", cfg.SetupWebDir, "setup/dist"),
|
||||
}
|
||||
return checks
|
||||
}
|
||||
|
||||
var adminPreflightAssetPattern = regexp.MustCompile(`(?:src|href)=["'](/admin/assets/[^"'?#]+)`)
|
||||
func checkAdminWebBuild(name string, cfg *Config) Check {
|
||||
var status adminassets.Diagnostics
|
||||
path := cfg.AdminWebDir
|
||||
if cfg.AdminAssetMode == adminassets.ModeEmbedded {
|
||||
status = adminassets.ValidateEmbedded(AdminBuildID)
|
||||
path = "embedded:admin/dist"
|
||||
} else {
|
||||
status = adminassets.ValidateDisk(cfg.AdminWebDir, AdminBuildID)
|
||||
}
|
||||
if !status.Ready {
|
||||
message := status.ValidationError
|
||||
if cfg.AdminAssetMode == adminassets.ModeDisk {
|
||||
message = strings.ReplaceAll(message, cfg.AdminWebDir, ".")
|
||||
}
|
||||
return Check{Name: name, Status: "error", Path: path, Message: message}
|
||||
}
|
||||
return Check{
|
||||
Name: name, Status: "ok", Path: path,
|
||||
Message: fmt.Sprintf("%s assets; build %s; %d manifest entries", status.Mode, status.BuildID, status.ManifestEntries),
|
||||
}
|
||||
}
|
||||
|
||||
func checkAdminWebBuild(name, path, embedRoot string) Check {
|
||||
check := checkWebBuild(name, path, embedRoot)
|
||||
if check.Status != "ok" || strings.Contains(check.Message, "embedded frontend assets") {
|
||||
return check
|
||||
}
|
||||
index := filepath.Join(path, "index.html")
|
||||
data, err := os.ReadFile(index)
|
||||
if err != nil {
|
||||
return check
|
||||
}
|
||||
matches := adminPreflightAssetPattern.FindAllSubmatch(data, -1)
|
||||
if len(matches) == 0 {
|
||||
return Check{Name: name, Status: "error", Path: index, Message: "index.html does not reference any /admin/assets files"}
|
||||
}
|
||||
for _, match := range matches {
|
||||
assetPath := strings.TrimPrefix(string(match[1]), "/admin/")
|
||||
if strings.Contains(assetPath, "..") || strings.ContainsAny(assetPath, `\`) {
|
||||
return Check{Name: name, Status: "error", Path: index, Message: fmt.Sprintf("invalid admin asset reference %s", assetPath)}
|
||||
}
|
||||
info, statErr := os.Stat(filepath.Join(path, filepath.FromSlash(assetPath)))
|
||||
if statErr == nil && !info.IsDir() {
|
||||
continue
|
||||
}
|
||||
message := fmt.Sprintf("disk asset %s is missing", assetPath)
|
||||
if embeddedWebBuildOK(embedRoot) {
|
||||
return Check{Name: name, Status: "ok", Path: path, Message: message + "; using embedded frontend assets"}
|
||||
}
|
||||
return Check{Name: name, Status: "error", Path: filepath.Join(path, filepath.FromSlash(assetPath)), Message: message}
|
||||
}
|
||||
return check
|
||||
func defaultAdminAssetMode() string {
|
||||
return adminassets.DefaultMode()
|
||||
}
|
||||
|
||||
func checkDir(name, path string, create bool) Check {
|
||||
|
||||
Reference in New Issue
Block a user