From 8c8fc1e7f8179916c509e2b3c3eed7a42c617e77 Mon Sep 17 00:00:00 2001 From: ZeroPointSix <2.29769386e+08+ZeroPointSix@users.noreply.github.com> Date: Sat, 15 Aug 2026 04:52:17 +0000 Subject: [PATCH] =?UTF-8?q?feat(zer-659):=20=E7=B3=BB=E7=BB=9F=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=20Telegram=20=E5=A2=9E=E5=8A=A0=E3=80=8C=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=BB=A3=E7=90=86=E8=BF=9E=E9=80=9A=E6=80=A7=E3=80=8D?= =?UTF-8?q?=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs ZER-659 --- ant-design-pro/src/pages/settings/index.tsx | 124 ++++++++++++++++-- .../src/services/outlook/settings.ts | 18 +++ 2 files changed, 133 insertions(+), 9 deletions(-) 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',