option.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. package model
  2. import (
  3. "one-api/common"
  4. "one-api/setting"
  5. "one-api/setting/config"
  6. "one-api/setting/operation_setting"
  7. "one-api/setting/ratio_setting"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. type Option struct {
  13. Key string `json:"key" gorm:"primaryKey"`
  14. Value string `json:"value"`
  15. }
  16. func AllOption() ([]*Option, error) {
  17. var options []*Option
  18. var err error
  19. err = DB.Find(&options).Error
  20. return options, err
  21. }
  22. func InitOptionMap() {
  23. common.OptionMapRWMutex.Lock()
  24. common.OptionMap = make(map[string]string)
  25. // 添加原有的系统配置
  26. common.OptionMap["FileUploadPermission"] = strconv.Itoa(common.FileUploadPermission)
  27. common.OptionMap["FileDownloadPermission"] = strconv.Itoa(common.FileDownloadPermission)
  28. common.OptionMap["ImageUploadPermission"] = strconv.Itoa(common.ImageUploadPermission)
  29. common.OptionMap["ImageDownloadPermission"] = strconv.Itoa(common.ImageDownloadPermission)
  30. common.OptionMap["PasswordLoginEnabled"] = strconv.FormatBool(common.PasswordLoginEnabled)
  31. common.OptionMap["PasswordRegisterEnabled"] = strconv.FormatBool(common.PasswordRegisterEnabled)
  32. common.OptionMap["EmailVerificationEnabled"] = strconv.FormatBool(common.EmailVerificationEnabled)
  33. common.OptionMap["GitHubOAuthEnabled"] = strconv.FormatBool(common.GitHubOAuthEnabled)
  34. common.OptionMap["LinuxDOOAuthEnabled"] = strconv.FormatBool(common.LinuxDOOAuthEnabled)
  35. common.OptionMap["TelegramOAuthEnabled"] = strconv.FormatBool(common.TelegramOAuthEnabled)
  36. common.OptionMap["WeChatAuthEnabled"] = strconv.FormatBool(common.WeChatAuthEnabled)
  37. common.OptionMap["TurnstileCheckEnabled"] = strconv.FormatBool(common.TurnstileCheckEnabled)
  38. common.OptionMap["RegisterEnabled"] = strconv.FormatBool(common.RegisterEnabled)
  39. common.OptionMap["AutomaticDisableChannelEnabled"] = strconv.FormatBool(common.AutomaticDisableChannelEnabled)
  40. common.OptionMap["AutomaticEnableChannelEnabled"] = strconv.FormatBool(common.AutomaticEnableChannelEnabled)
  41. common.OptionMap["LogConsumeEnabled"] = strconv.FormatBool(common.LogConsumeEnabled)
  42. common.OptionMap["LogUserInputEnabled"] = strconv.FormatBool(common.LogUserInputEnabled)
  43. common.OptionMap["DisplayInCurrencyEnabled"] = strconv.FormatBool(common.DisplayInCurrencyEnabled)
  44. common.OptionMap["DisplayTokenStatEnabled"] = strconv.FormatBool(common.DisplayTokenStatEnabled)
  45. common.OptionMap["DrawingEnabled"] = strconv.FormatBool(common.DrawingEnabled)
  46. common.OptionMap["TaskEnabled"] = strconv.FormatBool(common.TaskEnabled)
  47. common.OptionMap["DataExportEnabled"] = strconv.FormatBool(common.DataExportEnabled)
  48. common.OptionMap["ChannelDisableThreshold"] = strconv.FormatFloat(common.ChannelDisableThreshold, 'f', -1, 64)
  49. common.OptionMap["EmailDomainRestrictionEnabled"] = strconv.FormatBool(common.EmailDomainRestrictionEnabled)
  50. common.OptionMap["EmailAliasRestrictionEnabled"] = strconv.FormatBool(common.EmailAliasRestrictionEnabled)
  51. common.OptionMap["EmailDomainWhitelist"] = strings.Join(common.EmailDomainWhitelist, ",")
  52. common.OptionMap["SMTPServer"] = ""
  53. common.OptionMap["SMTPFrom"] = ""
  54. common.OptionMap["SMTPPort"] = strconv.Itoa(common.SMTPPort)
  55. common.OptionMap["SMTPAccount"] = ""
  56. common.OptionMap["SMTPToken"] = ""
  57. common.OptionMap["SMTPSSLEnabled"] = strconv.FormatBool(common.SMTPSSLEnabled)
  58. common.OptionMap["Notice"] = ""
  59. common.OptionMap["About"] = ""
  60. common.OptionMap["HomePageContent"] = ""
  61. common.OptionMap["Footer"] = common.Footer
  62. common.OptionMap["SystemName"] = common.SystemName
  63. common.OptionMap["Logo"] = common.Logo
  64. common.OptionMap["ServerAddress"] = ""
  65. common.OptionMap["WorkerUrl"] = setting.WorkerUrl
  66. common.OptionMap["WorkerValidKey"] = setting.WorkerValidKey
  67. common.OptionMap["WorkerAllowHttpImageRequestEnabled"] = strconv.FormatBool(setting.WorkerAllowHttpImageRequestEnabled)
  68. common.OptionMap["PayAddress"] = ""
  69. common.OptionMap["CustomCallbackAddress"] = ""
  70. common.OptionMap["EpayId"] = ""
  71. common.OptionMap["EpayKey"] = ""
  72. common.OptionMap["Price"] = strconv.FormatFloat(setting.Price, 'f', -1, 64)
  73. common.OptionMap["USDExchangeRate"] = strconv.FormatFloat(setting.USDExchangeRate, 'f', -1, 64)
  74. common.OptionMap["MinTopUp"] = strconv.Itoa(setting.MinTopUp)
  75. common.OptionMap["StripeMinTopUp"] = strconv.Itoa(setting.StripeMinTopUp)
  76. common.OptionMap["StripeApiSecret"] = setting.StripeApiSecret
  77. common.OptionMap["StripeWebhookSecret"] = setting.StripeWebhookSecret
  78. common.OptionMap["StripePriceId"] = setting.StripePriceId
  79. common.OptionMap["StripeUnitPrice"] = strconv.FormatFloat(setting.StripeUnitPrice, 'f', -1, 64)
  80. common.OptionMap["TopupGroupRatio"] = common.TopupGroupRatio2JSONString()
  81. common.OptionMap["Chats"] = setting.Chats2JsonString()
  82. common.OptionMap["AutoGroups"] = setting.AutoGroups2JsonString()
  83. common.OptionMap["DefaultUseAutoGroup"] = strconv.FormatBool(setting.DefaultUseAutoGroup)
  84. common.OptionMap["PayMethods"] = setting.PayMethods2JsonString()
  85. common.OptionMap["GitHubClientId"] = ""
  86. common.OptionMap["GitHubClientSecret"] = ""
  87. common.OptionMap["TelegramBotToken"] = ""
  88. common.OptionMap["TelegramBotName"] = ""
  89. common.OptionMap["WeChatServerAddress"] = ""
  90. common.OptionMap["WeChatServerToken"] = ""
  91. common.OptionMap["WeChatAccountQRCodeImageURL"] = ""
  92. common.OptionMap["TurnstileSiteKey"] = ""
  93. common.OptionMap["TurnstileSecretKey"] = ""
  94. common.OptionMap["QuotaForNewUser"] = strconv.Itoa(common.QuotaForNewUser)
  95. common.OptionMap["QuotaForInviter"] = strconv.Itoa(common.QuotaForInviter)
  96. common.OptionMap["QuotaForInvitee"] = strconv.Itoa(common.QuotaForInvitee)
  97. common.OptionMap["QuotaRemindThreshold"] = strconv.Itoa(common.QuotaRemindThreshold)
  98. common.OptionMap["PreConsumedQuota"] = strconv.Itoa(common.PreConsumedQuota)
  99. common.OptionMap["ModelRequestRateLimitCount"] = strconv.Itoa(setting.ModelRequestRateLimitCount)
  100. common.OptionMap["ModelRequestRateLimitDurationMinutes"] = strconv.Itoa(setting.ModelRequestRateLimitDurationMinutes)
  101. common.OptionMap["ModelRequestRateLimitSuccessCount"] = strconv.Itoa(setting.ModelRequestRateLimitSuccessCount)
  102. common.OptionMap["ModelRequestRateLimitGroup"] = setting.ModelRequestRateLimitGroup2JSONString()
  103. common.OptionMap["ModelRatio"] = ratio_setting.ModelRatio2JSONString()
  104. common.OptionMap["ModelPrice"] = ratio_setting.ModelPrice2JSONString()
  105. common.OptionMap["CacheRatio"] = ratio_setting.CacheRatio2JSONString()
  106. common.OptionMap["GroupRatio"] = ratio_setting.GroupRatio2JSONString()
  107. common.OptionMap["GroupGroupRatio"] = ratio_setting.GroupGroupRatio2JSONString()
  108. common.OptionMap["UserUsableGroups"] = setting.UserUsableGroups2JSONString()
  109. common.OptionMap["CompletionRatio"] = ratio_setting.CompletionRatio2JSONString()
  110. common.OptionMap["TopUpLink"] = common.TopUpLink
  111. //common.OptionMap["ChatLink"] = common.ChatLink
  112. //common.OptionMap["ChatLink2"] = common.ChatLink2
  113. common.OptionMap["QuotaPerUnit"] = strconv.FormatFloat(common.QuotaPerUnit, 'f', -1, 64)
  114. common.OptionMap["RetryTimes"] = strconv.Itoa(common.RetryTimes)
  115. common.OptionMap["DataExportInterval"] = strconv.Itoa(common.DataExportInterval)
  116. common.OptionMap["DataExportDefaultTime"] = common.DataExportDefaultTime
  117. common.OptionMap["DefaultCollapseSidebar"] = strconv.FormatBool(common.DefaultCollapseSidebar)
  118. common.OptionMap["MjNotifyEnabled"] = strconv.FormatBool(setting.MjNotifyEnabled)
  119. common.OptionMap["MjAccountFilterEnabled"] = strconv.FormatBool(setting.MjAccountFilterEnabled)
  120. common.OptionMap["MjModeClearEnabled"] = strconv.FormatBool(setting.MjModeClearEnabled)
  121. common.OptionMap["MjForwardUrlEnabled"] = strconv.FormatBool(setting.MjForwardUrlEnabled)
  122. common.OptionMap["MjActionCheckSuccessEnabled"] = strconv.FormatBool(setting.MjActionCheckSuccessEnabled)
  123. common.OptionMap["CheckSensitiveEnabled"] = strconv.FormatBool(setting.CheckSensitiveEnabled)
  124. common.OptionMap["DemoSiteEnabled"] = strconv.FormatBool(operation_setting.DemoSiteEnabled)
  125. common.OptionMap["SelfUseModeEnabled"] = strconv.FormatBool(operation_setting.SelfUseModeEnabled)
  126. common.OptionMap["ModelRequestRateLimitEnabled"] = strconv.FormatBool(setting.ModelRequestRateLimitEnabled)
  127. common.OptionMap["CheckSensitiveOnPromptEnabled"] = strconv.FormatBool(setting.CheckSensitiveOnPromptEnabled)
  128. common.OptionMap["StopOnSensitiveEnabled"] = strconv.FormatBool(setting.StopOnSensitiveEnabled)
  129. common.OptionMap["SensitiveWords"] = setting.SensitiveWordsToString()
  130. common.OptionMap["StreamCacheQueueLength"] = strconv.Itoa(setting.StreamCacheQueueLength)
  131. common.OptionMap["AutomaticDisableKeywords"] = operation_setting.AutomaticDisableKeywordsToString()
  132. common.OptionMap["ExposeRatioEnabled"] = strconv.FormatBool(ratio_setting.IsExposeRatioEnabled())
  133. // 自动添加所有注册的模型配置
  134. modelConfigs := config.GlobalConfig.ExportAllConfigs()
  135. for k, v := range modelConfigs {
  136. common.OptionMap[k] = v
  137. }
  138. common.OptionMapRWMutex.Unlock()
  139. loadOptionsFromDatabase()
  140. }
  141. func loadOptionsFromDatabase() {
  142. options, _ := AllOption()
  143. for _, option := range options {
  144. err := updateOptionMap(option.Key, option.Value)
  145. if err != nil {
  146. common.SysError("failed to update option map: " + err.Error())
  147. }
  148. }
  149. }
  150. func SyncOptions(frequency int) {
  151. for {
  152. time.Sleep(time.Duration(frequency) * time.Second)
  153. common.SysLog("syncing options from database")
  154. loadOptionsFromDatabase()
  155. }
  156. }
  157. func UpdateOption(key string, value string) error {
  158. // Save to database first
  159. option := Option{
  160. Key: key,
  161. }
  162. // https://gorm.io/docs/update.html#Save-All-Fields
  163. DB.FirstOrCreate(&option, Option{Key: key})
  164. option.Value = value
  165. // Save is a combination function.
  166. // If save value does not contain primary key, it will execute Create,
  167. // otherwise it will execute Update (with all fields).
  168. DB.Save(&option)
  169. // Update OptionMap
  170. return updateOptionMap(key, value)
  171. }
  172. func updateOptionMap(key string, value string) (err error) {
  173. common.OptionMapRWMutex.Lock()
  174. defer common.OptionMapRWMutex.Unlock()
  175. common.OptionMap[key] = value
  176. // 检查是否是模型配置 - 使用更规范的方式处理
  177. if handleConfigUpdate(key, value) {
  178. return nil // 已由配置系统处理
  179. }
  180. // 处理传统配置项...
  181. if strings.HasSuffix(key, "Permission") {
  182. intValue, _ := strconv.Atoi(value)
  183. switch key {
  184. case "FileUploadPermission":
  185. common.FileUploadPermission = intValue
  186. case "FileDownloadPermission":
  187. common.FileDownloadPermission = intValue
  188. case "ImageUploadPermission":
  189. common.ImageUploadPermission = intValue
  190. case "ImageDownloadPermission":
  191. common.ImageDownloadPermission = intValue
  192. }
  193. }
  194. if strings.HasSuffix(key, "Enabled") || key == "DefaultCollapseSidebar" || key == "DefaultUseAutoGroup" {
  195. boolValue := value == "true"
  196. switch key {
  197. case "PasswordRegisterEnabled":
  198. common.PasswordRegisterEnabled = boolValue
  199. case "PasswordLoginEnabled":
  200. common.PasswordLoginEnabled = boolValue
  201. case "EmailVerificationEnabled":
  202. common.EmailVerificationEnabled = boolValue
  203. case "GitHubOAuthEnabled":
  204. common.GitHubOAuthEnabled = boolValue
  205. case "LinuxDOOAuthEnabled":
  206. common.LinuxDOOAuthEnabled = boolValue
  207. case "WeChatAuthEnabled":
  208. common.WeChatAuthEnabled = boolValue
  209. case "TelegramOAuthEnabled":
  210. common.TelegramOAuthEnabled = boolValue
  211. case "TurnstileCheckEnabled":
  212. common.TurnstileCheckEnabled = boolValue
  213. case "RegisterEnabled":
  214. common.RegisterEnabled = boolValue
  215. case "EmailDomainRestrictionEnabled":
  216. common.EmailDomainRestrictionEnabled = boolValue
  217. case "EmailAliasRestrictionEnabled":
  218. common.EmailAliasRestrictionEnabled = boolValue
  219. case "AutomaticDisableChannelEnabled":
  220. common.AutomaticDisableChannelEnabled = boolValue
  221. case "AutomaticEnableChannelEnabled":
  222. common.AutomaticEnableChannelEnabled = boolValue
  223. case "LogConsumeEnabled":
  224. common.LogConsumeEnabled = boolValue
  225. case "LogUserInputEnabled":
  226. common.LogUserInputEnabled = boolValue
  227. case "DisplayInCurrencyEnabled":
  228. common.DisplayInCurrencyEnabled = boolValue
  229. case "DisplayTokenStatEnabled":
  230. common.DisplayTokenStatEnabled = boolValue
  231. case "DrawingEnabled":
  232. common.DrawingEnabled = boolValue
  233. case "TaskEnabled":
  234. common.TaskEnabled = boolValue
  235. case "DataExportEnabled":
  236. common.DataExportEnabled = boolValue
  237. case "DefaultCollapseSidebar":
  238. common.DefaultCollapseSidebar = boolValue
  239. case "MjNotifyEnabled":
  240. setting.MjNotifyEnabled = boolValue
  241. case "MjAccountFilterEnabled":
  242. setting.MjAccountFilterEnabled = boolValue
  243. case "MjModeClearEnabled":
  244. setting.MjModeClearEnabled = boolValue
  245. case "MjForwardUrlEnabled":
  246. setting.MjForwardUrlEnabled = boolValue
  247. case "MjActionCheckSuccessEnabled":
  248. setting.MjActionCheckSuccessEnabled = boolValue
  249. case "CheckSensitiveEnabled":
  250. setting.CheckSensitiveEnabled = boolValue
  251. case "DemoSiteEnabled":
  252. operation_setting.DemoSiteEnabled = boolValue
  253. case "SelfUseModeEnabled":
  254. operation_setting.SelfUseModeEnabled = boolValue
  255. case "CheckSensitiveOnPromptEnabled":
  256. setting.CheckSensitiveOnPromptEnabled = boolValue
  257. case "ModelRequestRateLimitEnabled":
  258. setting.ModelRequestRateLimitEnabled = boolValue
  259. case "StopOnSensitiveEnabled":
  260. setting.StopOnSensitiveEnabled = boolValue
  261. case "SMTPSSLEnabled":
  262. common.SMTPSSLEnabled = boolValue
  263. case "WorkerAllowHttpImageRequestEnabled":
  264. setting.WorkerAllowHttpImageRequestEnabled = boolValue
  265. case "DefaultUseAutoGroup":
  266. setting.DefaultUseAutoGroup = boolValue
  267. case "ExposeRatioEnabled":
  268. ratio_setting.SetExposeRatioEnabled(boolValue)
  269. }
  270. }
  271. switch key {
  272. case "EmailDomainWhitelist":
  273. common.EmailDomainWhitelist = strings.Split(value, ",")
  274. case "SMTPServer":
  275. common.SMTPServer = value
  276. case "SMTPPort":
  277. intValue, _ := strconv.Atoi(value)
  278. common.SMTPPort = intValue
  279. case "SMTPAccount":
  280. common.SMTPAccount = value
  281. case "SMTPFrom":
  282. common.SMTPFrom = value
  283. case "SMTPToken":
  284. common.SMTPToken = value
  285. case "ServerAddress":
  286. setting.ServerAddress = value
  287. case "WorkerUrl":
  288. setting.WorkerUrl = value
  289. case "WorkerValidKey":
  290. setting.WorkerValidKey = value
  291. case "PayAddress":
  292. setting.PayAddress = value
  293. case "Chats":
  294. err = setting.UpdateChatsByJsonString(value)
  295. case "AutoGroups":
  296. err = setting.UpdateAutoGroupsByJsonString(value)
  297. case "CustomCallbackAddress":
  298. setting.CustomCallbackAddress = value
  299. case "EpayId":
  300. setting.EpayId = value
  301. case "EpayKey":
  302. setting.EpayKey = value
  303. case "Price":
  304. setting.Price, _ = strconv.ParseFloat(value, 64)
  305. case "USDExchangeRate":
  306. setting.USDExchangeRate, _ = strconv.ParseFloat(value, 64)
  307. case "MinTopUp":
  308. setting.MinTopUp, _ = strconv.Atoi(value)
  309. case "StripeApiSecret":
  310. setting.StripeApiSecret = value
  311. case "StripeWebhookSecret":
  312. setting.StripeWebhookSecret = value
  313. case "StripePriceId":
  314. setting.StripePriceId = value
  315. case "StripeUnitPrice":
  316. setting.StripeUnitPrice, _ = strconv.ParseFloat(value, 64)
  317. case "StripeMinTopUp":
  318. setting.StripeMinTopUp, _ = strconv.Atoi(value)
  319. case "TopupGroupRatio":
  320. err = common.UpdateTopupGroupRatioByJSONString(value)
  321. case "GitHubClientId":
  322. common.GitHubClientId = value
  323. case "GitHubClientSecret":
  324. common.GitHubClientSecret = value
  325. case "LinuxDOClientId":
  326. common.LinuxDOClientId = value
  327. case "LinuxDOClientSecret":
  328. common.LinuxDOClientSecret = value
  329. case "Footer":
  330. common.Footer = value
  331. case "SystemName":
  332. common.SystemName = value
  333. case "Logo":
  334. common.Logo = value
  335. case "WeChatServerAddress":
  336. common.WeChatServerAddress = value
  337. case "WeChatServerToken":
  338. common.WeChatServerToken = value
  339. case "WeChatAccountQRCodeImageURL":
  340. common.WeChatAccountQRCodeImageURL = value
  341. case "TelegramBotToken":
  342. common.TelegramBotToken = value
  343. case "TelegramBotName":
  344. common.TelegramBotName = value
  345. case "TurnstileSiteKey":
  346. common.TurnstileSiteKey = value
  347. case "TurnstileSecretKey":
  348. common.TurnstileSecretKey = value
  349. case "QuotaForNewUser":
  350. common.QuotaForNewUser, _ = strconv.Atoi(value)
  351. case "QuotaForInviter":
  352. common.QuotaForInviter, _ = strconv.Atoi(value)
  353. case "QuotaForInvitee":
  354. common.QuotaForInvitee, _ = strconv.Atoi(value)
  355. case "QuotaRemindThreshold":
  356. common.QuotaRemindThreshold, _ = strconv.Atoi(value)
  357. case "PreConsumedQuota":
  358. common.PreConsumedQuota, _ = strconv.Atoi(value)
  359. case "ModelRequestRateLimitCount":
  360. setting.ModelRequestRateLimitCount, _ = strconv.Atoi(value)
  361. case "ModelRequestRateLimitDurationMinutes":
  362. setting.ModelRequestRateLimitDurationMinutes, _ = strconv.Atoi(value)
  363. case "ModelRequestRateLimitSuccessCount":
  364. setting.ModelRequestRateLimitSuccessCount, _ = strconv.Atoi(value)
  365. case "ModelRequestRateLimitGroup":
  366. err = setting.UpdateModelRequestRateLimitGroupByJSONString(value)
  367. case "RetryTimes":
  368. common.RetryTimes, _ = strconv.Atoi(value)
  369. case "DataExportInterval":
  370. common.DataExportInterval, _ = strconv.Atoi(value)
  371. case "DataExportDefaultTime":
  372. common.DataExportDefaultTime = value
  373. case "ModelRatio":
  374. err = ratio_setting.UpdateModelRatioByJSONString(value)
  375. case "GroupRatio":
  376. err = ratio_setting.UpdateGroupRatioByJSONString(value)
  377. case "GroupGroupRatio":
  378. err = ratio_setting.UpdateGroupGroupRatioByJSONString(value)
  379. case "UserUsableGroups":
  380. err = setting.UpdateUserUsableGroupsByJSONString(value)
  381. case "CompletionRatio":
  382. err = ratio_setting.UpdateCompletionRatioByJSONString(value)
  383. case "ModelPrice":
  384. err = ratio_setting.UpdateModelPriceByJSONString(value)
  385. case "CacheRatio":
  386. err = ratio_setting.UpdateCacheRatioByJSONString(value)
  387. case "TopUpLink":
  388. common.TopUpLink = value
  389. //case "ChatLink":
  390. // common.ChatLink = value
  391. //case "ChatLink2":
  392. // common.ChatLink2 = value
  393. case "ChannelDisableThreshold":
  394. common.ChannelDisableThreshold, _ = strconv.ParseFloat(value, 64)
  395. case "QuotaPerUnit":
  396. common.QuotaPerUnit, _ = strconv.ParseFloat(value, 64)
  397. case "SensitiveWords":
  398. setting.SensitiveWordsFromString(value)
  399. case "AutomaticDisableKeywords":
  400. operation_setting.AutomaticDisableKeywordsFromString(value)
  401. case "StreamCacheQueueLength":
  402. setting.StreamCacheQueueLength, _ = strconv.Atoi(value)
  403. case "PayMethods":
  404. err = setting.UpdatePayMethodsByJsonString(value)
  405. }
  406. return err
  407. }
  408. // handleConfigUpdate 处理分层配置更新,返回是否已处理
  409. func handleConfigUpdate(key, value string) bool {
  410. parts := strings.SplitN(key, ".", 2)
  411. if len(parts) != 2 {
  412. return false // 不是分层配置
  413. }
  414. configName := parts[0]
  415. configKey := parts[1]
  416. // 获取配置对象
  417. cfg := config.GlobalConfig.Get(configName)
  418. if cfg == nil {
  419. return false // 未注册的配置
  420. }
  421. // 更新配置
  422. configMap := map[string]string{
  423. configKey: value,
  424. }
  425. config.UpdateConfigFromMap(cfg, configMap)
  426. return true // 已处理
  427. }