option.go 19 KB

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