182 lines
5.3 KiB
TypeScript
182 lines
5.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',
|
|
};
|
|
|
|
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<ProbeState>('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 (
|
|
<>
|
|
<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…</p>
|
|
)}
|
|
|
|
{state === 'ok' && (
|
|
<div style={{ display: 'flex', gap: 16, flexWrap: 'wrap', justifyContent: 'center' }}>
|
|
<button onClick={() => choose('v4')} style={btnStyle}>IPv4 线路</button>
|
|
<button onClick={() => choose('v6')} style={btnStyle}>IPv6 线路</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: 480,
|
|
textAlign: 'center',
|
|
marginBottom: 24,
|
|
}}>
|
|
<p style={{ margin: 0, fontWeight: 600 }}>⚠️ 检测到你的网络不支持 IPv6 访问</p>
|
|
<p style={{ margin: '8px 0 0', color: 'rgba(255,255,255,.6)', fontSize: 14 }}>
|
|
已隐藏 IPv6 线路。请使用 IPv4 线路访问。
|
|
</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,
|
|
};
|