From daab64d2322c9428459cab6586ff4300c995db2a Mon Sep 17 00:00:00 2001
From: naiba
Date: Wed, 14 Aug 2024 00:24:17 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E7=AE=A1=E7=90=86=E5=90=8E=E5=8F=B0?=
=?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
cmd/dashboard/controller/common_page.go | 5 +----
cmd/dashboard/controller/member_api.go | 2 ++
model/config.go | 13 +++++++------
pkg/mygin/mygin.go | 2 ++
pkg/mygin/view_password.go | 3 +--
resource/l10n/en-US.toml | 3 +++
resource/l10n/es-ES.toml | 3 +++
resource/l10n/zh-CN.toml | 3 +++
resource/l10n/zh-TW.toml | 3 +++
resource/template/common/footer.html | 3 +--
resource/template/common/header.html | 4 ++++
resource/template/dashboard-default/setting.html | 10 +++++++---
resource/template/theme-default/footer.html | 1 -
resource/template/theme-default/header.html | 8 ++++++--
14 files changed, 43 insertions(+), 20 deletions(-)
diff --git a/cmd/dashboard/controller/common_page.go b/cmd/dashboard/controller/common_page.go
index 24e1c77..ad43d7e 100644
--- a/cmd/dashboard/controller/common_page.go
+++ b/cmd/dashboard/controller/common_page.go
@@ -99,7 +99,6 @@ func (p *commonPage) service(c *gin.Context) {
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "ServicesStatus"}),
"Services": res.([]interface{})[0],
"CycleTransferStats": res.([]interface{})[1],
- "CustomCode": singleton.Conf.Site.CustomCode,
}))
}
@@ -204,7 +203,6 @@ func (cp *commonPage) network(c *gin.Context) {
c.HTML(http.StatusOK, mygin.GetPreferredTheme(c, "/network"), mygin.CommonEnvironment(c, gin.H{
"Servers": string(serversBytes),
"MonitorInfos": string(monitorInfos),
- "CustomCode": singleton.Conf.Site.CustomCode,
"MaxTCPPingValue": singleton.Conf.MaxTCPPingValue,
}))
}
@@ -254,8 +252,7 @@ func (cp *commonPage) home(c *gin.Context) {
return
}
c.HTML(http.StatusOK, mygin.GetPreferredTheme(c, "/home"), mygin.CommonEnvironment(c, gin.H{
- "Servers": string(stat),
- "CustomCode": singleton.Conf.Site.CustomCode,
+ "Servers": string(stat),
}))
}
diff --git a/cmd/dashboard/controller/member_api.go b/cmd/dashboard/controller/member_api.go
index e614516..713a275 100644
--- a/cmd/dashboard/controller/member_api.go
+++ b/cmd/dashboard/controller/member_api.go
@@ -908,6 +908,7 @@ type settingForm struct {
Theme string
DashboardTheme string
CustomCode string
+ CustomCodeDashboard string
ViewPassword string
IgnoredIPNotification string
IPChangeNotificationTag string // IP变更提醒的通知组
@@ -973,6 +974,7 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
singleton.Conf.Site.Theme = sf.Theme
singleton.Conf.Site.DashboardTheme = sf.DashboardTheme
singleton.Conf.Site.CustomCode = sf.CustomCode
+ singleton.Conf.Site.CustomCodeDashboard = sf.CustomCodeDashboard
singleton.Conf.Site.ViewPassword = sf.ViewPassword
singleton.Conf.Oauth2.Admin = sf.Admin
// 保证NotificationTag不为空
diff --git a/model/config.go b/model/config.go
index ca5837b..91d7da7 100644
--- a/model/config.go
+++ b/model/config.go
@@ -80,12 +80,13 @@ type Config struct {
Debug bool // debug模式开关
Language string // 系统语言,默认 zh-CN
Site struct {
- Brand string // 站点名称
- CookieName string // 浏览器 Cookie 名称
- Theme string
- DashboardTheme string
- CustomCode string
- ViewPassword string // 前台查看密码
+ Brand string // 站点名称
+ CookieName string // 浏览器 Cookie 名称
+ Theme string
+ DashboardTheme string
+ CustomCode string
+ CustomCodeDashboard string
+ ViewPassword string // 前台查看密码
}
Oauth2 struct {
Type string
diff --git a/pkg/mygin/mygin.go b/pkg/mygin/mygin.go
index 45df0b1..78d6c1a 100644
--- a/pkg/mygin/mygin.go
+++ b/pkg/mygin/mygin.go
@@ -26,6 +26,8 @@ func CommonEnvironment(c *gin.Context, data map[string]interface{}) gin.H {
data["Version"] = singleton.Version
data["Conf"] = singleton.Conf
data["Themes"] = model.Themes
+ data["CustomCode"] = singleton.Conf.Site.CustomCode
+ data["CustomCodeDashboard"] = singleton.Conf.Site.CustomCodeDashboard
// 是否是管理页面
data["IsAdminPage"] = adminPage[data["MatchedPath"].(string)]
// 站点标题
diff --git a/pkg/mygin/view_password.go b/pkg/mygin/view_password.go
index 35e406b..1fb96ed 100644
--- a/pkg/mygin/view_password.go
+++ b/pkg/mygin/view_password.go
@@ -37,8 +37,7 @@ func ValidateViewPassword(opt ValidateViewPasswordOption) gin.HandlerFunc {
}
if opt.IsPage {
c.HTML(http.StatusOK, GetPreferredTheme(c, "/viewpassword"), CommonEnvironment(c, gin.H{
- "Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "VerifyPassword"}),
- "CustomCode": singleton.Conf.Site.CustomCode,
+ "Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "VerifyPassword"}),
}))
} else {
diff --git a/resource/l10n/en-US.toml b/resource/l10n/en-US.toml
index 1bf2972..4a33281 100644
--- a/resource/l10n/en-US.toml
+++ b/resource/l10n/en-US.toml
@@ -331,6 +331,9 @@ other = "Frontend Theme"
[CustomCodes]
other = "Custom Codes (Style and Script)"
+[CustomCodesDashboard]
+other = "Custom Codes for Dashboard"
+
[AccessPassword]
other = "Frontend Access Password"
diff --git a/resource/l10n/es-ES.toml b/resource/l10n/es-ES.toml
index 0c645b1..accc1ba 100644
--- a/resource/l10n/es-ES.toml
+++ b/resource/l10n/es-ES.toml
@@ -331,6 +331,9 @@ other = "Tema de Frontend"
[CustomCodes]
other = "Códigos Personalizados (Incluye style y script)"
+[CustomCodesDashboard]
+other = "Custom Codes for Dashboard"
+
[AccessPassword]
other = "Contraseña de Acceso al Frontend"
diff --git a/resource/l10n/zh-CN.toml b/resource/l10n/zh-CN.toml
index 5ea9b10..192efa7 100644
--- a/resource/l10n/zh-CN.toml
+++ b/resource/l10n/zh-CN.toml
@@ -331,6 +331,9 @@ other = "前台界面主题"
[CustomCodes]
other = "自定义代码(包括 style 和 script)"
+[CustomCodesDashboard]
+other = "Custom Codes for Dashboard"
+
[AccessPassword]
other = "前台访问密码"
diff --git a/resource/l10n/zh-TW.toml b/resource/l10n/zh-TW.toml
index f43e3dd..9a7cf51 100644
--- a/resource/l10n/zh-TW.toml
+++ b/resource/l10n/zh-TW.toml
@@ -331,6 +331,9 @@ other = "前台界面主題"
[CustomCodes]
other = "自定義代碼(包括 style 和 script)"
+[CustomCodesDashboard]
+other = "Custom Codes for Dashboard"
+
[AccessPassword]
other = "前台訪問密碼"
diff --git a/resource/template/common/footer.html b/resource/template/common/footer.html
index 1fc1fda..042b433 100644
--- a/resource/template/common/footer.html
+++ b/resource/template/common/footer.html
@@ -14,8 +14,7 @@