@@ -51,6 +51,13 @@ func (h *SettingHandler) GetSettings(c *gin.Context) {
5151
5252 // Check if ops monitoring is enabled (respects config.ops.enabled)
5353 opsEnabled := h .opsService != nil && h .opsService .IsMonitoringEnabled (c .Request .Context ())
54+ defaultSubscriptions := make ([]dto.DefaultSubscriptionSetting , 0 , len (settings .DefaultSubscriptions ))
55+ for _ , sub := range settings .DefaultSubscriptions {
56+ defaultSubscriptions = append (defaultSubscriptions , dto.DefaultSubscriptionSetting {
57+ GroupID : sub .GroupID ,
58+ ValidityDays : sub .ValidityDays ,
59+ })
60+ }
5461
5562 response .Success (c , dto.SystemSettings {
5663 RegistrationEnabled : settings .RegistrationEnabled ,
@@ -87,6 +94,7 @@ func (h *SettingHandler) GetSettings(c *gin.Context) {
8794 SoraClientEnabled : settings .SoraClientEnabled ,
8895 DefaultConcurrency : settings .DefaultConcurrency ,
8996 DefaultBalance : settings .DefaultBalance ,
97+ DefaultSubscriptions : defaultSubscriptions ,
9098 EnableModelFallback : settings .EnableModelFallback ,
9199 FallbackModelAnthropic : settings .FallbackModelAnthropic ,
92100 FallbackModelOpenAI : settings .FallbackModelOpenAI ,
@@ -146,8 +154,9 @@ type UpdateSettingsRequest struct {
146154 SoraClientEnabled bool `json:"sora_client_enabled"`
147155
148156 // 默认配置
149- DefaultConcurrency int `json:"default_concurrency"`
150- DefaultBalance float64 `json:"default_balance"`
157+ DefaultConcurrency int `json:"default_concurrency"`
158+ DefaultBalance float64 `json:"default_balance"`
159+ DefaultSubscriptions []dto.DefaultSubscriptionSetting `json:"default_subscriptions"`
151160
152161 // Model fallback configuration
153162 EnableModelFallback bool `json:"enable_model_fallback"`
@@ -194,6 +203,7 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
194203 if req .SMTPPort <= 0 {
195204 req .SMTPPort = 587
196205 }
206+ req .DefaultSubscriptions = normalizeDefaultSubscriptions (req .DefaultSubscriptions )
197207
198208 // Turnstile 参数验证
199209 if req .TurnstileEnabled {
@@ -300,6 +310,13 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
300310 }
301311 req .OpsMetricsIntervalSeconds = & v
302312 }
313+ defaultSubscriptions := make ([]service.DefaultSubscriptionSetting , 0 , len (req .DefaultSubscriptions ))
314+ for _ , sub := range req .DefaultSubscriptions {
315+ defaultSubscriptions = append (defaultSubscriptions , service.DefaultSubscriptionSetting {
316+ GroupID : sub .GroupID ,
317+ ValidityDays : sub .ValidityDays ,
318+ })
319+ }
303320
304321 // 验证最低版本号格式(空字符串=禁用,或合法 semver)
305322 if req .MinClaudeCodeVersion != "" {
@@ -343,6 +360,7 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
343360 SoraClientEnabled : req .SoraClientEnabled ,
344361 DefaultConcurrency : req .DefaultConcurrency ,
345362 DefaultBalance : req .DefaultBalance ,
363+ DefaultSubscriptions : defaultSubscriptions ,
346364 EnableModelFallback : req .EnableModelFallback ,
347365 FallbackModelAnthropic : req .FallbackModelAnthropic ,
348366 FallbackModelOpenAI : req .FallbackModelOpenAI ,
@@ -390,6 +408,13 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
390408 response .ErrorFrom (c , err )
391409 return
392410 }
411+ updatedDefaultSubscriptions := make ([]dto.DefaultSubscriptionSetting , 0 , len (updatedSettings .DefaultSubscriptions ))
412+ for _ , sub := range updatedSettings .DefaultSubscriptions {
413+ updatedDefaultSubscriptions = append (updatedDefaultSubscriptions , dto.DefaultSubscriptionSetting {
414+ GroupID : sub .GroupID ,
415+ ValidityDays : sub .ValidityDays ,
416+ })
417+ }
393418
394419 response .Success (c , dto.SystemSettings {
395420 RegistrationEnabled : updatedSettings .RegistrationEnabled ,
@@ -426,6 +451,7 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
426451 SoraClientEnabled : updatedSettings .SoraClientEnabled ,
427452 DefaultConcurrency : updatedSettings .DefaultConcurrency ,
428453 DefaultBalance : updatedSettings .DefaultBalance ,
454+ DefaultSubscriptions : updatedDefaultSubscriptions ,
429455 EnableModelFallback : updatedSettings .EnableModelFallback ,
430456 FallbackModelAnthropic : updatedSettings .FallbackModelAnthropic ,
431457 FallbackModelOpenAI : updatedSettings .FallbackModelOpenAI ,
@@ -547,6 +573,9 @@ func diffSettings(before *service.SystemSettings, after *service.SystemSettings,
547573 if before .DefaultBalance != after .DefaultBalance {
548574 changed = append (changed , "default_balance" )
549575 }
576+ if ! equalDefaultSubscriptions (before .DefaultSubscriptions , after .DefaultSubscriptions ) {
577+ changed = append (changed , "default_subscriptions" )
578+ }
550579 if before .EnableModelFallback != after .EnableModelFallback {
551580 changed = append (changed , "enable_model_fallback" )
552581 }
@@ -586,6 +615,35 @@ func diffSettings(before *service.SystemSettings, after *service.SystemSettings,
586615 return changed
587616}
588617
618+ func normalizeDefaultSubscriptions (input []dto.DefaultSubscriptionSetting ) []dto.DefaultSubscriptionSetting {
619+ if len (input ) == 0 {
620+ return nil
621+ }
622+ normalized := make ([]dto.DefaultSubscriptionSetting , 0 , len (input ))
623+ for _ , item := range input {
624+ if item .GroupID <= 0 || item .ValidityDays <= 0 {
625+ continue
626+ }
627+ if item .ValidityDays > service .MaxValidityDays {
628+ item .ValidityDays = service .MaxValidityDays
629+ }
630+ normalized = append (normalized , item )
631+ }
632+ return normalized
633+ }
634+
635+ func equalDefaultSubscriptions (a , b []service.DefaultSubscriptionSetting ) bool {
636+ if len (a ) != len (b ) {
637+ return false
638+ }
639+ for i := range a {
640+ if a [i ].GroupID != b [i ].GroupID || a [i ].ValidityDays != b [i ].ValidityDays {
641+ return false
642+ }
643+ }
644+ return true
645+ }
646+
589647// TestSMTPRequest 测试SMTP连接请求
590648type TestSMTPRequest struct {
591649 SMTPHost string `json:"smtp_host" binding:"required"`
0 commit comments