feat: 增强设置功能,支持当前识别的管理 IP 和白名单更新逻辑

This commit is contained in:
cita
2026-03-01 15:39:13 +08:00
parent 4d6cd683b3
commit e41b6b7993
9 changed files with 135 additions and 9 deletions
+16 -2
View File
@@ -19,6 +19,7 @@ type RuntimeSettings = {
routingWeights: RoutingWeights;
proxyTokenMasked?: string;
adminIpAllowlist?: string[];
currentAdminIp?: string;
};
const defaultWeights: RoutingWeights = {
@@ -88,6 +89,7 @@ export default function Settings() {
adminIpAllowlist: Array.isArray(runtimeInfo.adminIpAllowlist)
? runtimeInfo.adminIpAllowlist.filter((item: unknown) => typeof item === 'string')
: [],
currentAdminIp: typeof runtimeInfo.currentAdminIp === 'string' ? runtimeInfo.currentAdminIp : '',
});
setAdminIpAllowlistText(
Array.isArray(runtimeInfo.adminIpAllowlist)
@@ -176,10 +178,16 @@ export default function Settings() {
.split(/\r?\n|,/g)
.map((item) => item.trim())
.filter((item) => item.length > 0);
await api.updateRuntimeSettings({
const res = await api.updateRuntimeSettings({
adminIpAllowlist: allowlist,
});
setRuntime((prev) => ({ ...prev, adminIpAllowlist: allowlist }));
setRuntime((prev) => ({
...prev,
adminIpAllowlist: allowlist,
currentAdminIp: typeof res?.currentAdminIp === 'string'
? res.currentAdminIp
: prev.currentAdminIp,
}));
toast.success('安全设置已保存');
} catch (err: any) {
toast.error(err?.message || '保存失败');
@@ -446,6 +454,12 @@ export default function Settings() {
<div style={{ fontSize: 12, color: 'var(--color-text-muted)', marginBottom: 12 }}>
登录会话默认 12 小时自动过期。可选配置管理端 IP 白名单(每行一个 IP)。
</div>
<div style={{ fontSize: 12, color: 'var(--color-text-muted)', marginBottom: 6 }}>
{tr('当前识别到的管理端 IP(由服务端判定):')}
</div>
<code style={{ display: 'block', padding: '10px 14px', background: 'var(--color-bg)', borderRadius: 'var(--radius-sm)', fontSize: 13, fontFamily: 'var(--font-mono)', color: 'var(--color-text-secondary)', border: '1px solid var(--color-border-light)', marginBottom: 10 }}>
{runtime.currentAdminIp || tr('未知')}
</code>
<textarea
value={adminIpAllowlistText}
onChange={(e) => setAdminIpAllowlistText(e.target.value)}
@@ -84,6 +84,16 @@ describe('modelTesterSession', () => {
expect(restored?.parameterEnabled).toEqual(DEFAULT_PARAMETER_ENABLED);
});
it('defaults top_p to disabled when parameter switches are missing', () => {
const restored = parseModelTesterSession(JSON.stringify({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'hello' }],
pendingPayload: null,
}));
expect(restored?.parameterEnabled.top_p).toBe(false);
});
it('returns null for malformed or missing session payload', () => {
expect(parseModelTesterSession(null)).toBeNull();
expect(parseModelTesterSession('not-json')).toBeNull();
+1 -1
View File
@@ -96,7 +96,7 @@ export const DEFAULT_INPUTS: ModelTesterInputs = {
export const DEFAULT_PARAMETER_ENABLED: ParameterEnabled = {
temperature: true,
top_p: true,
top_p: false,
max_tokens: false,
frequency_penalty: true,
presence_penalty: true,