You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

200 rivejä
6.9 KiB

  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React, { useEffect, useState } from 'react';
  16. import { Card, Spin } from '@douyinfe/semi-ui';
  17. import { useTranslation } from 'react-i18next';
  18. import SettingsGeneral from '../../pages/Setting/Operation/SettingsGeneral';
  19. import SettingsHeaderNavModules from '../../pages/Setting/Operation/SettingsHeaderNavModules';
  20. import SettingsSidebarModulesAdmin from '../../pages/Setting/Operation/SettingsSidebarModulesAdmin';
  21. import SettingsSensitiveWords from '../../pages/Setting/Operation/SettingsSensitiveWords';
  22. import SettingsLog from '../../pages/Setting/Operation/SettingsLog';
  23. import SettingsMonitoring from '../../pages/Setting/Operation/SettingsMonitoring';
  24. import SettingsCreditLimit from '../../pages/Setting/Operation/SettingsCreditLimit';
  25. import SettingsCheckin from '../../pages/Setting/Operation/SettingsCheckin';
  26. import SettingsRegionSync from '../../pages/Setting/Operation/SettingsRegionSync';
  27. import SettingsPlayground from '../../pages/Setting/Operation/SettingsPlayground';
  28. import ModelPricing from '../../pages/Setting/Operation/ModelPricing';
  29. import { API, showError, toBoolean } from '../../helpers';
  30. const OperationSetting = () => {
  31. const { t } = useTranslation();
  32. let [inputs, setInputs] = useState({
  33. /* 额度相关 */
  34. QuotaForNewUser: 0,
  35. PreConsumedQuota: 0,
  36. QuotaForInviter: 0,
  37. QuotaForInvitee: 0,
  38. 'quota_setting.enable_free_model_pre_consume': true,
  39. /* 通用设置 */
  40. TopUpLink: '',
  41. 'general_setting.docs_link': '',
  42. QuotaPerUnit: 0,
  43. USDExchangeRate: 0,
  44. RetryTimes: 0,
  45. 'general_setting.quota_display_type': 'USD',
  46. DisplayTokenStatEnabled: false,
  47. DefaultCollapseSidebar: false,
  48. DemoSiteEnabled: false,
  49. SelfUseModeEnabled: false,
  50. /* 顶栏模块管理 */
  51. HeaderNavModules: '',
  52. /* 左侧边栏模块管理(管理员) */
  53. SidebarModulesAdmin: '',
  54. /* 敏感词设置 */
  55. CheckSensitiveEnabled: false,
  56. CheckSensitiveOnPromptEnabled: false,
  57. SensitiveWords: '',
  58. /* 日志设置 */
  59. LogConsumeEnabled: false,
  60. /* 监控设置 */
  61. ChannelDisableThreshold: 0,
  62. QuotaRemindThreshold: 0,
  63. AutomaticDisableChannelEnabled: false,
  64. AutomaticEnableChannelEnabled: false,
  65. AutomaticDisableKeywords: '',
  66. AutomaticDisableStatusCodes: '401',
  67. AutomaticRetryStatusCodes:
  68. '100-199,300-399,401-407,409-499,500-503,505-523,525-599',
  69. 'monitor_setting.auto_test_channel_enabled': false,
  70. 'monitor_setting.auto_test_channel_minutes': 10 /* 签到设置 */,
  71. 'checkin_setting.enabled': false,
  72. 'checkin_setting.min_quota': 1000,
  73. 'checkin_setting.max_quota': 10000,
  74. /* 跨区域同步设置 */
  75. 'region_sync.enabled': false,
  76. 'region_sync.region_id': '',
  77. 'region_sync.is_master': false,
  78. 'region_sync.master_endpoint': '',
  79. 'region_sync.slave_endpoints': '',
  80. 'region_sync.sync_api_key': '',
  81. 'region_sync.min_balance_threshold': 100000,
  82. 'region_sync.sync_interval_seconds': 60,
  83. 'region_sync.max_retry_count': 3,
  84. 'region_sync.sync_batch_size': 100,
  85. 'region_sync.quota_sync_interval_seconds': 300,
  86. 'region_sync.disable_cached_consume': false,
  87. /* 令牌设置 */
  88. 'token_setting.max_user_tokens': 1000,
  89. /* Playground 设置 */
  90. 'playground_setting.mutual_exclusive_params': '',
  91. });
  92. let [loading, setLoading] = useState(false);
  93. const getOptions = async () => {
  94. const res = await API.get('/api/option/');
  95. const { success, message, data } = res.data;
  96. if (success) {
  97. let apiInputs = {};
  98. data.forEach((item) => {
  99. // 只处理已知字段,避免添加未知字段
  100. if (inputs.hasOwnProperty(item.key)) {
  101. if (typeof inputs[item.key] === 'boolean') {
  102. apiInputs[item.key] = toBoolean(item.value);
  103. } else if (typeof inputs[item.key] === 'number') {
  104. apiInputs[item.key] = parseFloat(item.value) || 0;
  105. } else {
  106. apiInputs[item.key] = item.value;
  107. }
  108. }
  109. });
  110. // 合并 API 数据和初始默认值
  111. setInputs((prevInputs) => ({ ...prevInputs, ...apiInputs }));
  112. } else {
  113. showError(message);
  114. }
  115. };
  116. async function onRefresh() {
  117. try {
  118. setLoading(true);
  119. await getOptions();
  120. // showSuccess('刷新成功');
  121. } catch (error) {
  122. showError(t('刷新失败'));
  123. } finally {
  124. setLoading(false);
  125. }
  126. }
  127. useEffect(() => {
  128. onRefresh();
  129. }, []);
  130. return (
  131. <>
  132. <Spin spinning={loading} size='large'>
  133. {/* 通用设置 */}
  134. <Card style={{ marginTop: '10px' }}>
  135. <SettingsGeneral options={inputs} refresh={onRefresh} />
  136. </Card>
  137. {/* 顶栏模块管理 */}
  138. <div style={{ marginTop: '10px' }}>
  139. <SettingsHeaderNavModules options={inputs} refresh={onRefresh} />
  140. </div>
  141. {/* 左侧边栏模块管理(管理员) */}
  142. <div style={{ marginTop: '10px' }}>
  143. <SettingsSidebarModulesAdmin options={inputs} refresh={onRefresh} />
  144. </div>
  145. {/* 屏蔽词过滤设置 */}
  146. <Card style={{ marginTop: '10px' }}>
  147. <SettingsSensitiveWords options={inputs} refresh={onRefresh} />
  148. </Card>
  149. {/* 日志设置 */}
  150. <Card style={{ marginTop: '10px' }}>
  151. <SettingsLog options={inputs} refresh={onRefresh} />
  152. </Card>
  153. {/* 监控设置 */}
  154. <Card style={{ marginTop: '10px' }}>
  155. <SettingsMonitoring options={inputs} refresh={onRefresh} />
  156. </Card>
  157. {/* 额度设置 */}
  158. <Card style={{ marginTop: '10px' }}>
  159. <SettingsCreditLimit options={inputs} refresh={onRefresh} />
  160. </Card>
  161. {/* 签到设置 */}
  162. <Card style={{ marginTop: '10px' }}>
  163. <SettingsCheckin options={inputs} refresh={onRefresh} />
  164. </Card>
  165. {/* 跨区域同步设置 */}
  166. <Card style={{ marginTop: '10px' }}>
  167. <SettingsRegionSync options={inputs} refresh={onRefresh} />
  168. </Card>
  169. {/* Playground 参数互斥设置 */}
  170. <Card style={{ marginTop: '10px' }}>
  171. <SettingsPlayground options={inputs} refresh={onRefresh} />
  172. </Card>
  173. <ModelPricing />
  174. </Spin>
  175. </>
  176. );
  177. };
  178. export default OperationSetting;