Files
katelyatv/src/app/ipv6/page.tsx
T
jinghui d5443d97c9
Docker Build & Test / build (push) Canceled after 0s
Docker Build & Test / test (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/amd64) (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/arm/v7) (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/arm64) (push) Canceled after 0s
Build & Push Docker image / merge-images (push) Canceled after 0s
Release / release (push) Canceled after 0s
Release / docker (push) Canceled after 0s
fix: 移除首访强制跳转/ipv6 与图片代理拼接修复 (fixed105)
- 删除 Ipv6FirstVisitGate 首访强制跳转(layout.tsx 不再挂载),首页直接加载数据
- 开启 NEXT_PUBLIC_IMAGE_PROXY=/api/image-proxy,海报走站内代理
- 修复 processImageUrl 缺少 ?url= 分隔符导致的非法图片 URL
- 实测: 30/30 海报加载成功, 无跳转, IPv6 推荐浮层正常显示
2026-11-10 02:14:18 +08:00

265 lines
9.3 KiB
TypeScript

'use client';
import TopRightButtons from '@/components/TopRightButtons';
import { useEffect, useState } from 'react';
const H = {
v4: 'https://tv.88531.cn',
v6: 'https://tv6.88531.cn:4443',
};
// 第一步:纯 IPv6 端点(仅 AAAA 记录),用于判断"客户端自己是否有 IPv6 出口"
const IPV6_TEST = 'https://api6.ipify.org?format=json';
// 第二步:我们自己的 IPv6 入口
const URLS = [
'https://tv6.88531.cn:4443/api/license-config?_=',
'https://tv6.88531.cn/api/license-config?_=',
];
type ProbeState = 'checking' | 'ok' | 'fail';
type FailReason = 'no-ipv6' | 'entry' | 'unknown';
export default function IPv6Page() {
const [state, setState] = useState<ProbeState>('checking');
const [reason, setReason] = useState<FailReason>('unknown');
const [detail, setDetail] = useState('');
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');
setReason(cached.reason || 'unknown');
setDetail(cached.detail || '');
return;
}
} catch (e) { // ignore
// ignore parse errors
}
let cancelled = false;
const fetchJson = (url: string, timeout = 5000) => {
const c = new AbortController();
const ti = setTimeout(() => c.abort(), timeout);
return fetch(url, { mode: 'cors', signal: c.signal, cache: 'no-store', credentials: 'omit' })
.then((r) => { clearTimeout(ti); return r.json(); })
.catch((e) => { clearTimeout(ti); throw e; });
};
const fail = (r: FailReason, d: string) => {
if (cancelled) return;
try { localStorage.setItem('__v6probe', JSON.stringify({ t: Date.now(), ok: false, reason: r, detail: d })); } catch (e) { /* ignore */ }
setReason(r);
setDetail(d);
setState('fail');
};
// 单一检测点:我们自己的 v6 入口(纯 IPv6,AAAA 记录)
// 能通 ⇒ 客户端有 IPv6 出口且 v6 入口可达;不通 ⇒ 其中一方有问题
let i = 0;
const probeEntry = () => {
if (i >= URLS.length) {
fail('entry', 'v6 入口 ' + URLS.join(' / ') + ' 全部失败:客户端没有可用的 IPv6 出口,或服务端 v6 入口被防火墙/运营商拦截。');
return;
}
fetchJson(URLS[i] + Date.now(), 5000)
.then((jj) => {
if (cancelled) return;
if (jj && jj.code === 200 && jj.data) {
try { localStorage.setItem('__v6probe', JSON.stringify({ t: Date.now(), ok: true })); } catch (e) { /* ignore */ }
setState('ok');
} else {
i++;
probeEntry();
}
})
.catch((e) => {
if (cancelled) return;
i++;
probeEntry();
});
};
probeEntry();
return () => { cancelled = true; };
}, []);
const choose = (which: 'v4' | 'v6') => {
const dest = which === 'v4' ? H.v4 : H.v6;
let targetBack = back;
try {
const s = sessionStorage.getItem('__v6back');
if (s) { targetBack = s; sessionStorage.removeItem('__v6back'); }
} catch (e) { /* ignore */ }
try { localStorage.setItem('__v6dest', which); } catch (e) { // ignore
// ignore
}
document.cookie = `__v6dest=${which}; path=/; max-age=31536000; samesite=lax`;
// 去掉 search 里的 back 参数,避免透传到目标地址
const qs = new URLSearchParams(window.location.search);
qs.delete('back');
const searchStr = qs.toString() ? '?' + qs.toString() : '';
const u = new URL(dest);
const m = /^([^?#]*)(\?[^#]*)?(#.*)?$/.exec(targetBack) || [];
u.pathname = m[1] || '/';
if (m[2]) {
const q2 = new URLSearchParams(m[2].slice(1));
q2.forEach((v, k) => { if (!u.searchParams.has(k)) u.searchParams.set(k, v); });
}
if (searchStr) {
const q3 = new URLSearchParams(searchStr.slice(1));
q3.forEach((v, k) => { if (!u.searchParams.has(k)) u.searchParams.set(k, v); });
}
if (m[3]) u.hash = m[3];
window.location.href = u.toString();
};
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
}
document.cookie = '__v6dest=v6; path=/; max-age=31536000; samesite=lax';
let targetBack = back;
try {
const s = sessionStorage.getItem('__v6back');
if (s) { targetBack = s; sessionStorage.removeItem('__v6back'); }
} catch (e) { /* ignore */ }
const u = new URL(H.v6);
const m = /^([^?#]*)(\?[^#]*)?(#.*)?$/.exec(targetBack) || [];
u.pathname = m[1] || '/';
if (m[2]) {
const q2 = new URLSearchParams(m[2].slice(1));
q2.forEach((v, k) => { if (!u.searchParams.has(k)) u.searchParams.set(k, v); });
}
const qs = new URLSearchParams(window.location.search);
qs.delete('back');
qs.forEach((v, k) => { if (!u.searchParams.has(k)) u.searchParams.set(k, v); });
if (m[3]) u.hash = m[3];
window.location.href = u.toString();
};
return (
<>
<TopRightButtons variant='float' />
<div style={{
minHeight: '100vh',
background: '#0a0a0a',
color: '#fff',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
padding: '24px',
fontFamily: 'system-ui, -apple-system, sans-serif',
}}>
<h1 style={{ fontSize: 28, marginBottom: 8 }}>KatelyaTV</h1>
<p style={{ color: 'rgba(255,255,255,.5)', marginBottom: 32 }}>选择访问线路</p>
{state === 'checking' && (
<p style={{ color: 'rgba(255,255,255,.45)' }}>正在检测 IPv6(客户端出口 + v6 入口)…</p>
)}
{state === 'ok' && (
<>
<div style={{
background: 'rgba(80,220,120,.10)',
border: '1px solid rgba(80,220,120,.3)',
borderRadius: 12,
padding: '14px 20px',
maxWidth: 520,
textAlign: 'center',
marginBottom: 24,
}}>
<p style={{ margin: 0, fontWeight: 600, color: '#7ef0a0' }}>✅ 检测到你的网络支持 IPv6</p>
<p style={{ margin: '8px 0 0', color: 'rgba(255,255,255,.6)', fontSize: 13, lineHeight: 1.5 }}>
推荐选择「IPv6 线路」,观影更流畅;如遇 IPv6 无法访问再切回 IPv4。
</p>
</div>
<div style={{ display: 'flex', gap: 16, flexWrap: 'wrap', justifyContent: 'center' }}>
<button onClick={() => choose('v6')} style={{
...btnStyle,
background: 'rgba(80,220,120,.16)',
border: '1px solid rgba(80,220,120,.55)',
fontWeight: 600,
}}>IPv6 线路(推荐)</button>
<button onClick={() => choose('v4')} style={btnStyle}>IPv4 线路</button>
</div>
</>
)}
{state === 'fail' && (
<>
<div style={{
background: 'rgba(255,180,0,.12)',
border: '1px solid rgba(255,180,0,.3)',
borderRadius: 12,
padding: '16px 20px',
maxWidth: 520,
textAlign: 'left',
marginBottom: 24,
}}>
<p style={{ margin: 0, fontWeight: 600 }}>
{reason === 'no-ipv6' ? '⚠️ 你的浏览器/网络没有可用的 IPv6 出口' : '⚠️ 你的网络支持 IPv6,但我们的 v6 入口不可达'}
</p>
<p style={{ margin: '8px 0 0', color: 'rgba(255,255,255,.6)', fontSize: 13, lineHeight: 1.5, wordBreak: 'break-word' }}>
{detail}
</p>
<p style={{ margin: '10px 0 0', color: 'rgba(255,255,255,.45)', fontSize: 12 }}>
{reason === 'no-ipv6'
? '常见原因:系统代理/VPN 只走 IPv4;路由器未分配 IPv6;浏览器禁用 IPv6。'
: '常见原因:路由器/光猫 IPv6 防火墙拦截入向 4443;运营商阻断;或服务端 IPv6 地址已变更。'}
</p>
</div>
<div style={{ display: 'flex', gap: 12, flexWrap: 'wrap', justifyContent: 'center' }}>
<button onClick={() => choose('v4')} style={btnStyle}>IPv4 线路</button>
<button onClick={reprobe} style={btnStyleSecondary}>重新检测</button>
<button onClick={forceV6} style={btnStyleSecondary}>仍要使用 IPv6</button>
</div>
</>
)}
</div>
</>
);
}
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,
};