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 ? '启用中' : '已禁用'} + + +