@@ -8,6 +8,25 @@ import (
|
||||
webassets "ymhut-box/server/unified-management/web"
|
||||
)
|
||||
|
||||
const defaultUpdateInfoJSON = `{
|
||||
"app_version": "0.0.0",
|
||||
"download_url": "",
|
||||
"update_notes": {},
|
||||
"last_update_notes": {},
|
||||
"release_notes": "",
|
||||
"release_notes_md": "",
|
||||
"last_updated": ""
|
||||
}
|
||||
`
|
||||
|
||||
const defaultMediaTypesJSON = `{
|
||||
"layout_version": "1.0.0",
|
||||
"last_updated": "",
|
||||
"ui_config": {},
|
||||
"categories": []
|
||||
}
|
||||
`
|
||||
|
||||
type Check struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
@@ -19,12 +38,12 @@ func Preflight(cfg *Config) []Check {
|
||||
checks := []Check{
|
||||
checkDir("storage", cfg.StorageDir, true),
|
||||
checkParent("sqlite", cfg.Database.SQLitePath),
|
||||
checkDir("update public", cfg.UpdatePublicDir, false),
|
||||
checkDir("update notice", cfg.UpdateNoticeDir, false),
|
||||
checkDir("downloads", cfg.DownloadsDir, false),
|
||||
checkFile("legacy update-info", filepath.Join(cfg.UpdatePublicDir, "update-info.json"), false),
|
||||
checkFile("legacy media-types", filepath.Join(cfg.UpdatePublicDir, "media-types.json"), false),
|
||||
checkFile("version notice index", filepath.Join(cfg.UpdateNoticeDir, "total.json"), false),
|
||||
checkDir("update public", cfg.UpdatePublicDir, true),
|
||||
checkDir("update notice", cfg.UpdateNoticeDir, true),
|
||||
checkDir("downloads", cfg.DownloadsDir, true),
|
||||
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")),
|
||||
checkWebBuild("admin web dist", cfg.AdminWebDir, "admin/dist"),
|
||||
checkWebBuild("portal web dist", cfg.PortalWebDir, "portal/dist"),
|
||||
checkWebBuild("setup web dist", cfg.SetupWebDir, "setup/dist"),
|
||||
@@ -48,6 +67,37 @@ func checkDir(name, path string, create bool) Check {
|
||||
return Check{Name: name, Status: "ok", Path: path}
|
||||
}
|
||||
|
||||
func checkNoticeIndex(name, path string) Check {
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
return Check{Name: name, Status: "ok", Path: path}
|
||||
} else if !os.IsNotExist(err) {
|
||||
return Check{Name: name, Status: "error", Path: path, Message: err.Error()}
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o750); err != nil {
|
||||
return Check{Name: name, Status: "error", Path: path, Message: err.Error()}
|
||||
}
|
||||
data := []byte("{\n \"schema_version\": 1,\n \"product\": \"YMhut Box\",\n \"versions\": []\n}\n")
|
||||
if err := os.WriteFile(path, data, 0o640); err != nil {
|
||||
return Check{Name: name, Status: "error", Path: path, Message: err.Error()}
|
||||
}
|
||||
return Check{Name: name, Status: "ok", Path: path, Message: "created empty notice index"}
|
||||
}
|
||||
|
||||
func checkSeedFile(name, path string, data []byte) Check {
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
return Check{Name: name, Status: "ok", Path: path}
|
||||
} else if !os.IsNotExist(err) {
|
||||
return Check{Name: name, Status: "error", Path: path, Message: err.Error()}
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o750); err != nil {
|
||||
return Check{Name: name, Status: "error", Path: path, Message: err.Error()}
|
||||
}
|
||||
if err := os.WriteFile(path, data, 0o640); err != nil {
|
||||
return Check{Name: name, Status: "error", Path: path, Message: err.Error()}
|
||||
}
|
||||
return Check{Name: name, Status: "ok", Path: path, Message: "created default compatibility JSON"}
|
||||
}
|
||||
|
||||
func checkParent(name, path string) Check {
|
||||
dir := filepath.Dir(path)
|
||||
if err := os.MkdirAll(dir, 0o750); err != nil {
|
||||
@@ -116,12 +166,12 @@ func embeddedWebBuildOK(embedRoot string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func FormatPreflight(checks []Check) []string {
|
||||
func FormatPreflight(cfg *Config, checks []Check) []string {
|
||||
lines := make([]string, 0, len(checks))
|
||||
for _, check := range checks {
|
||||
line := fmt.Sprintf("[%s] %s", check.Status, check.Name)
|
||||
if check.Path != "" {
|
||||
line += " -> " + check.Path
|
||||
line += " -> " + relativePath(cfg.BaseDir, check.Path)
|
||||
}
|
||||
if check.Message != "" {
|
||||
line += " (" + check.Message + ")"
|
||||
|
||||
Reference in New Issue
Block a user