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
219 lines
6.8 KiB
TypeScript
219 lines
6.8 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;
|
|
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
|
|
}
|
|
// 去掉 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
|
|
}
|
|
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…</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,
|
|
};
|