diff --git a/Dockerfile b/Dockerfile index ea26d50..52dffc7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,7 +51,7 @@ ENV NODE_ENV=production ENV HOSTNAME=0.0.0.0 ENV PORT=3000 ENV DOCKER_ENV=true -ENV NEXT_PUBLIC_SITE_VERSION=fixed70 +ENV NEXT_PUBLIC_SITE_VERSION=fixed71 # 从构建器中复制 standalone 输出 COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ diff --git a/src/app/api/tvbox/all/route.ts b/src/app/api/tvbox/all/route.ts index cff5d6b..5ac6da8 100644 --- a/src/app/api/tvbox/all/route.ts +++ b/src/app/api/tvbox/all/route.ts @@ -48,29 +48,35 @@ async function fetchClass(api: string): Promise { return []; } -// t=902(香港剧 direct)→ 源站真实 id;t=901(香港电影 agg)→ 源站电影 id + area=香港过滤 -async function resolveTop(sources: SrcCfg[], sp: URLSearchParams): Promise<{ extraArea: string }> { +// t=901-907(顶层分类)→ 每个源各自的真实 type_id(各源分类表不同,不能拿第一个源的 id 发给全源) +// t=902(香港剧):源站有“香港剧”类目则直取;没有则取电视剧类目 + area=香港 过滤,保证只出香港剧 +async function resolveTopPerSource(sources: SrcCfg[], sp: URLSearchParams): Promise<{ extraArea: string; nativeByApi: Map }> { const t = sp.get('t'); - if (!t || !/^90[1-9]$/.test(t) || sp.get('wd')) return { extraArea: '' }; - const first = sources[0]; - if (!first) return { extraArea: '' }; - const cls = await fetchClass(first.api); - const byN: Record = {}; - cls.forEach((c) => { if (c && c.type_name != null) byN[String(c.type_name).trim()] = c; }); - const fd = (...names: string[]) => { for (const n of names) if (byN[n]) return byN[n]; return null; }; - const mv = fd('电影', '电影片'); - const tv = fd('连续剧', '电视剧', '剧集'); - const vy = fd('综艺', '综艺片'); - const an = fd('动漫', '动漫片'); - const to = fd('动画片', '动画电影', '动漫电影'); - const hk = fd('香港剧', '港澳剧', '港台剧', '港剧'); - const nat: Record = { '901': mv, '902': hk, '903': mv, '904': tv, '905': vy, '906': to, '907': an }; - const hit = nat[t]; - if (hit) { - sp.set('t', String(hit.type_id)); - if (t === '901') { sp.set('area', '香港'); return { extraArea: '香港' }; } - } - return { extraArea: '' }; + const nativeByApi = new Map(); + if (!t || !/^90[1-9]$/.test(t) || sp.get('wd') || sp.get('ids')) return { extraArea: '', nativeByApi }; + const classes = await Promise.all(sources.map((s) => fetchClass(s.api))); + sources.forEach((s, i) => { + const byN: Record = {}; + (classes[i] || []).forEach((c) => { if (c && c.type_name != null) byN[String(c.type_name).trim()] = c; }); + const fd = (...names: string[]) => { for (const n of names) if (byN[n]) return byN[n]; return null; }; + const mv = fd('电影', '电影片'); + const tv = fd('连续剧', '电视剧', '剧集'); + const vy = fd('综艺', '综艺片'); + const an = fd('动漫', '动漫片'); + const to = fd('动画片', '动画电影', '动漫电影'); + const hk = fd('香港剧', '港澳剧', '港台剧', '港剧'); + let hit = null; + if (t === '901') hit = mv; + else if (t === '902') hit = hk || tv; + else if (t === '903') hit = mv; + else if (t === '904') hit = tv; + else if (t === '905') hit = vy; + else if (t === '906') hit = to; + else if (t === '907') hit = an; + if (hit) nativeByApi.set(s.api, String(hit.type_id)); + }); + if (t === '901' || t === '902') return { extraArea: '香港', nativeByApi }; + return { extraArea: '', nativeByApi }; } async function aggregateAll(sources: SrcCfg[], sp: URLSearchParams) { @@ -96,15 +102,23 @@ async function aggregateAll(sources: SrcCfg[], sp: URLSearchParams) { return out; } - let q = 'ac=videolist&pg=' + pg; - if (wd) q += '&wd=' + encodeURIComponent(wd); - // 顶层 9xx 分类先映射到源站真实 type_id(旧补丁 P() tops 逻辑) - const { extraArea } = await resolveTop(srcs, sp); - const t2 = sp.get('t'); - if (t2) q += '&t=' + encodeURIComponent(t2); - ['st', 'year', 'area', 'by'].forEach((k) => { const v = sp.get(k); if (v) q += '&' + k + '=' + encodeURIComponent(v); }); + // 顶层 9xx 分类:每个源用自己的真实 type_id 查询(旧补丁 P() tops 逻辑,源码化时按源分别映射) + const topT = sp.get('t'); + const isTop = topT && /^90[1-9]$/.test(topT) && !wd && !ids; + const { extraArea, nativeByApi } = isTop + ? await resolveTopPerSource(srcs, sp) + : { extraArea: '', nativeByApi: new Map() }; + const baseExtra = ['st', 'year', 'area', 'by'].map((k) => { const v = sp.get(k); return v ? '&' + k + '=' + encodeURIComponent(v) : ''; }).join(''); + const queries = srcs.map((s) => { + let q = 'ac=videolist&pg=' + pg; + if (wd) q += '&wd=' + encodeURIComponent(wd); + const nt = isTop ? nativeByApi.get(s.api) : topT; + if (nt) q += '&t=' + encodeURIComponent(nt); + q += baseExtra; + return q; + }); - const results = await Promise.all(srcs.map((s) => subFetch(s.api, q))); + const results = await Promise.all(srcs.map((s, i) => subFetch(s.api, queries[i]))); const seen: Record = {}; let list: any[] = []; results.forEach((d, i) => { @@ -117,10 +131,20 @@ async function aggregateAll(sources: SrcCfg[], sp: URLSearchParams) { } }); list.sort((a, b) => String(b.vod_time == null ? '' : b.vod_time).localeCompare(String(a.vod_time == null ? '' : a.vod_time))); + // 902 香港剧硬性过滤:只保留地区含“香港”的条目(兜底:无地区但名字命中的保留,避免误杀) + if (topT === '902') { + const hkPat = /港剧|粤语|TVB|邵氏|香港/i; + list = list.filter((x) => { + const area = String(x.vod_area || ''); + if (area.indexOf('香港') >= 0 || area === '香港') return true; + if (!area && hkPat.test(String(x.vod_name || ''))) return true; + return false; + }); + } const fy = sp.get('year'); const fa = sp.get('area') || extraArea; if (fy) list = list.filter((x) => String(x.vod_year || '').indexOf(fy) >= 0); - if (fa) list = list.filter((x) => String(x.vod_area || '').indexOf(fa) >= 0); + if (fa && topT !== '902') list = list.filter((x) => String(x.vod_area || '').indexOf(fa) >= 0); list = list.slice(0, 300); out.list = list; out.total = list.length; out.limit = list.length; const rep = results.find((d) => d && Array.isArray(d.class) && d.class.length); diff --git a/src/components/TopRightButtons.tsx b/src/components/TopRightButtons.tsx index 3031005..102873b 100644 --- a/src/components/TopRightButtons.tsx +++ b/src/components/TopRightButtons.tsx @@ -37,7 +37,7 @@ export default function TopRightButtons({ variant = 'bar' }: TopRightButtonsProp className='hidden lg:inline-flex shrink-0 items-center select-none rounded-lg px-2 py-1.5 text-xs font-bold tracking-wide text-purple-600 dark:text-purple-400 bg-purple-500/10 border border-purple-500/20' title='米视TV 当前版本' > - v{process.env.NEXT_PUBLIC_SITE_VERSION || 'fixed70'} + v{process.env.NEXT_PUBLIC_SITE_VERSION || 'fixed71'}