diff --git a/ant-design-pro/src/pages/settings/index.tsx b/ant-design-pro/src/pages/settings/index.tsx index c8c1b977..79e34e04 100644 --- a/ant-design-pro/src/pages/settings/index.tsx +++ b/ant-design-pro/src/pages/settings/index.tsx @@ -55,6 +55,8 @@ import { syncCfWorkerDomains, testEmailNotification, testTelegram, + testTelegramProxy, + type TelegramProxyTestResponse, testVerificationAi, testWebhook, triggerSystemUpdate, @@ -147,6 +149,10 @@ const SettingsPage: React.FC = () => { const [webhookTestLoading, setWebhookTestLoading] = useState(false); const [webhookTestResult, setWebhookTestResult] = useState(null); + const [telegramProxyTestLoading, setTelegramProxyTestLoading] = + useState(false); + const [telegramProxyTestResult, setTelegramProxyTestResult] = + useState(null); const settingsQuery = useQuery({ queryKey: ['settings'], @@ -520,6 +526,42 @@ const SettingsPage: React.FC = () => { } }; + const testTelegramProxyUrl = async () => { + const proxyUrl = String( + form.getFieldValue('telegram_proxy_url') || '', + ).trim(); + if (dirty) { + message.warning('请先保存当前 Telegram 配置,再测试代理连通性'); + return; + } + setTelegramProxyTestLoading(true); + setTelegramProxyTestResult(null); + try { + const result = await testTelegramProxy(proxyUrl); + setTelegramProxyTestResult(result); + if (result?.success === false) { + message.error(pickSettingsError(result, '代理连通性测试失败')); + } else if (result?.ok === false) { + message.warning(result?.message || '代理可达但 Telegram 连接异常'); + } else { + message.success(result?.message || '代理连通性测试成功'); + } + } catch (error: any) { + const payload = + error?.data || + error?.info || + error?.response?.data || { + success: false, + message: error?.message || '代理连通性测试失败', + error, + }; + setTelegramProxyTestResult(payload); + message.error(pickSettingsError(payload, '代理连通性测试失败')); + } finally { + setTelegramProxyTestLoading(false); + } + }; + const loadDeployment = async () => { setDeploymentLoading(true); try { @@ -1040,16 +1082,80 @@ const SettingsPage: React.FC = () => { style={{ width: '100%' }} /> - - - - + + + + + + + {telegramProxyTestResult && ( + + + 状态: + {telegramProxyTestResult.ok === false + ? `代理可达但 Telegram 返回异常(网络不可用/被拦截)` + : telegramProxyTestResult.success + ? '代理连通成功' + : '代理连接失败'} + + {telegramProxyTestResult.message && ( + + 服务端返回: + {telegramProxyTestResult.message} + + )} + {telegramProxyTestResult.latency_ms != null && ( + + 耗时: + {telegramProxyTestResult.latency_ms} ms + + )} + {telegramProxyTestResult.error?.code && ( + + 错误码: + {String(telegramProxyTestResult.error.code)} + + )} + + } + /> + )} ), }, diff --git a/ant-design-pro/src/services/outlook/settings.ts b/ant-design-pro/src/services/outlook/settings.ts index f208ddb8..492ca5e0 100644 --- a/ant-design-pro/src/services/outlook/settings.ts +++ b/ant-design-pro/src/services/outlook/settings.ts @@ -56,6 +56,24 @@ export async function testTelegram() { ); } +export type TelegramProxyTestResponse = { + success: boolean; + ok?: boolean; + message?: string; + message_en?: string; + latency_ms?: number; + proxy_url?: string; + error?: any; +}; + +/** 测试 Telegram 代理连通性:后端会用表单里的代理地址实际请求 api.telegram.org/getMe。 */ +export async function testTelegramProxy(proxyUrl: string) { + return outlookRequest( + '/api/settings/test-telegram-proxy', + { method: 'POST', data: { proxy_url: proxyUrl }, skipErrorHandler: true }, + ); +} + export async function testEmailNotification() { return outlookRequest<{ success: boolean; message?: string; error?: any }>( '/api/settings/email-test',