From fe210c26cb2af8da5b56d614c0fe8a41e7c5e31f Mon Sep 17 00:00:00 2001 From: mtvpls Date: Mon, 16 Mar 2026 15:47:12 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E8=A7=86=E7=9B=B4=E6=92=AD=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E6=8E=A7=E5=88=B6=E6=9D=83=E4=BB=8E=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E6=94=B9=E4=B8=BA=E6=9C=8D=E5=8A=A1=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/admin/page.tsx | 71 +++++++++++++++++++++++++++++++++ src/app/api/admin/live/route.ts | 9 +++++ src/app/live/page.tsx | 9 +++-- src/components/UserMenu.tsx | 38 ------------------ src/lib/admin.types.ts | 1 + 5 files changed, 86 insertions(+), 42 deletions(-) diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx index c1d772a..e63c876 100644 --- a/src/app/admin/page.tsx +++ b/src/app/admin/page.tsx @@ -380,6 +380,7 @@ interface LiveDataSource { channelNumber?: number; disabled?: boolean; from: 'config' | 'custom'; + proxyMode?: boolean; // 代理模式开关 } // 自定义分类数据类型 @@ -10936,6 +10937,49 @@ const LiveSourceConfig = ({ }); }; + const handleToggleProxyMode = (key: string) => { + withLoading(`toggleLiveProxyMode_${key}`, async () => { + // 乐观更新本地状态 + setLiveSources((prev) => + prev.map((s) => + s.key === key ? { ...s, proxyMode: !s.proxyMode } : s + ) + ); + + try { + const response = await fetch('/api/admin/live', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + action: 'toggle_proxy_mode', + key, + }), + }); + + if (!response.ok) { + throw new Error('切换代理模式失败'); + } + + // 成功后刷新配置 + await refreshConfig(); + } catch (error) { + // 失败时回滚本地状态 + setLiveSources((prev) => + prev.map((s) => + s.key === key ? { ...s, proxyMode: !s.proxyMode } : s + ) + ); + showError( + error instanceof Error ? error.message : '切换代理模式失败', + showAlert + ); + throw error; + } + }).catch(() => { + console.error('操作失败', 'toggle_proxy_mode', key); + }); + }; + const handleDelete = (key: string) => { withLoading(`deleteLiveSource_${key}`, () => callLiveSourceApi({ action: 'delete', key }) @@ -11112,6 +11156,30 @@ const LiveSourceConfig = ({ {!liveSource.disabled ? '启用中' : '已禁用'} + + +