feat: enhance template configuration and update README for translation status

This commit is contained in:
naiba 2024-12-10 22:27:06 +08:00
parent 8f8a30c02c
commit 06738d5d16
6 changed files with 28 additions and 10 deletions

View File

@ -26,6 +26,10 @@
### Translation ### Translation
<a href="https://hosted.weblate.org/engage/nezha/">
<img src="https://hosted.weblate.org/widget/nezha/multi-blue.svg" alt="Translation status" />
</a>
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/). 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 ## 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) | | ![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) | | [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 ## Contributors
<!--GAMFC_DELIMITER--><a href="https://github.com/naiba" title="naiba"><img src="https://avatars.githubusercontent.com/u/29243953?v=4" width="50;" alt="naiba"/></a> <!--GAMFC_DELIMITER--><a href="https://github.com/naiba" title="naiba"><img src="https://avatars.githubusercontent.com/u/29243953?v=4" width="50;" alt="naiba"/></a>

View File

@ -240,11 +240,11 @@ func fallbackToFrontend(frontendDist fs.FS) func(*gin.Context) {
} }
if strings.HasPrefix(c.Request.URL.Path, "/dashboard") { if strings.HasPrefix(c.Request.URL.Path, "/dashboard") {
stripPath := strings.TrimPrefix(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) { if checkLocalFileOrFs(c, frontendDist, localFilePath) {
return 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"))) c.JSON(http.StatusOK, newErrorResponse(errors.New("404 Not Found")))
} }
return return

View File

@ -60,8 +60,10 @@ func updateConfig(c *gin.Context) (any, error) {
} }
var userTemplateValid bool var userTemplateValid bool
for _, v := range singleton.FrontendTemplates { for _, v := range singleton.FrontendTemplates {
if v.Path == sf.UserTemplate && sf.UserTemplate != "admin-dist" { if !userTemplateValid && v.Path == sf.UserTemplate && !v.IsAdmin {
userTemplateValid = true userTemplateValid = true
}
if userTemplateValid {
break break
} }
} }

View File

@ -28,6 +28,7 @@ type Config struct {
Language string `mapstructure:"language" json:"language"` // 系统语言,默认 zh_CN Language string `mapstructure:"language" json:"language"` // 系统语言,默认 zh_CN
SiteName string `mapstructure:"site_name" json:"site_name"` SiteName string `mapstructure:"site_name" json:"site_name"`
UserTemplate string `mapstructure:"user_template" json:"user_template,omitempty"` 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"` JWTSecretKey string `mapstructure:"jwt_secret_key" json:"jwt_secret_key,omitempty"`
AgentSecretKey string `mapstructure:"agent_secret_key" json:"agent_secret_key,omitempty"` AgentSecretKey string `mapstructure:"agent_secret_key" json:"agent_secret_key,omitempty"`
ListenPort uint `mapstructure:"listen_port" json:"listen_port,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 == "" { if c.Location == "" {
c.Location = "Asia/Shanghai" c.Location = "Asia/Shanghai"
} }
var userTemplateValid bool var userTemplateValid, adminTemplateValid bool
for _, v := range frontendTemplates { for _, v := range frontendTemplates {
if v.Path == c.UserTemplate && c.UserTemplate != "admin-dist" { if !userTemplateValid && v.Path == c.UserTemplate && !v.IsAdmin {
userTemplateValid = true userTemplateValid = true
}
if !adminTemplateValid && v.Path == c.AdminTemplate && v.IsAdmin {
adminTemplateValid = true
}
if userTemplateValid && adminTemplateValid {
break break
} }
} }
if c.UserTemplate == "" || !userTemplateValid { if c.UserTemplate == "" || !userTemplateValid {
c.UserTemplate = "user-dist" c.UserTemplate = "user-dist"
} }
if c.AdminTemplate == "" || !adminTemplateValid {
c.AdminTemplate = "admin-dist"
}
if c.AvgPingCount == 0 { if c.AvgPingCount == 0 {
c.AvgPingCount = 2 c.AvgPingCount = 2
} }

View File

@ -23,9 +23,9 @@ type FrontendTemplate struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Repository string `json:"repository,omitempty"` Repository string `json:"repository,omitempty"`
Author string `json:"author,omitempty"` Author string `json:"author,omitempty"`
Community bool `json:"community,omitempty"`
Version string `json:"version,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 { type SettingResponse struct {

View File

@ -2,16 +2,17 @@
name: "OfficialAdmin" name: "OfficialAdmin"
repository: "https://github.com/nezhahq/admin-frontend" repository: "https://github.com/nezhahq/admin-frontend"
author: "nezhahq" author: "nezhahq"
version: "v1.1.1" version: "v1.1.3"
isadmin: true isadmin: true
isofficial: true
- path: "user-dist" - path: "user-dist"
name: "Official" name: "Official"
repository: "https://github.com/hamster1963/nezha-dash-v1" repository: "https://github.com/hamster1963/nezha-dash-v1"
author: "hamster1963" author: "hamster1963"
version: "v1.2.5" version: "v1.2.5"
isofficial: true
- path: "nazhua-dist" - path: "nazhua-dist"
name: "Nazhua" name: "Nazhua"
repository: "https://github.com/hi2shark/nazhua" repository: "https://github.com/hi2shark/nazhua"
author: "hi2hi" author: "hi2hi"
version: "v0.4.10" version: "v0.4.13"
community: true