mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
fix dashboard custom theme, expose HideForGuest for api (#434)
* fix: dashboard custom theme * api: expose HideForGuest
This commit is contained in:
parent
55f5c89c1c
commit
0b7f43b149
@ -84,7 +84,7 @@ func routers(r *gin.Engine) {
|
||||
}
|
||||
|
||||
func loadThirdPartyTemplates(tmpl *template.Template) *template.Template {
|
||||
var ret = tmpl
|
||||
ret := tmpl
|
||||
themes, err := os.ReadDir("resource/template")
|
||||
if err != nil {
|
||||
log.Printf("NEZHA>> Error reading themes folder: %v", err)
|
||||
@ -96,6 +96,12 @@ func loadThirdPartyTemplates(tmpl *template.Template) *template.Template {
|
||||
}
|
||||
|
||||
themeDir := theme.Name()
|
||||
if strings.HasPrefix(themeDir, "dashboard-") {
|
||||
// load dashboard templates, ignore desc file
|
||||
ret = loadTemplates(ret, themeDir)
|
||||
continue
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(themeDir, "theme-") {
|
||||
log.Printf("NEZHA>> Invalid theme name: %s", themeDir)
|
||||
continue
|
||||
@ -115,22 +121,27 @@ func loadThirdPartyTemplates(tmpl *template.Template) *template.Template {
|
||||
}
|
||||
|
||||
// load templates
|
||||
templatePath := filepath.Join("resource", "template", themeDir, "*.html")
|
||||
t, err := ret.ParseGlob(templatePath)
|
||||
if err != nil {
|
||||
log.Printf("NEZHA>> Error parsing templates %s: %v", themeDir, err)
|
||||
continue
|
||||
}
|
||||
ret = loadTemplates(ret, themeDir)
|
||||
|
||||
themeKey := strings.TrimPrefix(themeDir, "theme-")
|
||||
model.Themes[themeKey] = themeName.String()
|
||||
|
||||
ret = t
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func loadTemplates(tmpl *template.Template, themeDir string) *template.Template {
|
||||
// load templates
|
||||
templatePath := filepath.Join("resource", "template", themeDir, "*.html")
|
||||
t, err := tmpl.ParseGlob(templatePath)
|
||||
if err != nil {
|
||||
log.Printf("NEZHA>> Error parsing templates %s: %v", themeDir, err)
|
||||
return tmpl
|
||||
}
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
var funcMap = template.FuncMap{
|
||||
"tr": func(id string, dataAndCount ...interface{}) string {
|
||||
conf := i18n.LocalizeConfig{
|
||||
|
@ -940,7 +940,7 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, yes := model.Themes[sf.DashboardTheme]; !yes {
|
||||
if _, yes := model.DashboardThemes[sf.DashboardTheme]; !yes {
|
||||
c.JSON(http.StatusOK, model.Response{
|
||||
Code: http.StatusBadRequest,
|
||||
Message: fmt.Sprintf("后台主题不存在:%s", sf.DashboardTheme),
|
||||
|
@ -34,6 +34,7 @@ type CommonServerInfo struct {
|
||||
IPV6 string `json:"ipv6"`
|
||||
ValidIP string `json:"valid_ip"`
|
||||
DisplayIndex int `json:"display_index"`
|
||||
HideForGuest bool `json:"hide_for_guest"`
|
||||
}
|
||||
|
||||
// StatusResponse 服务器状态子结构 包含服务器信息与状态信息
|
||||
@ -150,6 +151,7 @@ func (s *ServerAPIService) GetAllStatus() *ServerStatusResponse {
|
||||
IPV6: ipv6,
|
||||
ValidIP: validIP,
|
||||
DisplayIndex: v.DisplayIndex,
|
||||
HideForGuest: v.HideForGuest,
|
||||
}
|
||||
res.Result = append(res.Result, &StatusResponse{
|
||||
CommonServerInfo: info,
|
||||
|
Loading…
Reference in New Issue
Block a user