feat: middleware 首访未选线路时跳转 /ipv6 选择页 (v-fixed98)
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

This commit is contained in:
3970260761 committed 2026-11-09 18:06:17 +08:00
1 parent 9ffb113ca5
commit 2c8a68b064
4 files changed
+19 -2

No files matched your search

+2
View File
@@ -91,6 +91,7 @@ export default function IPv6Page() {
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');
@@ -125,6 +126,7 @@ export default function IPv6Page() {
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');
+2
View File
@@ -8,6 +8,8 @@ export default function Ipv6FirstVisitGate() {
try {
if (location.hostname !== 'tv.88531.cn') return; // 仅公网 IPv4 入口;LAN/IPv6 线路不跳转(避免循环)
if (location.pathname === '/ipv6') return;
// middleware 已记住线路(cookie)即视为已选择,不再重复弹
if (/(^|;\s*)__v6dest=/.test(document.cookie)) return;
if (localStorage.getItem('__v6dest')) return; // 已记住线路,不打扰
sessionStorage.setItem('__v6back', location.pathname + location.search + location.hash);
location.replace('/ipv6');
+13
View File
@@ -49,6 +49,19 @@ export async function middleware(request: NextRequest) {
return NextResponse.next();
}
// 首访线路选择(源码化,替代旧 patches/patch_license.js 的 V6-PROBE):
// 公网 IPv4 入口且未记住线路(cookie __v6dest 缺失)时,先跳 /ipv6 选择页再回来
const hostName = (request.headers.get('host') || request.nextUrl.hostname || '').split(':')[0];
if (
hostName === 'tv.88531.cn' &&
pathname !== '/warning' &&
!request.cookies.get('__v6dest')
) {
const u = new URL('/ipv6', request.url);
u.searchParams.set('back', pathname + request.nextUrl.search);
return NextResponse.redirect(u);
}
const storageType = process.env.NEXT_PUBLIC_STORAGE_TYPE || 'localstorage';
if (!process.env.AUTH_PASSWORD) {