Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions web/src/components/settings/OperationSetting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const OperationSetting = () => {
QuotaForInviter: 0,
QuotaForInvitee: 0,
'quota_setting.enable_free_model_pre_consume': true,
'oidc_quota_reset.enabled': false,
'oidc_quota_reset.amount': 500000,

/* 通用设置 */
TopUpLink: '',
Expand Down
17 changes: 14 additions & 3 deletions web/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
"使用 GitHub 继续": "Continue with GitHub",
"使用 JSON 对象格式,格式为:{\"组名\": [最多请求次数, 最多请求完成次数]}": "Use JSON object format, format: {\"group_name\": [max_requests, max_completions]}",
"使用 LinuxDO 继续": "Continue with LinuxDO",
"使用 OIDC 继续": "Continue with OIDC",
"使用 OIDC 继续": "Continue with Duke NetID",
"使用 Passkey 实现免密且更安全的登录体验": "Use Passkey for password-free and more secure login experience",
"使用 Passkey 登录": "Sign in with Passkey",
"使用 Passkey 验证": "Verify with Passkey",
Expand Down Expand Up @@ -390,6 +390,17 @@
"保存通用设置": "Save General Settings",
"保存邮箱域名白名单设置": "Save Email Domain Whitelist Settings",
"保存额度设置": "Save Quota Settings",
"OIDC 用户月度额度重置": "OIDC User Monthly Quota Reset",
"启用月度自动重置": "Enable Monthly Auto Reset",
"每月 1 日自动重置所有 OIDC 用户额度": "Auto reset all OIDC users quota on 1st of each month",
"重置额度": "Reset Quota",
"每次重置时设置的额度值": "Quota value to set on each reset",
"立即重置所有 OIDC 用户额度": "Reset All OIDC Users Quota Now",
"确认重置": "Confirm Reset",
"确定要立即重置所有 OIDC 用户的额度吗?": "Are you sure you want to reset all OIDC users quota now?",
"重置成功,已重置 {{count}} 个用户的额度为 {{quota}}": "Reset successful, {{count}} users quota reset to {{quota}}",
"重置失败": "Reset failed",
"重置失败:": "Reset failed: ",
"修复数据库一致性": "Fix database consistency",
"修改为": "Modify to",
"修改子渠道优先级": "Modify sub-channel priority",
Expand Down Expand Up @@ -776,7 +787,7 @@
"多密钥渠道操作项目组": "Multi-key channel operation project group",
"多密钥管理": "Multi-key management",
"多种充值方式,安全便捷": "Multiple recharge methods, safe and convenient",
"大模型接口网关": "LLM API Gateway",
"大模型接口网关": "Gateway",
"天": "day",
"天前": "days ago",
"失败": "Failed",
Expand Down Expand Up @@ -1858,7 +1869,7 @@
"绘图任务记录": "Drawing task records",
"绘图日志": "Drawing Logs",
"绘图设置": "Drawing settings",
"统一的": "The Unified",
"统一的": "DKU AI Service",
"统计Tokens": "Statistical Tokens",
"统计次数": "Statistical count",
"统计额度": "Statistical quota",
Expand Down
17 changes: 14 additions & 3 deletions web/src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
"使用 GitHub 继续": "使用 GitHub 继续",
"使用 JSON 对象格式,格式为:{\"组名\": [最多请求次数, 最多请求完成次数]}": "使用 JSON 对象格式,格式为:{\"组名\": [最多请求次数, 最多请求完成次数]}",
"使用 LinuxDO 继续": "使用 LinuxDO 继续",
"使用 OIDC 继续": "使用 OIDC 继续",
"使用 OIDC 继续": "使用 Duke NetID 继续",
"使用 Passkey 实现免密且更安全的登录体验": "使用 Passkey 实现免密且更安全的登录体验",
"使用 Passkey 登录": "使用 Passkey 登录",
"使用 Passkey 验证": "使用 Passkey 验证",
Expand Down Expand Up @@ -386,6 +386,17 @@
"保存通用设置": "保存通用设置",
"保存邮箱域名白名单设置": "保存邮箱域名白名单设置",
"保存额度设置": "保存额度设置",
"OIDC 用户月度额度重置": "OIDC 用户月度额度重置",
"启用月度自动重置": "启用月度自动重置",
"每月 1 日自动重置所有 OIDC 用户额度": "每月 1 日自动重置所有 OIDC 用户额度",
"重置额度": "重置额度",
"每次重置时设置的额度值": "每次重置时设置的额度值",
"立即重置所有 OIDC 用户额度": "立即重置所有 OIDC 用户额度",
"确认重置": "确认重置",
"确定要立即重置所有 OIDC 用户的额度吗?": "确定要立即重置所有 OIDC 用户的额度吗?",
"重置成功,已重置 {{count}} 个用户的额度为 {{quota}}": "重置成功,已重置 {{count}} 个用户的额度为 {{quota}}",
"重置失败": "重置失败",
"重置失败:": "重置失败:",
"修复数据库一致性": "修复数据库一致性",
"修改为": "修改为",
"修改子渠道优先级": "修改子渠道优先级",
Expand Down Expand Up @@ -769,7 +780,7 @@
"多密钥渠道操作项目组": "多密钥渠道操作项目组",
"多密钥管理": "多密钥管理",
"多种充值方式,安全便捷": "多种充值方式,安全便捷",
"大模型接口网关": "大模型接口网关",
"大模型接口网关": "接口网关",
"天": "天",
"天前": "天前",
"失败": "失败",
Expand Down Expand Up @@ -1844,7 +1855,7 @@
"绘图任务记录": "绘图任务记录",
"绘图日志": "绘图日志",
"绘图设置": "绘图设置",
"统一的": "统一的",
"统一的": "DKU AI服务",
"统计Tokens": "统计Tokens",
"统计次数": "统计次数",
"统计额度": "统计额度",
Expand Down
102 changes: 99 additions & 3 deletions web/src/pages/Setting/Operation/SettingsCreditLimit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
*/

import React, { useEffect, useState, useRef } from 'react';
import { Button, Col, Form, Row, Spin } from '@douyinfe/semi-ui';
import { Button, Col, Form, Row, Spin, Popconfirm } from '@douyinfe/semi-ui';
import { useTranslation } from 'react-i18next';
import {
compareObjects,
Expand All @@ -28,6 +28,8 @@ import {
showWarning,
} from '../../../helpers';

const SYNC_SERVICE_URL = '/api/sync';

export default function SettingsCreditLimit(props) {
const { t } = useTranslation();
const [loading, setLoading] = useState(false);
Expand All @@ -37,9 +39,12 @@ export default function SettingsCreditLimit(props) {
QuotaForInviter: '',
QuotaForInvitee: '',
'quota_setting.enable_free_model_pre_consume': true,
'oidc_quota_reset.enabled': false,
'oidc_quota_reset.amount': 500000,
});
const refForm = useRef();
const [inputsRow, setInputsRow] = useState(inputs);
const [resetting, setResetting] = useState(false);

function onSubmit() {
const updateArray = compareObjects(inputs, inputsRow);
Expand Down Expand Up @@ -76,10 +81,44 @@ export default function SettingsCreditLimit(props) {
});
}

async function handleManualReset() {
setResetting(true);
try {
const response = await fetch(`${SYNC_SERVICE_URL}/reset-oidc-quota`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
});
const data = await response.json();
if (data.success) {
showSuccess(t('重置成功,已重置 {{count}} 个用户的额度为 {{quota}}', {
count: data.affected,
quota: data.quota,
}));
} else {
showError(data.message || t('重置失败'));
}
} catch (error) {
showError(t('重置失败:') + error.message);
} finally {
setResetting(false);
}
}
Comment on lines +84 to +107

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Search for API helper definitions and auth/interceptor patterns
rg -n "API\s*=\s*|export\s+const\s+API|axios\.create" web/src --type js --type jsx

Repository: QuantumNous/new-api

Length of output: 90


🏁 Script executed:

# Search for Authorization headers and auth interceptors
rg -n "Authorization|token|interceptor|Bearer" web/src --type js --type jsx | head -30

Repository: QuantumNous/new-api

Length of output: 90


🏁 Script executed:

# Find where SYNC_SERVICE_URL is defined and used
rg -n "SYNC_SERVICE_URL" web/src --type js --type jsx

Repository: QuantumNous/new-api

Length of output: 90


🏁 Script executed:

# Check other API call patterns in the codebase
rg -n "fetch\(" web/src --type js --type jsx -A 2 | head -40

Repository: QuantumNous/new-api

Length of output: 90


🏁 Script executed:

# Look for API helper usage patterns (API.post, API.get, etc.)
rg -n "API\.(post|get|put|delete|request)" web/src --type js --type jsx | head -30

Repository: QuantumNous/new-api

Length of output: 90


🏁 Script executed:

# Search for API helper definitions (broader search)
rg -n "API\s*=\s*|export\s+const\s+API|axios\.create" web/src

Repository: QuantumNous/new-api

Length of output: 519


🏁 Script executed:

# Search for Authorization and interceptor patterns
rg -n "Authorization|interceptor|Bearer" web/src

Repository: QuantumNous/new-api

Length of output: 4987


🏁 Script executed:

# Find SYNC_SERVICE_URL definition
rg -n "SYNC_SERVICE_URL" web/src

Repository: QuantumNous/new-api

Length of output: 295


🏁 Script executed:

# Look at the actual file in question
cat -n web/src/pages/Setting/Operation/SettingsCreditLimit.jsx | head -120

Repository: QuantumNous/new-api

Length of output: 4539


🏁 Script executed:

# Find API-related imports and usage patterns
rg -n "import.*API|from.*api" web/src | head -20

Repository: QuantumNous/new-api

Length of output: 2351


🏁 Script executed:

# Examine the API helper setup and interceptors
cat -n web/src/helpers/api.js | head -100

Repository: QuantumNous/new-api

Length of output: 3373


🏁 Script executed:

# Check auth helper setup
cat -n web/src/helpers/auth.jsx | head -50

Repository: QuantumNous/new-api

Length of output: 1866


🏁 Script executed:

# Check if there's a request interceptor that adds auth headers
rg -n "interceptors\.request|setAuthHeader" web/src --context 5

Repository: QuantumNous/new-api

Length of output: 45


🏁 Script executed:

# Look at how other components use API for POST requests
rg -n "API\.post" web/src -A 3 | head -40

Repository: QuantumNous/new-api

Length of output: 2630


🏁 Script executed:

# Check if auth headers are being injected via request interceptor
cat -n web/src/helpers/api.js | tail -50

Repository: QuantumNous/new-api

Length of output: 1704


🏁 Script executed:

# Check helpers/index.js to see what's exported
cat -n web/src/helpers/index.js

Repository: QuantumNous/new-api

Length of output: 1322


🏁 Script executed:

# Look for any middleware or setup that adds auth to requests
rg -n "authHeader|Authorization" web/src/helpers --context 3

Repository: QuantumNous/new-api

Length of output: 728


🏁 Script executed:

# Check if there's a request interceptor we may have missed
rg -n "interceptors\.request" web/src/helpers/api.js -A 10

Repository: QuantumNous/new-api

Length of output: 45


🏁 Script executed:

# Verify if authHeader is actually used anywhere as a request interceptor
rg -n "authHeader\(" web/src --context 2

Repository: QuantumNous/new-api

Length of output: 854


🏁 Script executed:

# Check the complete setup of the API instance one more time - look for where auth is configured
sed -n '29,93p' web/src/helpers/api.js

Repository: QuantumNous/new-api

Length of output: 1641


Use API.post() instead of fetch() for consistency and to include necessary request headers.

The current fetch() call bypasses the API helper entirely, missing the New-API-User header that is automatically injected by the API instance. Use API.post('/api/sync/reset-oidc-quota') to align with the existing API pattern (as used on line 59 of this file with API.put()) and ensure proper request headers are included.

🤖 Prompt for AI Agents
In `@web/src/pages/Setting/Operation/SettingsCreditLimit.jsx` around lines 84 -
107, In handleManualReset replace the raw fetch call with the shared API helper
(use API.post('/api/sync/reset-oidc-quota')) so the request gets the standard
headers (including New-API-User) and consistent behavior; keep the same
success/error handling (parse response, call showSuccess/showError,
setResetting(true/false) in try/finally) and ensure you await API.post and read
the returned data shape (data.success, data.affected, data.quota, data.message)
just like the current fetch-based logic.


useEffect(() => {
const currentInputs = {};
const defaultInputs = {
QuotaForNewUser: '',
PreConsumedQuota: '',
QuotaForInviter: '',
QuotaForInvitee: '',
'quota_setting.enable_free_model_pre_consume': true,
'oidc_quota_reset.enabled': false,
'oidc_quota_reset.amount': 500000,
};
const currentInputs = { ...defaultInputs };
for (let key in props.options) {
if (Object.keys(inputs).includes(key)) {
if (Object.keys(defaultInputs).includes(key)) {
currentInputs[key] = props.options[key];
}
}
Expand Down Expand Up @@ -189,6 +228,63 @@ export default function SettingsCreditLimit(props) {
</Button>
</Row>
</Form.Section>

<Form.Section text={t('OIDC 用户月度额度重置')}>
<Row gutter={16}>
<Col xs={24} sm={12} md={8} lg={8} xl={8}>
<Form.Switch
label={t('启用月度自动重置')}
field={'oidc_quota_reset.enabled'}
extraText={t('每月 1 日自动重置所有 OIDC 用户额度')}
onChange={(value) =>
setInputs({
...inputs,
'oidc_quota_reset.enabled': value,
})
}
/>
</Col>
<Col xs={24} sm={12} md={8} lg={8} xl={8}>
<Form.InputNumber
label={t('重置额度')}
field={'oidc_quota_reset.amount'}
step={10000}
min={0}
suffix={'Token'}
extraText={t('每次重置时设置的额度值')}
placeholder={'500000'}
onChange={(value) =>
setInputs({
...inputs,
'oidc_quota_reset.amount': String(value),
})
}
/>
</Col>
</Row>
<Row gutter={16} style={{ marginTop: 16 }}>
<Col>
<Button size='default' onClick={onSubmit}>
{t('保存设置')}
</Button>
</Col>
<Col>
<Popconfirm
title={t('确认重置')}
content={t('确定要立即重置所有 OIDC 用户的额度吗?')}
onConfirm={handleManualReset}
>
<Button
size='default'
type='warning'
loading={resetting}
>
{t('立即重置所有 OIDC 用户额度')}
</Button>
</Popconfirm>
</Col>
</Row>
</Form.Section>
</Form>
</Spin>
</>
Expand Down