From c52a46906c6f99769d42a57e58398c2fdfc7face Mon Sep 17 00:00:00 2001 From: 3970260761 <3970260761@qq.com> Date: Mon, 2 Nov 2026 15:41:54 +0800 Subject: [PATCH] feat: migrate /ipv6 page and /live page to source; whitelist in middleware --- src/app/ipv6/page.tsx | 177 ++++++++++++++++++++++++++++++++++++++++++ src/app/live/page.tsx | 20 +++++ src/middleware.ts | 2 + 3 files changed, 199 insertions(+) create mode 100644 src/app/ipv6/page.tsx create mode 100644 src/app/live/page.tsx diff --git a/src/app/ipv6/page.tsx b/src/app/ipv6/page.tsx new file mode 100644 index 0000000..353ce0a --- /dev/null +++ b/src/app/ipv6/page.tsx @@ -0,0 +1,177 @@ +'use client'; + +import { useEffect, useState } from 'react'; + +const H = { + v4: 'https://tv.88531.cn', + v6: 'https://tv6.88531.cn:4443', +}; + +const URLS = [ + 'https://tv6.88531.cn:4443/api/license-config?_=', + 'https://tv6.88531.cn/api/license-config?_=', +]; + +type ProbeState = 'checking' | 'ok' | 'fail'; + +export default function IPv6Page() { + const [state, setState] = useState('checking'); + const [back, setBack] = useState('/'); + + useEffect(() => { + const params = new URLSearchParams(window.location.search); + setBack(params.get('back') || '/'); + }, []); + + useEffect(() => { + // If already on tv6 hostname, IPv6 is available + if (window.location.hostname === 'tv6.88531.cn') { + setState('ok'); + return; + } + // Check cache (2 min) + try { + const cached = JSON.parse(localStorage.getItem('__v6probe') || 'null'); + if (cached && Date.now() - cached.t < 120000) { + setState(cached.ok ? 'ok' : 'fail'); + return; + } + } catch (e) { // ignore + // ignore parse errors + } + + let cancelled = false; + let i = 0; + const probe = () => { + if (i >= URLS.length) { + if (!cancelled) { + try { localStorage.setItem('__v6probe', JSON.stringify({ t: Date.now(), ok: false })); } catch (e) { // ignore + // ignore + } + setState('fail'); + } + return; + } + const c = new AbortController(); + const ti = setTimeout(() => c.abort(), 5000); + fetch(URLS[i] + Date.now(), { mode: 'cors', signal: c.signal, cache: 'no-store', credentials: 'omit' }) + .then((r) => r.json()) + .then((j) => { + clearTimeout(ti); + if (cancelled) return; + if (j && j.code === 200 && j.data) { + try { localStorage.setItem('__v6probe', JSON.stringify({ t: Date.now(), ok: true })); } catch (e) { // ignore + // ignore + } + setState('ok'); + } else { + i++; + probe(); + } + }) + .catch(() => { + clearTimeout(ti); + if (cancelled) return; + i++; + probe(); + }); + }; + probe(); + return () => { cancelled = true; }; + }, []); + + const choose = (which: 'v4' | 'v6') => { + const dest = which === 'v4' ? H.v4 : H.v6; + try { localStorage.setItem('__v6dest', which); } catch (e) { // ignore + // ignore + } + window.location.href = dest + back + window.location.search + window.location.hash; + }; + + const reprobe = () => { + try { localStorage.removeItem('__v6probe'); } catch (e) { // ignore + // ignore + } + setState('checking'); + window.location.reload(); + }; + + const forceV6 = () => { + try { localStorage.setItem('__v6probe', JSON.stringify({ t: Date.now(), ok: true })); } catch (e) { // ignore + // ignore + } + try { localStorage.setItem('__v6dest', 'v6'); } catch (e) { // ignore + // ignore + } + window.location.href = H.v6 + back + window.location.search + window.location.hash; + }; + + return ( +
+

KatelyaTV

+

选择访问线路

+ + {state === 'checking' && ( +

正在检测 IPv6…

+ )} + + {state === 'ok' && ( +
+ + +
+ )} + + {state === 'fail' && ( + <> +
+

⚠️ 检测到你的网络不支持 IPv6 访问

+

+ 已隐藏 IPv6 线路。请使用 IPv4 线路访问。 +

+
+
+ + + +
+ + )} +
+ ); +} + +const btnStyle: React.CSSProperties = { + padding: '12px 28px', + borderRadius: 10, + border: '1px solid rgba(255,255,255,.15)', + background: 'rgba(255,255,255,.08)', + color: '#fff', + fontSize: 16, + cursor: 'pointer', + transition: 'background .2s', +}; + +const btnStyleSecondary: React.CSSProperties = { + ...btnStyle, + background: 'rgba(255,255,255,.04)', + fontSize: 14, +}; diff --git a/src/app/live/page.tsx b/src/app/live/page.tsx new file mode 100644 index 0000000..6a49371 --- /dev/null +++ b/src/app/live/page.tsx @@ -0,0 +1,20 @@ +'use client'; + +export default function LivePage() { + return ( +
+

港澳台电视直播

+

直播功能加载中…

+
+ ); +} diff --git a/src/middleware.ts b/src/middleware.ts index f584906..062e2ec 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -125,6 +125,8 @@ function shouldSkipAuth(pathname: string): boolean { '/icons/', '/logo.png', '/screenshot.png', + '/ipv6', + '/live', ]; return skipPaths.some((path) => pathname.startsWith(path));