option.go 18 KB

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