- 48 个 Go 文件所有注释(行注释/块注释/行尾注释,含 _test.go)翻译为中文 - 保留技术标识符:SECURITY_TODO(n)、unsafe-inline、sqlite/mysql、路由参数等 - 代码、字符串字面量、日志消息保持英文原文,零逻辑改动 - go build/vet 通过,go test -count=1 ./... 全绿
124 lines
4.3 KiB
Go
124 lines
4.3 KiB
Go
package models
|
||
|
||
import "time"
|
||
|
||
// SiteSetting 保存单例(id=1)的全局展示配置:
|
||
// 徽标、左上角标题、页头横幅文案和页脚文案,每项均有 zh/en 变体,
|
||
// 为空时回退到 i18n 默认值。
|
||
type SiteSetting struct {
|
||
ID uint `gorm:"primarykey" json:"id"`
|
||
Logo string `gorm:"size:512" json:"logo"` // 本地文件名(供 /uploads/logos 目录提供)或完整 URL
|
||
Favicon string `gorm:"size:512" json:"favicon"` // 本地文件名(供 /uploads/logos 目录提供)或完整 URL
|
||
LogoTextZh string `gorm:"size:255" json:"logo_text_zh"` // 左上角标题(中文)
|
||
LogoTextEn string `gorm:"size:255" json:"logo_text_en"` // 左上角标题(英文)
|
||
HeaderTextZh string `gorm:"size:512" json:"header_text_zh"` // 页头横幅文案(中文)
|
||
HeaderTextEn string `gorm:"size:512" json:"header_text_en"` // 页头横幅文案(英文)
|
||
HomeWelcomeZh string `gorm:"size:255" json:"home_welcome_zh"` // 首页欢迎标题(中文)
|
||
HomeWelcomeEn string `gorm:"size:255" json:"home_welcome_en"` // 首页欢迎标题(英文)
|
||
HomeSubtitleZh string `gorm:"size:512" json:"home_subtitle_zh"`// 首页副标题(中文)
|
||
HomeSubtitleEn string `gorm:"size:512" json:"home_subtitle_en"`// 首页副标题(英文)
|
||
FooterTextZh string `gorm:"size:512" json:"footer_text_zh"` // 页脚文案(中文)
|
||
FooterTextEn string `gorm:"size:512" json:"footer_text_en"` // 页脚文案(英文)
|
||
// SiteURL 是用于 RSS/订阅链接的规范化站点基础 URL(SECURITY_TODO #16);
|
||
// 为空时在运行时回退到请求的 Host。
|
||
SiteURL string `gorm:"size:512" json:"site_url"`
|
||
AllowRegistration bool `gorm:"default:false" json:"allow_registration"` // 是否允许用户自助注册
|
||
UpdatedBy uint `gorm:"index" json:"updated_by"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
}
|
||
|
||
// TableName 覆盖 GORM 默认的表名。
|
||
func (SiteSetting) TableName() string {
|
||
return "site_settings"
|
||
}
|
||
|
||
// LogoIsURL 报告徽标值是否为外部 URL 而非本地文件名。
|
||
func (s *SiteSetting) LogoIsURL() bool {
|
||
if s == nil || s.Logo == "" {
|
||
return false
|
||
}
|
||
return len(s.Logo) >= 4 && (s.Logo[:4] == "http")
|
||
}
|
||
|
||
// FaviconIsURL 报告 favicon 值是否为外部 URL 而非本地文件名。
|
||
func (s *SiteSetting) FaviconIsURL() bool {
|
||
if s == nil || s.Favicon == "" {
|
||
return false
|
||
}
|
||
return len(s.Favicon) >= 4 && (s.Favicon[:4] == "http")
|
||
}
|
||
|
||
// LogoText 返回指定语言代码下的标题,当所请求语言为空时回退到另一语言。
|
||
func (s *SiteSetting) LogoText(lang string) string {
|
||
if lang == "zh" {
|
||
if s.LogoTextZh != "" {
|
||
return s.LogoTextZh
|
||
}
|
||
return s.LogoTextEn
|
||
}
|
||
if s.LogoTextEn != "" {
|
||
return s.LogoTextEn
|
||
}
|
||
return s.LogoTextZh
|
||
}
|
||
|
||
// HeaderText 返回指定语言代码下的页头横幅文案,当所请求语言为空时
|
||
// 回退到另一语言。
|
||
func (s *SiteSetting) HeaderText(lang string) string {
|
||
if lang == "zh" {
|
||
if s.HeaderTextZh != "" {
|
||
return s.HeaderTextZh
|
||
}
|
||
return s.HeaderTextEn
|
||
}
|
||
if s.HeaderTextEn != "" {
|
||
return s.HeaderTextEn
|
||
}
|
||
return s.HeaderTextZh
|
||
}
|
||
|
||
// HomeWelcome 返回指定语言下的首页欢迎标题,当所请求语言为空时
|
||
// 回退到另一语言。
|
||
func (s *SiteSetting) HomeWelcome(lang string) string {
|
||
if lang == "zh" {
|
||
if s.HomeWelcomeZh != "" {
|
||
return s.HomeWelcomeZh
|
||
}
|
||
return s.HomeWelcomeEn
|
||
}
|
||
if s.HomeWelcomeEn != "" {
|
||
return s.HomeWelcomeEn
|
||
}
|
||
return s.HomeWelcomeZh
|
||
}
|
||
|
||
// HomeSubtitle 返回指定语言下的首页副标题,当所请求语言为空时
|
||
// 回退到另一语言。
|
||
func (s *SiteSetting) HomeSubtitle(lang string) string {
|
||
if lang == "zh" {
|
||
if s.HomeSubtitleZh != "" {
|
||
return s.HomeSubtitleZh
|
||
}
|
||
return s.HomeSubtitleEn
|
||
}
|
||
if s.HomeSubtitleEn != "" {
|
||
return s.HomeSubtitleEn
|
||
}
|
||
return s.HomeSubtitleZh
|
||
}
|
||
|
||
// FooterText 返回指定语言代码下的页脚文案,当所请求语言为空时
|
||
// 回退到另一语言。
|
||
func (s *SiteSetting) FooterText(lang string) string {
|
||
if lang == "zh" {
|
||
if s.FooterTextZh != "" {
|
||
return s.FooterTextZh
|
||
}
|
||
return s.FooterTextEn
|
||
}
|
||
if s.FooterTextEn != "" {
|
||
return s.FooterTextEn
|
||
}
|
||
return s.FooterTextZh
|
||
}
|