refactor: 移除旧版数据库配置的简易模式实现
移除与 PR #66 冲突的旧版简易模式实现(commit 7d4b7de)。 新版简易模式通过 run_mode 配置文件/环境变量控制,无需数据库设置。 后端变更: - 移除 SettingKeySimpleMode 常量 - 移除 SystemSettings/PublicSettings 中的 SimpleMode 字段 - 移除 setting_handler 中的简易模式切换逻辑 - 移除 userService 依赖(不再需要自动设置管理员并发数) 前端变更: - 移除 appStore.simpleMode 状态 - 移除设置页面的"使用模式"设置区块 - 移除 GroupsView 中的简易模式相关逻辑 - 移除相关国际化文案
This commit is contained in:
@@ -99,7 +99,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
||||
geminiOAuthHandler := admin.NewGeminiOAuthHandler(geminiOAuthService)
|
||||
proxyHandler := admin.NewProxyHandler(adminService)
|
||||
adminRedeemHandler := admin.NewRedeemHandler(adminService)
|
||||
settingHandler := admin.NewSettingHandler(settingService, emailService, userService)
|
||||
settingHandler := admin.NewSettingHandler(settingService, emailService)
|
||||
updateCache := repository.NewUpdateCache(client)
|
||||
gitHubReleaseClient := repository.NewGitHubReleaseClient()
|
||||
serviceBuildInfo := provideServiceBuildInfo(buildInfo)
|
||||
|
||||
@@ -12,15 +12,13 @@ import (
|
||||
type SettingHandler struct {
|
||||
settingService *service.SettingService
|
||||
emailService *service.EmailService
|
||||
userService *service.UserService
|
||||
}
|
||||
|
||||
// NewSettingHandler 创建系统设置处理器
|
||||
func NewSettingHandler(settingService *service.SettingService, emailService *service.EmailService, userService *service.UserService) *SettingHandler {
|
||||
func NewSettingHandler(settingService *service.SettingService, emailService *service.EmailService) *SettingHandler {
|
||||
return &SettingHandler{
|
||||
settingService: settingService,
|
||||
emailService: emailService,
|
||||
userService: userService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +52,6 @@ func (h *SettingHandler) GetSettings(c *gin.Context) {
|
||||
DocUrl: settings.DocUrl,
|
||||
DefaultConcurrency: settings.DefaultConcurrency,
|
||||
DefaultBalance: settings.DefaultBalance,
|
||||
SimpleMode: settings.SimpleMode,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -89,9 +86,6 @@ type UpdateSettingsRequest struct {
|
||||
// 默认配置
|
||||
DefaultConcurrency int `json:"default_concurrency"`
|
||||
DefaultBalance float64 `json:"default_balance"`
|
||||
|
||||
// 使用模式
|
||||
SimpleMode bool `json:"simple_mode"`
|
||||
}
|
||||
|
||||
// UpdateSettings 更新系统设置
|
||||
@@ -114,14 +108,8 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
||||
req.SmtpPort = 587
|
||||
}
|
||||
|
||||
// 简单模式下自动关闭开放注册
|
||||
registrationEnabled := req.RegistrationEnabled
|
||||
if req.SimpleMode {
|
||||
registrationEnabled = false
|
||||
}
|
||||
|
||||
settings := &service.SystemSettings{
|
||||
RegistrationEnabled: registrationEnabled,
|
||||
RegistrationEnabled: req.RegistrationEnabled,
|
||||
EmailVerifyEnabled: req.EmailVerifyEnabled,
|
||||
SmtpHost: req.SmtpHost,
|
||||
SmtpPort: req.SmtpPort,
|
||||
@@ -141,7 +129,6 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
||||
DocUrl: req.DocUrl,
|
||||
DefaultConcurrency: req.DefaultConcurrency,
|
||||
DefaultBalance: req.DefaultBalance,
|
||||
SimpleMode: req.SimpleMode,
|
||||
}
|
||||
|
||||
if err := h.settingService.UpdateSettings(c.Request.Context(), settings); err != nil {
|
||||
@@ -149,14 +136,6 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 如果切换到简单模式,自动将管理员并发数设为 99999
|
||||
if req.SimpleMode && h.userService != nil {
|
||||
admin, err := h.userService.GetFirstAdmin(c.Request.Context())
|
||||
if err == nil && admin != nil {
|
||||
_ = h.userService.UpdateConcurrency(c.Request.Context(), admin.ID, 99999)
|
||||
}
|
||||
}
|
||||
|
||||
// 重新获取设置返回
|
||||
updatedSettings, err := h.settingService.GetAllSettings(c.Request.Context())
|
||||
if err != nil {
|
||||
@@ -185,7 +164,6 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
||||
DocUrl: updatedSettings.DocUrl,
|
||||
DefaultConcurrency: updatedSettings.DefaultConcurrency,
|
||||
DefaultBalance: updatedSettings.DefaultBalance,
|
||||
SimpleMode: updatedSettings.SimpleMode,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ type SystemSettings struct {
|
||||
|
||||
DefaultConcurrency int `json:"default_concurrency"`
|
||||
DefaultBalance float64 `json:"default_balance"`
|
||||
|
||||
SimpleMode bool `json:"simple_mode"` // 简单模式
|
||||
}
|
||||
|
||||
type PublicSettings struct {
|
||||
@@ -42,5 +40,4 @@ type PublicSettings struct {
|
||||
ContactInfo string `json:"contact_info"`
|
||||
DocUrl string `json:"doc_url"`
|
||||
Version string `json:"version"`
|
||||
SimpleMode bool `json:"simple_mode"` // 简单模式
|
||||
}
|
||||
|
||||
@@ -43,6 +43,5 @@ func (h *SettingHandler) GetPublicSettings(c *gin.Context) {
|
||||
ContactInfo: settings.ContactInfo,
|
||||
DocUrl: settings.DocUrl,
|
||||
Version: h.version,
|
||||
SimpleMode: settings.SimpleMode,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -90,9 +90,6 @@ const (
|
||||
|
||||
// 管理员 API Key
|
||||
SettingKeyAdminApiKey = "admin_api_key" // 全局管理员 API Key(用于外部系统集成)
|
||||
|
||||
// 使用模式
|
||||
SettingKeySimpleMode = "simple_mode" // 简单模式(隐藏多用户管理功能)
|
||||
)
|
||||
|
||||
// Admin API Key prefix (distinct from user "sk-" keys)
|
||||
|
||||
@@ -64,7 +64,6 @@ func (s *SettingService) GetPublicSettings(ctx context.Context) (*PublicSettings
|
||||
SettingKeyApiBaseUrl,
|
||||
SettingKeyContactInfo,
|
||||
SettingKeyDocUrl,
|
||||
SettingKeySimpleMode,
|
||||
}
|
||||
|
||||
settings, err := s.settingRepo.GetMultiple(ctx, keys)
|
||||
@@ -83,7 +82,6 @@ func (s *SettingService) GetPublicSettings(ctx context.Context) (*PublicSettings
|
||||
ApiBaseUrl: settings[SettingKeyApiBaseUrl],
|
||||
ContactInfo: settings[SettingKeyContactInfo],
|
||||
DocUrl: settings[SettingKeyDocUrl],
|
||||
SimpleMode: settings[SettingKeySimpleMode] == "true",
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -125,9 +123,6 @@ func (s *SettingService) UpdateSettings(ctx context.Context, settings *SystemSet
|
||||
updates[SettingKeyDefaultConcurrency] = strconv.Itoa(settings.DefaultConcurrency)
|
||||
updates[SettingKeyDefaultBalance] = strconv.FormatFloat(settings.DefaultBalance, 'f', 8, 64)
|
||||
|
||||
// 使用模式
|
||||
updates[SettingKeySimpleMode] = strconv.FormatBool(settings.SimpleMode)
|
||||
|
||||
return s.settingRepo.SetMultiple(ctx, updates)
|
||||
}
|
||||
|
||||
@@ -228,7 +223,6 @@ func (s *SettingService) parseSettings(settings map[string]string) *SystemSettin
|
||||
ApiBaseUrl: settings[SettingKeyApiBaseUrl],
|
||||
ContactInfo: settings[SettingKeyContactInfo],
|
||||
DocUrl: settings[SettingKeyDocUrl],
|
||||
SimpleMode: settings[SettingKeySimpleMode] == "true",
|
||||
}
|
||||
|
||||
// 解析整数类型
|
||||
|
||||
@@ -25,8 +25,6 @@ type SystemSettings struct {
|
||||
|
||||
DefaultConcurrency int
|
||||
DefaultBalance float64
|
||||
|
||||
SimpleMode bool // 简单模式
|
||||
}
|
||||
|
||||
type PublicSettings struct {
|
||||
@@ -41,5 +39,4 @@ type PublicSettings struct {
|
||||
ContactInfo string
|
||||
DocUrl string
|
||||
Version string
|
||||
SimpleMode bool // 简单模式
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user