完善站点运营设置:分路由管理、登录可见评论、邮件模板内联与关闭注册 SSR。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-23 00:17:00 +08:00
parent acde7ee288
commit 6f054a903c
98 changed files with 8239 additions and 2073 deletions

View File

@@ -22,6 +22,8 @@ const (
SettingKeyAllowRegister = "allow_register"
// SettingKeyAllowComments 全站开放评论;缺行视为开启(默认开)
SettingKeyAllowComments = "allow_comments"
// SettingKeyCommentsRequireLogin 评论仅登录可见;缺行视为关闭(游客可读)
SettingKeyCommentsRequireLogin = "comments_require_login"
// SettingKeyAllowMessages 全站开放私聊/群聊;缺行视为开启(默认开)
SettingKeyAllowMessages = "allow_messages"
SettingKeyPostCooldownHours = "post_cooldown_hours"
@@ -100,8 +102,9 @@ type PublicSiteSettings struct {
SiteName string `json:"site_name"`
SiteDescription string `json:"site_description"`
AllowRegister bool `json:"allow_register"`
AllowComments bool `json:"allow_comments"`
AllowMessages bool `json:"allow_messages"`
AllowComments bool `json:"allow_comments"`
CommentsRequireLogin bool `json:"comments_require_login"`
AllowMessages bool `json:"allow_messages"`
PostCooldownHours int `json:"post_cooldown_hours"`
CodeBlockAutoFold bool `json:"code_block_auto_fold"`
CodeBlockFoldLines int `json:"code_block_fold_lines"`
@@ -181,6 +184,26 @@ func (s *SettingService) setBoolDefaultTrue(key string, on bool) error {
return s.putValue(key, "false")
}
// 缺行视为关;仅显式 true/1/on/yes 为开。
func parseBoolDefaultFalse(v string, found bool) bool {
if !found {
return false
}
switch strings.TrimSpace(strings.ToLower(v)) {
case "true", "1", "on", "yes":
return true
default:
return false
}
}
func (s *SettingService) setBoolDefaultFalse(key string, on bool) error {
if !on {
return s.deleteKey(key)
}
return s.putValue(key, "true")
}
// Public 返回解析后的公开站点设置(缺省已填默认值)
func (s *SettingService) Public() (PublicSiteSettings, error) {
out := PublicSiteSettings{
@@ -189,6 +212,7 @@ func (s *SettingService) Public() (PublicSiteSettings, error) {
TrustReviewedPublish: true,
AllowRegister: true,
AllowComments: true,
CommentsRequireLogin: false,
AllowMessages: true,
PostCooldownHours: DefaultCooldownHours,
CodeBlockAutoFold: true,
@@ -254,6 +278,12 @@ func (s *SettingService) Public() (PublicSiteSettings, error) {
}
out.AllowComments = comments
requireLogin, err := s.CommentsRequireLogin()
if err != nil {
return out, err
}
out.CommentsRequireLogin = requireLogin
messages, err := s.AllowMessages()
if err != nil {
return out, err
@@ -447,6 +477,20 @@ func (s *SettingService) SetAllowComments(on bool) error {
return s.setBoolDefaultTrue(SettingKeyAllowComments, on)
}
// CommentsRequireLogin 评论是否仅登录可见。缺行视为关闭。
func (s *SettingService) CommentsRequireLogin() (bool, error) {
v, found, err := s.getValue(SettingKeyCommentsRequireLogin)
if err != nil {
return false, err
}
return parseBoolDefaultFalse(v, found), nil
}
// SetCommentsRequireLogin 持久化「登录可见评论」;关闭时删键保持「缺行=默认关」。
func (s *SettingService) SetCommentsRequireLogin(on bool) error {
return s.setBoolDefaultFalse(SettingKeyCommentsRequireLogin, on)
}
// AllowMessages 是否允许全站私聊/群聊。缺行视为开启。
func (s *SettingService) AllowMessages() (bool, error) {
v, found, err := s.getValue(SettingKeyAllowMessages)