mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-19 11:10:49 +08:00
feat(config): warn restart required when commercial mode changes
This commit is contained in:
@@ -1094,6 +1094,7 @@
|
|||||||
"gemini_api_key": "Gemini API key",
|
"gemini_api_key": "Gemini API key",
|
||||||
"codex_api_key": "Codex API key",
|
"codex_api_key": "Codex API key",
|
||||||
"claude_api_key": "Claude API key",
|
"claude_api_key": "Claude API key",
|
||||||
|
"commercial_mode_restart_required": "Commercial mode setting changed. Please restart the service for it to take effect",
|
||||||
"copy_failed": "Copy failed",
|
"copy_failed": "Copy failed",
|
||||||
"link_copied": "Link copied to clipboard"
|
"link_copied": "Link copied to clipboard"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1099,6 +1099,7 @@
|
|||||||
"gemini_api_key": "API-ключ Gemini",
|
"gemini_api_key": "API-ключ Gemini",
|
||||||
"codex_api_key": "API-ключ Codex",
|
"codex_api_key": "API-ключ Codex",
|
||||||
"claude_api_key": "API-ключ Claude",
|
"claude_api_key": "API-ключ Claude",
|
||||||
|
"commercial_mode_restart_required": "Режим коммерческого использования изменён. Перезапустите сервис, чтобы применить изменения",
|
||||||
"copy_failed": "Не удалось скопировать",
|
"copy_failed": "Не удалось скопировать",
|
||||||
"link_copied": "Ссылка скопирована в буфер обмена"
|
"link_copied": "Ссылка скопирована в буфер обмена"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1094,6 +1094,7 @@
|
|||||||
"gemini_api_key": "Gemini API密钥",
|
"gemini_api_key": "Gemini API密钥",
|
||||||
"codex_api_key": "Codex API密钥",
|
"codex_api_key": "Codex API密钥",
|
||||||
"claude_api_key": "Claude API密钥",
|
"claude_api_key": "Claude API密钥",
|
||||||
|
"commercial_mode_restart_required": "商业模式开关已变更,请重启服务后生效",
|
||||||
"copy_failed": "复制失败",
|
"copy_failed": "复制失败",
|
||||||
"link_copied": "已复制"
|
"link_copied": "已复制"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import CodeMirror, { ReactCodeMirrorRef } from '@uiw/react-codemirror';
|
|||||||
import { yaml } from '@codemirror/lang-yaml';
|
import { yaml } from '@codemirror/lang-yaml';
|
||||||
import { search, searchKeymap, highlightSelectionMatches } from '@codemirror/search';
|
import { search, searchKeymap, highlightSelectionMatches } from '@codemirror/search';
|
||||||
import { keymap } from '@codemirror/view';
|
import { keymap } from '@codemirror/view';
|
||||||
|
import { parse as parseYaml } from 'yaml';
|
||||||
import { Card } from '@/components/ui/Card';
|
import { Card } from '@/components/ui/Card';
|
||||||
import { Button } from '@/components/ui/Button';
|
import { Button } from '@/components/ui/Button';
|
||||||
import { Input } from '@/components/ui/Input';
|
import { Input } from '@/components/ui/Input';
|
||||||
@@ -17,6 +18,16 @@ import styles from './ConfigPage.module.scss';
|
|||||||
|
|
||||||
type ConfigEditorTab = 'visual' | 'source';
|
type ConfigEditorTab = 'visual' | 'source';
|
||||||
|
|
||||||
|
function readCommercialModeFromYaml(yamlContent: string): boolean {
|
||||||
|
try {
|
||||||
|
const parsed = parseYaml(yamlContent);
|
||||||
|
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return false;
|
||||||
|
return Boolean((parsed as Record<string, unknown>)['commercial-mode']);
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function ConfigPage() {
|
export function ConfigPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { showNotification } = useNotificationStore();
|
const { showNotification } = useNotificationStore();
|
||||||
@@ -78,13 +89,19 @@ export function ConfigPage() {
|
|||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
try {
|
try {
|
||||||
|
const previousCommercialMode = readCommercialModeFromYaml(content);
|
||||||
const nextContent = activeTab === 'visual' ? applyVisualChangesToYaml(content) : content;
|
const nextContent = activeTab === 'visual' ? applyVisualChangesToYaml(content) : content;
|
||||||
|
const nextCommercialMode = readCommercialModeFromYaml(nextContent);
|
||||||
|
const commercialModeChanged = previousCommercialMode !== nextCommercialMode;
|
||||||
await configFileApi.saveConfigYaml(nextContent);
|
await configFileApi.saveConfigYaml(nextContent);
|
||||||
const latestContent = await configFileApi.fetchConfigYaml();
|
const latestContent = await configFileApi.fetchConfigYaml();
|
||||||
setDirty(false);
|
setDirty(false);
|
||||||
setContent(latestContent);
|
setContent(latestContent);
|
||||||
loadVisualValuesFromYaml(latestContent);
|
loadVisualValuesFromYaml(latestContent);
|
||||||
showNotification(t('config_management.save_success'), 'success');
|
showNotification(t('config_management.save_success'), 'success');
|
||||||
|
if (commercialModeChanged) {
|
||||||
|
showNotification(t('notification.commercial_mode_restart_required'), 'warning');
|
||||||
|
}
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
const message = err instanceof Error ? err.message : '';
|
const message = err instanceof Error ? err.message : '';
|
||||||
showNotification(`${t('notification.save_failed')}: ${message}`, 'error');
|
showNotification(`${t('notification.save_failed')}: ${message}`, 'error');
|
||||||
|
|||||||
Reference in New Issue
Block a user