From 06738d5d16daa4886e125f735c1a2c1aa043fcf2 Mon Sep 17 00:00:00 2001 From: naiba Date: Tue, 10 Dec 2024 22:27:06 +0800 Subject: [PATCH] feat: enhance template configuration and update README for translation status --- README.md | 6 ++++++ cmd/dashboard/controller/controller.go | 4 ++-- cmd/dashboard/controller/setting.go | 4 +++- model/config.go | 13 +++++++++++-- model/setting_api.go | 4 ++-- service/singleton/frontend-templates.yaml | 7 ++++--- 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b30a73b..b872b5a 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ ### Translation + +Translation status + + Is Nezha not in your language, or the translation is incorrect or incomplete? Get involved in the translations on [Hosted Weblate](https://hosted.weblate.org/engage/nezha/). ## Screenshots @@ -35,6 +39,8 @@ Is Nezha not in your language, or the translation is incorrect or incomplete? Ge | ![user](.github/user-frontend.20241128.png) | ![admin](.github/admin-frontend.20241128.png) | | [hamster1963/nezha-dash](https://github.com/hamster1963/nezha-dash) | [nezhahq/admin-frontend](https://github.com/nezhahq/admin-frontend) | +add your theme to [service/singleton/frontend-templates.yaml](service/singleton/frontend-templates.yaml) + ## Contributors naiba diff --git a/cmd/dashboard/controller/controller.go b/cmd/dashboard/controller/controller.go index 6755687..9f0f4af 100644 --- a/cmd/dashboard/controller/controller.go +++ b/cmd/dashboard/controller/controller.go @@ -240,11 +240,11 @@ func fallbackToFrontend(frontendDist fs.FS) func(*gin.Context) { } if strings.HasPrefix(c.Request.URL.Path, "/dashboard") { stripPath := strings.TrimPrefix(c.Request.URL.Path, "/dashboard") - localFilePath := path.Join("admin-dist", stripPath) + localFilePath := path.Join(singleton.Conf.AdminTemplate, stripPath) if checkLocalFileOrFs(c, frontendDist, localFilePath) { return } - if !checkLocalFileOrFs(c, frontendDist, "admin-dist/index.html") { + if !checkLocalFileOrFs(c, frontendDist, singleton.Conf.AdminTemplate+"/index.html") { c.JSON(http.StatusOK, newErrorResponse(errors.New("404 Not Found"))) } return diff --git a/cmd/dashboard/controller/setting.go b/cmd/dashboard/controller/setting.go index ef3a1b4..e7dd606 100644 --- a/cmd/dashboard/controller/setting.go +++ b/cmd/dashboard/controller/setting.go @@ -60,8 +60,10 @@ func updateConfig(c *gin.Context) (any, error) { } var userTemplateValid bool for _, v := range singleton.FrontendTemplates { - if v.Path == sf.UserTemplate && sf.UserTemplate != "admin-dist" { + if !userTemplateValid && v.Path == sf.UserTemplate && !v.IsAdmin { userTemplateValid = true + } + if userTemplateValid { break } } diff --git a/model/config.go b/model/config.go index ce839d4..4befbb2 100644 --- a/model/config.go +++ b/model/config.go @@ -28,6 +28,7 @@ type Config struct { Language string `mapstructure:"language" json:"language"` // 系统语言,默认 zh_CN SiteName string `mapstructure:"site_name" json:"site_name"` UserTemplate string `mapstructure:"user_template" json:"user_template,omitempty"` + AdminTemplate string `mapstructure:"admin_template" json:"admin_template,omitempty"` JWTSecretKey string `mapstructure:"jwt_secret_key" json:"jwt_secret_key,omitempty"` AgentSecretKey string `mapstructure:"agent_secret_key" json:"agent_secret_key,omitempty"` ListenPort uint `mapstructure:"listen_port" json:"listen_port,omitempty"` @@ -88,16 +89,24 @@ func (c *Config) Read(path string, frontendTemplates []FrontendTemplate) error { if c.Location == "" { c.Location = "Asia/Shanghai" } - var userTemplateValid bool + var userTemplateValid, adminTemplateValid bool for _, v := range frontendTemplates { - if v.Path == c.UserTemplate && c.UserTemplate != "admin-dist" { + if !userTemplateValid && v.Path == c.UserTemplate && !v.IsAdmin { userTemplateValid = true + } + if !adminTemplateValid && v.Path == c.AdminTemplate && v.IsAdmin { + adminTemplateValid = true + } + if userTemplateValid && adminTemplateValid { break } } if c.UserTemplate == "" || !userTemplateValid { c.UserTemplate = "user-dist" } + if c.AdminTemplate == "" || !adminTemplateValid { + c.AdminTemplate = "admin-dist" + } if c.AvgPingCount == 0 { c.AvgPingCount = 2 } diff --git a/model/setting_api.go b/model/setting_api.go index db3dbcb..b75becb 100644 --- a/model/setting_api.go +++ b/model/setting_api.go @@ -23,9 +23,9 @@ type FrontendTemplate struct { Name string `json:"name,omitempty"` Repository string `json:"repository,omitempty"` Author string `json:"author,omitempty"` - Community bool `json:"community,omitempty"` Version string `json:"version,omitempty"` - IsAdmin string `json:"is_admin,omitempty"` + IsAdmin bool `json:"is_admin,omitempty"` + IsOfficial bool `json:"is_official,omitempty"` } type SettingResponse struct { diff --git a/service/singleton/frontend-templates.yaml b/service/singleton/frontend-templates.yaml index d4e5a07..b38f8e4 100644 --- a/service/singleton/frontend-templates.yaml +++ b/service/singleton/frontend-templates.yaml @@ -2,16 +2,17 @@ name: "OfficialAdmin" repository: "https://github.com/nezhahq/admin-frontend" author: "nezhahq" - version: "v1.1.1" + version: "v1.1.3" isadmin: true + isofficial: true - path: "user-dist" name: "Official" repository: "https://github.com/hamster1963/nezha-dash-v1" author: "hamster1963" version: "v1.2.5" + isofficial: true - path: "nazhua-dist" name: "Nazhua" repository: "https://github.com/hi2shark/nazhua" author: "hi2hi" - version: "v0.4.10" - community: true + version: "v0.4.13"