From d5443d97c9fa6e57b39b7d65cf9b4adf15036334 Mon Sep 17 00:00:00 2001 From: jinghui <3970260761@qq.com> Date: Tue, 10 Nov 2026 02:14:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E9=A6=96=E8=AE=BF?= =?UTF-8?q?=E5=BC=BA=E5=88=B6=E8=B7=B3=E8=BD=AC/ipv6=20=E4=B8=8E=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=BB=A3=E7=90=86=E6=8B=BC=E6=8E=A5=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20(fixed105)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 Ipv6FirstVisitGate 首访强制跳转(layout.tsx 不再挂载),首页直接加载数据 - 开启 NEXT_PUBLIC_IMAGE_PROXY=/api/image-proxy,海报走站内代理 - 修复 processImageUrl 缺少 ?url= 分隔符导致的非法图片 URL - 实测: 30/30 海报加载成功, 无跳转, IPv6 推荐浮层正常显示 --- Dockerfile | 7 +- src/app/ipv6/page.tsx | 108 ++++++++++++++++++++--------- src/app/layout.tsx | 4 +- src/app/page.tsx | 2 + src/components/LineRecommender.tsx | 98 ++++++++++++++++++++++++++ src/lib/utils.ts | 5 +- src/middleware.ts | 18 +---- 7 files changed, 190 insertions(+), 52 deletions(-) create mode 100644 src/components/LineRecommender.tsx diff --git a/Dockerfile b/Dockerfile index 4073f52..286dec2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,7 +33,9 @@ COPY . . RUN find ./src -type f -name "route.ts" -print0 \ | xargs -0 sed -i "s/export const runtime = 'edge';/export const runtime = 'nodejs';/g" ENV DOCKER_ENV=true -ENV NEXT_PUBLIC_SITE_VERSION=fixed98 +# 海报走站内 /api/image-proxy(浏览器直连豆瓣图被拦导致全裂) +ENV NEXT_PUBLIC_IMAGE_PROXY=/api/image-proxy +ENV NEXT_PUBLIC_SITE_VERSION=fixed105 # For Docker builds, force dynamic rendering to read runtime environment variables. RUN sed -i "/const inter = Inter({ subsets: \['latin'] });/a export const dynamic = 'force-dynamic';" src/app/layout.tsx @@ -52,7 +54,8 @@ ENV NODE_ENV=production ENV HOSTNAME=0.0.0.0 ENV PORT=3000 ENV DOCKER_ENV=true -ENV NEXT_PUBLIC_SITE_VERSION=fixed98 +ENV NEXT_PUBLIC_IMAGE_PROXY=/api/image-proxy +ENV NEXT_PUBLIC_SITE_VERSION=fixed105 # 从构建器中复制 standalone 输出 COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ diff --git a/src/app/ipv6/page.tsx b/src/app/ipv6/page.tsx index 4e2c3af..05f7a8c 100644 --- a/src/app/ipv6/page.tsx +++ b/src/app/ipv6/page.tsx @@ -8,15 +8,21 @@ const H = { 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('checking'); + const [reason, setReason] = useState('unknown'); + const [detail, setDetail] = useState(''); const [back, setBack] = useState('/'); useEffect(() => { @@ -35,6 +41,8 @@ export default function IPv6Page() { 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 @@ -42,42 +50,50 @@ export default function IPv6Page() { } 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 probe = () => { + const probeEntry = () => { if (i >= URLS.length) { - if (!cancelled) { - try { localStorage.setItem('__v6probe', JSON.stringify({ t: Date.now(), ok: false })); } catch (e) { // ignore - // ignore - } - setState('fail'); - } + fail('entry', 'v6 入口 ' + URLS.join(' / ') + ' 全部失败:客户端没有可用的 IPv6 出口,或服务端 v6 入口被防火墙/运营商拦截。'); 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); + fetchJson(URLS[i] + Date.now(), 5000) + .then((jj) => { 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 - } + 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++; - probe(); + probeEntry(); } }) - .catch(() => { - clearTimeout(ti); + .catch((e) => { if (cancelled) return; i++; - probe(); + probeEntry(); }); }; - probe(); + probeEntry(); + return () => { cancelled = true; }; }, []); @@ -164,14 +180,35 @@ export default function IPv6Page() {

选择访问线路

{state === 'checking' && ( -

正在检测 IPv6…

+

正在检测 IPv6(客户端出口 + v6 入口)…

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

✅ 检测到你的网络支持 IPv6

+

+ 推荐选择「IPv6 线路」,观影更流畅;如遇 IPv6 无法访问再切回 IPv4。 +

+
+
+ + +
+ )} {state === 'fail' && ( @@ -181,13 +218,20 @@ export default function IPv6Page() { border: '1px solid rgba(255,180,0,.3)', borderRadius: 12, padding: '16px 20px', - maxWidth: 480, - textAlign: 'center', + maxWidth: 520, + textAlign: 'left', marginBottom: 24, }}> -

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

-

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

+ {reason === 'no-ipv6' ? '⚠️ 你的浏览器/网络没有可用的 IPv6 出口' : '⚠️ 你的网络支持 IPv6,但我们的 v6 入口不可达'} +

+

+ {detail} +

+

+ {reason === 'no-ipv6' + ? '常见原因:系统代理/VPN 只走 IPv4;路由器未分配 IPv6;浏览器禁用 IPv6。' + : '常见原因:路由器/光猫 IPv6 防火墙拦截入向 4443;运营商阻断;或服务端 IPv6 地址已变更。'}

diff --git a/src/app/layout.tsx b/src/app/layout.tsx index b56622f..1335ee6 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -8,7 +8,6 @@ import { getConfig } from '@/lib/config'; import { SiteProvider } from '../components/SiteProvider'; import { ThemeProvider } from '../components/ThemeProvider'; -import Ipv6FirstVisitGate from '../components/Ipv6FirstVisitGate'; const inter = Inter({ subsets: ['latin'] }); @@ -115,7 +114,8 @@ export default async function RootLayout({ disableTransitionOnChange > - + {/* 首访不再强制跳 /ipv6(fixed105 移除 Ipv6FirstVisitGate):首页直接加载数据, + IPv6 推荐改由首页 LineRecommender 非阻塞提示 */} {children} diff --git a/src/app/page.tsx b/src/app/page.tsx index f18a7f9..eac4818 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -20,6 +20,7 @@ import { DoubanItem } from '@/lib/types'; import CapsuleSwitch from '@/components/CapsuleSwitch'; import ContinueWatching from '@/components/ContinueWatching'; import HkDramaRow from '@/components/HkDramaRow'; +import LineRecommender from '@/components/LineRecommender'; import PageLayout from '@/components/PageLayout'; import PaginatedRow from '@/components/PaginatedRow'; import VideoCard from '@/components/VideoCard'; @@ -540,6 +541,7 @@ export default function Home() { return ( + ); } diff --git a/src/components/LineRecommender.tsx b/src/components/LineRecommender.tsx new file mode 100644 index 0000000..9283bd5 --- /dev/null +++ b/src/components/LineRecommender.tsx @@ -0,0 +1,98 @@ +'use client'; + +import { useEffect, useState } from 'react'; + +const V6 = 'https://tv6.88531.cn:4443'; +const PROBE_URL = 'https://tv6.88531.cn:4443/api/license-config?_='; + +// 首次访问的线路推荐:不阻塞数据加载,检测到支持 IPv6 时浮层提示用户可切换 +export default function LineRecommender() { + const [show, setShow] = useState(false); + + useEffect(() => { + try { + // 已记住线路 / 不在 v6 入口 / 已提示过 → 不再弹 + if (window.location.hostname === 'tv6.88531.cn') return; + if (localStorage.getItem('__v6dest')) return; + if (localStorage.getItem('__v6hint')) return; + + const cached = JSON.parse(localStorage.getItem('__v6probe') || 'null'); + if (cached && Date.now() - cached.t < 120000) { + if (cached.ok) setShow(true); + return; + } + + const c = new AbortController(); + const ti = setTimeout(() => c.abort(), 5000); + fetch(PROBE_URL + Date.now(), { mode: 'cors', signal: c.signal, cache: 'no-store', credentials: 'omit' }) + .then((r) => { clearTimeout(ti); return r.json(); }) + .then((jj) => { + const ok = !!(jj && jj.code === 200 && jj.data); + try { localStorage.setItem('__v6probe', JSON.stringify({ t: Date.now(), ok })); } catch (e) { /* ignore */ } + if (ok) setShow(true); + }) + .catch(() => { clearTimeout(ti); }); + } catch (e) { /* ignore */ } + }, []); + + if (!show) return null; + + const dismiss = (pick?: 'v6' | 'v4') => { + try { + localStorage.setItem('__v6hint', '1'); + if (pick === 'v6') { + localStorage.setItem('__v6dest', 'v6'); + document.cookie = '__v6dest=v6; path=/; max-age=31536000; samesite=lax'; + window.location.href = V6 + window.location.pathname + window.location.search; + return; + } + if (pick === 'v4') { + localStorage.setItem('__v6dest', 'v4'); + document.cookie = '__v6dest=v4; path=/; max-age=31536000; samesite=lax'; + } + } catch (e) { /* ignore */ } + setShow(false); + }; + + return ( +
+
+

+ ✅ 检测到你的网络支持 IPv6 +

+ +
+

+ 推荐切换到 IPv6 线路,观影更流畅。 +

+
+ + +
+
+ ); +} diff --git a/src/lib/utils.ts b/src/lib/utils.ts index cc5152c..e4d4c0d 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -37,7 +37,10 @@ export function processImageUrl(originalUrl: string): string { const proxyUrl = getImageProxyUrl(); if (!proxyUrl) return originalUrl; - return `${proxyUrl}${encodeURIComponent(originalUrl)}`; + // 代理地址若未自带查询参数(如 /api/image-proxy),补 ?url=,否则拼出的 URL 非法 + if (proxyUrl.includes('url=')) return `${proxyUrl}${encodeURIComponent(originalUrl)}`; + const sep = proxyUrl.includes('?') ? '&' : '?url='; + return `${proxyUrl}${sep}${encodeURIComponent(originalUrl)}`; } /** diff --git a/src/middleware.ts b/src/middleware.ts index f5d02f2..d20d556 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -49,25 +49,13 @@ 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); - } + // 首次访问不再强制跳转 /ipv6 选线路页:首页直接加载数据,线路由顶栏「IPV4/IPV6」切换 const storageType = process.env.NEXT_PUBLIC_STORAGE_TYPE || 'localstorage'; if (!process.env.AUTH_PASSWORD) { - // 如果没有设置密码,重定向到警告页面 - const warningUrl = new URL('/warning', request.url); - return NextResponse.redirect(warningUrl); + // 未配置 AUTH_PASSWORD 时直接放行,不强制访问控制 + return NextResponse.next(); } // 从cookie获取认证信息