d6daf1dce6
- 新增站点自定义(标题/Favicon/登录页描述) - 新增在线自定义 CSS/JS 编辑器 - 扩展备份迁移支持面板配置导出导入 - 默认账号改为 admin/1234 - 设置按钮改为橙色更醒目 - 修复登录页误报"登录过期"弹窗 - 修复 i18n 双重 apps 块导致翻译失效 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
116 lines
3.0 KiB
Go
116 lines
3.0 KiB
Go
package systemSetting
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"sun-panel/lib/cache"
|
|
"sun-panel/models"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
const (
|
|
SYSTEM_APPLICATION = "system_application"
|
|
SYSTEM_EMAIL = "system_email"
|
|
DISCLAIMER = "disclaimer" // 免责声明 储存类型:字符串
|
|
WEB_ABOUT_DESCRIPTION = "web_about_description" // 关于的描述信息
|
|
PANEL_PUBLIC_USER_ID = "panel_public_user_id" // 公开访问模式用户id *uint|null
|
|
SITE_CUSTOMIZE = "site_customize" // 站点自定义配置
|
|
CUSTOM_STYLE = "custom_style" // 自定义 CSS/JS
|
|
)
|
|
|
|
type SystemSettingCache struct {
|
|
Cache cache.Cacher[interface{}]
|
|
}
|
|
|
|
type Email struct {
|
|
Host string `json:"host" binding:"required"`
|
|
Port int `json:"port" binding:"required"`
|
|
Mail string `json:"mail" binding:"required,email"`
|
|
Password string `json:"password" binding:"required"`
|
|
}
|
|
|
|
type Register struct {
|
|
EmailSuffix string `json:"emailSuffix"` // 注册邮箱后缀
|
|
OpenRegister bool `json:"openRegister"` // 开放注册
|
|
}
|
|
|
|
type Login struct {
|
|
LoginCaptcha bool `json:"loginCaptcha"` // 登录验证码
|
|
}
|
|
|
|
type ApplicationSetting struct {
|
|
Register
|
|
Login
|
|
WebSiteUrl string `json:"webSiteUrl"` // 站点地址
|
|
}
|
|
|
|
// 站点自定义配置
|
|
type SiteCustomize struct {
|
|
SiteTitle string `json:"siteTitle"` // 站点标题(显示在登录页)
|
|
FaviconUrl string `json:"faviconUrl"` // Favicon 图标 URL
|
|
LoginDescription string `json:"loginDescription"` // 登录页描述文字
|
|
}
|
|
|
|
// 自定义 CSS/JS
|
|
type CustomStyle struct {
|
|
Css string `json:"css"` // 自定义 CSS 内容
|
|
Js string `json:"js"` // 自定义 JS 内容
|
|
}
|
|
|
|
var (
|
|
ErrorNoExists = errors.New("no exists")
|
|
)
|
|
|
|
// 系统配置启用缓存功能
|
|
func (s *SystemSettingCache) GetValueString(configName string) (result string, err error) {
|
|
if v, ok := s.Cache.Get(configName); ok {
|
|
if v1, ok1 := v.(string); ok1 {
|
|
// fmt.Println("读取缓存")
|
|
return v1, nil
|
|
}
|
|
}
|
|
|
|
mSetting := models.SystemSetting{}
|
|
result, err = mSetting.Get(configName)
|
|
if err == gorm.ErrRecordNotFound {
|
|
err = ErrorNoExists
|
|
}
|
|
// 查询出来,缓存起来
|
|
s.Cache.SetDefault(configName, result)
|
|
return
|
|
}
|
|
|
|
// value 需为指针
|
|
func (s *SystemSettingCache) GetValueByInterface(configName string, value interface{}) error {
|
|
if v, ok := s.Cache.Get(configName); ok {
|
|
// fmt.Println("缓存")
|
|
if s, sok := v.(string); sok {
|
|
if err := json.Unmarshal([]byte(s), value); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
mSetting := models.SystemSetting{}
|
|
result, err := mSetting.Get(configName)
|
|
if err == gorm.ErrRecordNotFound {
|
|
err = ErrorNoExists
|
|
return err
|
|
}
|
|
err = json.Unmarshal([]byte(result), value)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
s.Cache.SetDefault(configName, result)
|
|
return nil
|
|
}
|
|
|
|
func (s *SystemSettingCache) Set(configName string, configValue interface{}) error {
|
|
s.Cache.Delete(configName)
|
|
mSetting := models.SystemSetting{}
|
|
err := mSetting.Set(configName, configValue)
|
|
return err
|
|
}
|