Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bc58e33cd | ||
|
|
e086667927 | ||
|
|
a74a82b5d1 | ||
|
|
4ba6bc2339 | ||
|
|
dfc1d87a54 |
No files matched your search
@@ -2,6 +2,80 @@
|
||||
|
||||
本文档记录 KatelyaTV 项目的重要更新和功能变更。
|
||||
|
||||
## [fixed132] - 2026-11-16
|
||||
|
||||
### ✨ 全新浏览器标签页图标(favicon)
|
||||
- **重新设计网站图标**:替换原来「暗黑肖像插画缩略图」的旧 favicon(16px 下糊成一团黑、不可辨识)。
|
||||
新图标为 **深蓝渐变圆角底 + 天蓝播放三角 + 右上角星光点缀**,与站点暗色主题/天蓝主色一致,
|
||||
影视播放属性一眼可辨。
|
||||
- **小尺寸专门优化**:favicon.ico 内含 4 个尺寸——**16px 用专用优化版**(三角放大至 72%、去星光、
|
||||
加粗边线,保证标签页最小尺寸下清晰可辨为播放三角),32/48/64px 用标准版(4K 超采样渲染 + LANCZOS 缩放抗锯齿)。
|
||||
- **同步更新 PWA 图标**:`public/icons/icon-{192,256,384,512}.png` 全部换成新版设计,
|
||||
`manifest.json` 图标路径不变,浏览器安装/书签场景同步生效。
|
||||
- 图标由代码渲染生成(Pillow,脚本存 scratch),无需外部素材;16/32/48/64 四尺寸经视觉逐级核验。
|
||||
|
||||
### 验证
|
||||
- 线上 `/favicon.ico`(32038 字节)与源文件 **sha256 逐字节一致**;浏览器实际加载的 favicon hash 同为 `960d4431c7c88996…`,MATCH。
|
||||
- 首页 307→登录页正常、登录探针 401、`/icons/icon-512x512.png` 200、Redis 65 键数据完好。
|
||||
- 镜像 `katelyatv:fixed132` 双推内网 Gitea + 腾讯 TCR(`fixed132` 与 `latest` tag,双仓 digest 一致 `7648449d…`)。
|
||||
|
||||
### 🔄 保持不变
|
||||
- 站点功能、登录鉴权、观看记录(Redis)、相关推荐(fixed131)、TVBox 配置等全部无改动;
|
||||
仅替换图标资源文件。
|
||||
|
||||
## [fixed131] - 2026-11-14
|
||||
|
||||
### ✨ 重做(相关推荐:本站片源按元数据匹配,点击直达实际片源)
|
||||
- **数据源换成本站已有片源,不再走豆瓣推荐接口**:新增 `/api/related` 接口
|
||||
(`src/app/api/related/route.ts`),用当前片的 **主演 / 导演** 名称全站搜索本站资源站拿到候选池,
|
||||
再对前 12 个候选取详情,按 **主演、导演、语言、地区、类型** 五项元数据重合度打分,
|
||||
排除自己/同名/豆瓣同 ID,同名跨源去重后取前 10 返回(`score` + `reasons` 标注重合依据)。
|
||||
- **点击直达实际片源**:相关推荐卡片 `href` 改为 `/play?source=<源>&id=<条目ID>&title=...`
|
||||
(`src/components/VideoMetaExtra.tsx`),带 source+id 进播放页后 **直接取该条详情开播,
|
||||
不再做标题搜索**(`src/app/play/page.tsx` 直达模式)——彻底解决「按 title 找片对不上」的问题;
|
||||
同名源随后台补搜填充「换源」面板,不阻塞开播;该 id 失效时自动回退标题搜索。
|
||||
- **推荐规则显示在「相关推荐」旁**:标题右侧常驻说明「按主演 / 导演 / 语言 / 地区 / 类型匹配 · 本站片源直达」,
|
||||
每张卡片下方还显示年份 · 源站与重合依据(如「导演:叶伟信 · 主演:甄子丹」,悬停看全量)。
|
||||
- `/api/related` 加入 middleware 白名单(与 `/api/search`、`/api/detail` 同级),接口 10 分钟内存缓存。
|
||||
|
||||
### 验证
|
||||
- 《叶问》(甄子丹/叶伟信/香港/剧情,动作) → 10 条全部同导演同主演:叶问2/叶问4、杀破狼、龙虎门、导火线、叶问3 等,耗时 12.7s。
|
||||
- 返回条目逐条 `source+id` 直取 `/api/detail` 均返回可播 m3u8(如叶问2 → c1.rrcdnbf2.com/.../index.m3u8);`/play?source=&id=` HTTP 200。
|
||||
- 构建产物确认播放页 chunk 含「本站片源直达」文案与 `/api/related` 调用。
|
||||
|
||||
### 🔄 保持不变
|
||||
- 登录/注册鉴权、豆瓣评分/短评(仅推荐改成本站数据)、TVBox 配置(fixed128)、首页最新港剧(fixed127)、首访 IPv6 线路门。
|
||||
|
||||
### 🐛 修复(2026-11-15 追加:观看记录"消失"事故)
|
||||
- **根因**:某次 `docker run` 重建容器时漏带 `--env-file .env`,`NEXT_PUBLIC_STORAGE_TYPE=redis`
|
||||
环境变量丢失 → 站点退回 `localstorage` 模式:服务端 Redis 里的 24 个账号、全部观看记录/收藏/
|
||||
管理配置瞬间不可读(用户表现为"观看记录都没了"),且登录接口在该模式下未配置 `AUTH_PASSWORD`
|
||||
直接放行(站内登录形同虚设;外层 Basic Auth 仍在)。**数据本身未丢失**,Redis 中 13 条记录完好。
|
||||
- **修复**:① `Dockerfile` builder/runner 两阶段 `ENV NEXT_PUBLIC_STORAGE_TYPE=redis` 烤进镜像,
|
||||
彻底杜绝再丢;② 容器重建改用 `--env-file /vol3/1000/HD3/docker/katelyatv/.env` 全量环境 +
|
||||
显式 `-e NEXT_PUBLIC_STORAGE_TYPE=redis` 兜底;③ README 新增「方式二 docker run(必须带
|
||||
`--env-file`)」与部署铁则警示;④ compose `image` 对齐 `katelyatv:fixed131`。
|
||||
- **验证**:`RUNTIME_CONFIG.STORAGE_TYPE=redis`;`/api/playrecords`(合法签名 cookie)200 返回
|
||||
13 条记录;登录探针 `__probe__` 401「用户名或密码错误」(修复前为 `ok:true` 直接放行);
|
||||
登录态首页 200、`/login` 200、公网 `tv.88531.cn` 跳转链正常。
|
||||
- **注**:故障窗口内在浏览器新看的片记录留在本地 localStorage,不会自动同步回服务端。
|
||||
|
||||
### 镜像
|
||||
- katelyatv:fixed131(内网 + 腾讯云双推,latest 同步)
|
||||
|
||||
## [fixed130] - 2026-11-14
|
||||
|
||||
### ✨ 优化(相关推荐)
|
||||
- **标题旁显示推荐规则**:「相关推荐」右侧新增说明「豆瓣相似影片推荐 · 取前10」——
|
||||
数据来自豆瓣官方推荐接口 `m.douban.com/rexxar/api/v2/{tv|movie}/{豆瓣ID}/recommendations`(取前 10 条),
|
||||
让用户知道这一栏是按什么规则出的数据(`src/components/VideoMetaExtra.tsx`)。
|
||||
|
||||
### 🔄 保持不变
|
||||
- 相关推荐卡片点击直达播放页(fixed129)、登录/注册鉴权、TVBox 配置(fixed128)、首页最新港剧(fixed127)。
|
||||
|
||||
### 镜像
|
||||
- katelyatv:fixed130(内网 + 腾讯云双推,latest 同步)
|
||||
|
||||
## [fixed129] - 2026-11-14
|
||||
|
||||
### 🐛 修复(详情页「相关推荐」点了跳到搜索页)
|
||||
|
||||
@@ -35,8 +35,11 @@ RUN find ./src -type f -name "route.ts" -print0 \
|
||||
ENV DOCKER_ENV=true
|
||||
# 海报走站内 /api/image-proxy(浏览器直连豆瓣图被拦导致全裂)
|
||||
ENV NEXT_PUBLIC_IMAGE_PROXY=/api/image-proxy
|
||||
ENV NEXT_PUBLIC_SITE_VERSION=fixed129
|
||||
ENV NEXT_PUBLIC_SITE_VERSION=fixed131
|
||||
ENV NEXT_PUBLIC_ENABLE_REGISTER=true
|
||||
# 存储模式必须烤进镜像:丢失会导致服务端数据(观看记录/账号/收藏)全部不可读,
|
||||
# 且登录接口走 localstorage 分支无 AUTH_PASSWORD 直接放行(2026-11-15 事故)
|
||||
ENV NEXT_PUBLIC_STORAGE_TYPE=redis
|
||||
|
||||
# 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
|
||||
@@ -56,8 +59,11 @@ ENV HOSTNAME=0.0.0.0
|
||||
ENV PORT=3000
|
||||
ENV DOCKER_ENV=true
|
||||
ENV NEXT_PUBLIC_IMAGE_PROXY=/api/image-proxy
|
||||
ENV NEXT_PUBLIC_SITE_VERSION=fixed129
|
||||
ENV NEXT_PUBLIC_SITE_VERSION=fixed131
|
||||
ENV NEXT_PUBLIC_ENABLE_REGISTER=true
|
||||
# 存储模式必须烤进镜像:丢失会导致服务端数据(观看记录/账号/收藏)全部不可读,
|
||||
# 且登录接口走 localstorage 分支无 AUTH_PASSWORD 直接放行(2026-11-15 事故)
|
||||
ENV NEXT_PUBLIC_STORAGE_TYPE=redis
|
||||
|
||||
# 从构建器中复制 standalone 输出
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
|
||||
@@ -133,6 +133,25 @@ cp .env.redis.example .env
|
||||
docker compose -f docker-compose.redis.yml up -d
|
||||
```
|
||||
|
||||
#### ⚠️ `docker run` + Redis 模式(生产部署方式,必须带 `--env-file`)
|
||||
|
||||
```bash
|
||||
docker run -d --name katelyatv \
|
||||
--network katelyatv_katelyatv-network \
|
||||
-p 3030:3000 \
|
||||
--restart always \
|
||||
--env-file .env \
|
||||
-e NEXT_PUBLIC_STORAGE_TYPE=redis \
|
||||
--add-host host.docker.internal:host-gateway \
|
||||
gitea.88531.cn/jinghui/katelyatv:latest
|
||||
```
|
||||
|
||||
> **部署铁则**:`NEXT_PUBLIC_STORAGE_TYPE=redis` 决定观看记录/账号/收藏/管理配置读哪套存储。
|
||||
> 重建容器时漏带 `--env-file` 或漏掉该变量,站点会退回 `localstorage` 模式——服务端全部账号与
|
||||
> 观看记录瞬间"不可读"(数据未丢但在页面上表现为全部消失),且登录接口会绕过密码校验直接放行。
|
||||
> 2026-11-15 生产事故即由此引起。自 fixed131 起该变量已烤进镜像(Dockerfile ENV),
|
||||
> `docker run` 仍建议显式带 `--env-file .env` 兜底。
|
||||
|
||||
### 方式二:Docker Compose部署
|
||||
|
||||
上面「Docker + Redis」用到的 `docker-compose.redis.yml` 完整内容(与仓库文件一致,含全部 ports / volumes / environment):
|
||||
@@ -228,6 +247,9 @@ docker compose -f docker-compose.redis.yml down
|
||||
|
||||
## 📋 更新日志
|
||||
|
||||
- **v-fixed131**:相关推荐重做——数据改为**本站已有片源**,新增 `/api/related` 按 **主演/导演/语言/地区/类型** 五项元数据匹配打分(豆瓣推荐接口不再用于推荐);卡片点击带 `source+id` **直达实际片源开播**(播放页直达模式不再按标题搜索,杜绝片源对不上);「相关推荐」标题旁常驻显示匹配规则「按主演 / 导演 / 语言 / 地区 / 类型匹配 · 本站片源直达」,卡片下标注重合依据
|
||||
- **v-fixed130**:详情页「相关推荐」标题旁显示推荐规则说明「豆瓣相似影片推荐 · 取前10」(数据来自豆瓣官方推荐接口,取前 10 条相似影片)
|
||||
|
||||
- **v-fixed129**:详情页「相关推荐」点击改为直接打开影片详情并播放(`/play?title=`,原为跳搜索页 `/search?q=`);播放页标题匹配加兜底(精确匹配不到时放宽到双向包含,避免点进去报「未找到匹配结果」)
|
||||
|
||||
- **v-fixed128**:恢复 TVBox 旧版配置结构(「全部资源」站点 + 逐站代理 `/api/tvbox/<key>` + TOP7 分类视图,源码化时丢失);新增 `/api/tvbox/[site]` 逐站代理(9xx 分类→该源真实分类 id、逐子分类聚合、AI短剧搜索、筛选兜底);修复裸 `/api/tvbox` 的 9xx 分类全部 0 条、`wd` 搜索返回成配置 JSON、配置页 Base64 格式实际返回 JSON;配置响应改 no-store,88531 域名强制 https
|
||||
|
||||
|
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 162 KiB After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 296 KiB After Width: | Height: | Size: 86 KiB |
@@ -0,0 +1,268 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { getAvailableApiSites, getCacheTime, type ApiSite } from '@/lib/config';
|
||||
import { addCorsHeaders, handleOptionsRequest } from '@/lib/cors';
|
||||
import { searchFromApi, getDetailFromApi } from '@/lib/downstream';
|
||||
import type { SearchResult } from '@/lib/types';
|
||||
|
||||
export const runtime = 'edge';
|
||||
|
||||
// 处理OPTIONS预检请求
|
||||
export async function OPTIONS() {
|
||||
return handleOptionsRequest();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 相关推荐:只在本站已有片源里找,按「主演 / 导演 / 语言 / 地区 / 类型」匹配,
|
||||
// 返回可直接播放的 source+id(点击进 /play?source=&id= 直达,不走标题搜索)。
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
interface RelatedItem {
|
||||
source: string;
|
||||
source_name: string;
|
||||
id: string;
|
||||
title: string;
|
||||
poster: string;
|
||||
year: string;
|
||||
score: number;
|
||||
reasons: string[];
|
||||
}
|
||||
|
||||
// edge 实例内的短 TTL 缓存,避免同一部片反复全站搜索
|
||||
const cache = new Map<string, { ts: number; items: RelatedItem[] }>();
|
||||
const CACHE_TTL = 10 * 60 * 1000;
|
||||
|
||||
// 拆分人名/地区/语言/类型串(、,,/;| 和空白分隔)
|
||||
function splitNames(raw: string, max: number): string[] {
|
||||
if (!raw) return [];
|
||||
const parts = raw
|
||||
.split(/[、,,/;;|]+|\s+/)
|
||||
.map((x) => x.trim())
|
||||
.filter((x) => x.length >= 2);
|
||||
const seen = new Set<string>();
|
||||
const out: string[] = [];
|
||||
for (const p of parts) {
|
||||
if (!seen.has(p)) {
|
||||
seen.add(p);
|
||||
out.push(p);
|
||||
}
|
||||
if (out.length >= max) break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function normTitle(x: string): string {
|
||||
return x
|
||||
.replace(/[\s·::\-—\[\]【]()()、\/]/g, '')
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
// 双向包含式重叠("中国香港" 与 "香港" 互认)
|
||||
function overlap(self: string[], cand: string[]): string[] {
|
||||
return self.filter(
|
||||
(a) => a.length >= 2 && cand.some((b) => b.includes(a) || a.includes(b))
|
||||
);
|
||||
}
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const title = searchParams.get('title') || '';
|
||||
const actor = searchParams.get('actor') || '';
|
||||
const director = searchParams.get('director') || '';
|
||||
const area = searchParams.get('area') || '';
|
||||
const lang = searchParams.get('lang') || '';
|
||||
const genre = searchParams.get('genre') || '';
|
||||
const isTvRaw = searchParams.get('isTv'); // '1' | '0' | null
|
||||
const doubanId = searchParams.get('doubanId') || '';
|
||||
const selfSource = searchParams.get('selfSource') || '';
|
||||
const selfId = searchParams.get('selfId') || '';
|
||||
|
||||
const respond = async (items: RelatedItem[]) => {
|
||||
const cacheTime = await getCacheTime();
|
||||
const response = NextResponse.json(
|
||||
{ items },
|
||||
{
|
||||
headers: {
|
||||
'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`,
|
||||
'CDN-Cache-Control': `public, s-maxage=${cacheTime}`,
|
||||
'Vercel-CDN-Cache-Control': `public, s-maxage=${cacheTime}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
return addCorsHeaders(response);
|
||||
};
|
||||
|
||||
const dirs = splitNames(director, 2);
|
||||
const acts = splitNames(actor, 3);
|
||||
// 没有主演/导演就没有匹配依据 → 不出相关推荐
|
||||
if (!title || (dirs.length === 0 && acts.length === 0)) {
|
||||
return respond([]);
|
||||
}
|
||||
|
||||
const cacheKey = [
|
||||
title, actor, director, area, lang, genre, isTvRaw, doubanId, selfSource, selfId,
|
||||
].join('|');
|
||||
const hit = cache.get(cacheKey);
|
||||
if (hit && Date.now() - hit.ts < CACHE_TTL) {
|
||||
return respond(hit.items);
|
||||
}
|
||||
|
||||
try {
|
||||
const sites = await getAvailableApiSites(true); // 与搜索一致:过滤成人源
|
||||
if (!sites || sites.length === 0) return respond([]);
|
||||
|
||||
// 1) 按 导演名/演员名 全站搜索,得到「本站已有」的候选池(带来源强度)
|
||||
const keywords: { kw: string; dir: boolean }[] = [
|
||||
...dirs.map((k) => ({ kw: k, dir: true })),
|
||||
...acts.map((k) => ({ kw: k, dir: false })),
|
||||
];
|
||||
const prov = new Map<
|
||||
string,
|
||||
{ dir: number; act: number; sample: SearchResult }
|
||||
>();
|
||||
await Promise.all(
|
||||
keywords.map(async ({ kw, dir }) => {
|
||||
const batches = await Promise.all(
|
||||
sites.map((site) =>
|
||||
searchFromApi(site, kw).catch(() => [] as SearchResult[])
|
||||
)
|
||||
);
|
||||
for (const r of batches.flat()) {
|
||||
if (!r || !r.id || !r.source) continue;
|
||||
const key = `${r.source}:${r.id}`;
|
||||
const cur = prov.get(key) || { dir: 0, act: 0, sample: r };
|
||||
if (dir) cur.dir += 1;
|
||||
else cur.act += 1;
|
||||
if (!cur.sample.episodes?.length && r.episodes?.length) {
|
||||
cur.sample = r;
|
||||
}
|
||||
prov.set(key, cur);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
const selfTitle = normTitle(title);
|
||||
const selfKey = selfSource && selfId ? `${selfSource}:${selfId}` : '';
|
||||
const doubanNum = parseInt(doubanId, 10);
|
||||
|
||||
// 2) 初筛:必须可播放、不是本条目、不是同名
|
||||
const pool: { r: SearchResult; dir: number; act: number }[] = [];
|
||||
prov.forEach((v, key) => {
|
||||
const r = v.sample;
|
||||
if (key === selfKey) return;
|
||||
if (!r.episodes || r.episodes.length === 0) return;
|
||||
if (selfTitle && normTitle(r.title) === selfTitle) return;
|
||||
if (doubanNum && r.douban_id === doubanNum) return;
|
||||
pool.push({ r, dir: v.dir, act: v.act });
|
||||
});
|
||||
if (pool.length === 0) return respond([]);
|
||||
|
||||
// 3) 按来源强度排序,取前 12 补全元数据(主演/导演/地区/语言 只在详情里有)
|
||||
pool.sort((a, b) => b.dir * 2 + b.act - (a.dir * 2 + a.act));
|
||||
const top = pool.slice(0, 12);
|
||||
const siteMap = new Map<string, ApiSite>(
|
||||
sites.map((s) => [s.key, s] as [string, ApiSite])
|
||||
);
|
||||
const enriched = await Promise.all(
|
||||
top.map(async (c) => {
|
||||
const site = siteMap.get(c.r.source);
|
||||
if (!site) return { ...c, detail: null as SearchResult | null };
|
||||
try {
|
||||
const d = await getDetailFromApi(site, c.r.id);
|
||||
return { ...c, detail: d || null };
|
||||
} catch {
|
||||
return { ...c, detail: null };
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
// 4) 打分:主演/导演/地区/语言/类型 越多重合分越高
|
||||
const selfActs = splitNames(actor, 12);
|
||||
const selfDirs = splitNames(director, 6);
|
||||
const selfArea = splitNames(area, 4);
|
||||
const selfLang = splitNames(lang, 4);
|
||||
const selfGenre = splitNames(genre, 8);
|
||||
const isTv = isTvRaw === '1' || isTvRaw === '0' ? isTvRaw === '1' : null;
|
||||
|
||||
const items: RelatedItem[] = [];
|
||||
const seenTitles = new Set<string>();
|
||||
|
||||
for (const c of enriched) {
|
||||
const meta = c.detail || c.r;
|
||||
const candActs = splitNames(meta.actor || c.r.actor || '', 12);
|
||||
const candDirs = splitNames(meta.director || c.r.director || '', 8);
|
||||
const candArea = splitNames(meta.area || '', 4);
|
||||
const candLang = splitNames(meta.lang || '', 4);
|
||||
const candGenre = splitNames(meta.class || c.r.class || '', 8);
|
||||
|
||||
const sharedActor = overlap(selfActs, candActs);
|
||||
const sharedDir = overlap(selfDirs, candDirs);
|
||||
const areaHit = overlap(selfArea, candArea);
|
||||
const langHit = overlap(selfLang, candLang);
|
||||
const genreHit = overlap(selfGenre, candGenre);
|
||||
|
||||
const hasMeta =
|
||||
candActs.length + candDirs.length + candArea.length + candLang.length > 0;
|
||||
const kindHit =
|
||||
isTv === null
|
||||
? 0
|
||||
: (isTv && c.r.episodes.length > 1) ||
|
||||
(!isTv && c.r.episodes.length <= 1)
|
||||
? 1
|
||||
: 0;
|
||||
|
||||
const score =
|
||||
sharedDir.length * 5 +
|
||||
Math.min(sharedActor.length, 3) * 3 +
|
||||
Math.min(areaHit.length, 2) * 2 +
|
||||
Math.min(langHit.length, 2) * 2 +
|
||||
Math.min(genreHit.length, 3) +
|
||||
Math.min(c.dir, 2) * 2 +
|
||||
Math.min(c.act, 3) +
|
||||
(isTv === null ? 0 : kindHit * 2);
|
||||
|
||||
// 证据:有任一元数据重合,或该候选本来就是按导演/演员名搜出来的
|
||||
const evidence = hasMeta
|
||||
? sharedDir.length > 0 ||
|
||||
sharedActor.length > 0 ||
|
||||
areaHit.length > 0 ||
|
||||
langHit.length > 0 ||
|
||||
genreHit.length > 0 ||
|
||||
c.dir > 0
|
||||
: c.dir > 0 || c.act > 0;
|
||||
if (!evidence || score < 3) continue;
|
||||
|
||||
const reasons: string[] = [];
|
||||
if (sharedDir.length) reasons.push(`导演:${sharedDir[0]}`);
|
||||
sharedActor.slice(0, 2).forEach((a) => reasons.push(`主演:${a}`));
|
||||
if (areaHit.length) reasons.push(`地区:${areaHit[0]}`);
|
||||
if (langHit.length) reasons.push(`语言:${langHit[0]}`);
|
||||
if (genreHit.length) reasons.push(`类型:${genreHit.slice(0, 2).join('/')}`);
|
||||
|
||||
const nt = normTitle(c.r.title);
|
||||
if (seenTitles.has(nt)) continue; // 同名去重(跨源只留分数最高的一条)
|
||||
seenTitles.add(nt);
|
||||
|
||||
items.push({
|
||||
source: c.r.source,
|
||||
source_name: c.r.source_name || '',
|
||||
id: c.r.id,
|
||||
title: c.r.title,
|
||||
poster: c.r.poster || '',
|
||||
year: c.r.year || '',
|
||||
score,
|
||||
reasons: reasons.slice(0, 4),
|
||||
});
|
||||
}
|
||||
|
||||
items.sort((a, b) => b.score - a.score);
|
||||
const finalItems = items.slice(0, 10);
|
||||
|
||||
if (cache.size > 100) cache.clear();
|
||||
cache.set(cacheKey, { ts: Date.now(), items: finalItems });
|
||||
|
||||
return respond(finalItems);
|
||||
} catch {
|
||||
return respond([]);
|
||||
}
|
||||
}
|
||||
@@ -580,7 +580,27 @@ function PlayPageClient() {
|
||||
: '🔍 正在搜索播放源...'
|
||||
);
|
||||
|
||||
let sourcesInfo = await fetchSourcesData(searchTitle || videoTitle);
|
||||
// 直达模式:带 source+id 且无搜索词、无优选要求 → 直接取该条详情开播,
|
||||
// 不做标题搜索(按标题找片容易对错片);同名源随后台补搜,供「换源」面板使用
|
||||
const directMode =
|
||||
!!currentSource && !!currentId && !searchTitle && !needPrefer;
|
||||
let directSucceeded = false;
|
||||
let sourcesInfo: SearchResult[] = [];
|
||||
if (directMode) {
|
||||
const direct = await fetchSourceDetail(
|
||||
currentSource as string,
|
||||
currentId as string
|
||||
);
|
||||
if (direct.length) {
|
||||
sourcesInfo = direct;
|
||||
directSucceeded = true;
|
||||
} else {
|
||||
// 该 source+id 已失效 → 回退标题搜索
|
||||
sourcesInfo = await fetchSourcesData(searchTitle || videoTitle);
|
||||
}
|
||||
} else {
|
||||
sourcesInfo = await fetchSourcesData(searchTitle || videoTitle);
|
||||
}
|
||||
if (
|
||||
currentSource &&
|
||||
currentId &&
|
||||
@@ -644,6 +664,26 @@ function PlayPageClient() {
|
||||
newUrl.searchParams.delete('prefer');
|
||||
window.history.replaceState({}, '', newUrl.toString());
|
||||
|
||||
// 直达模式:后台补搜同名源填充「换源」面板(不阻塞开播,不做标题匹配)
|
||||
if (directSucceeded && videoTitleRef.current) {
|
||||
const directItem = sourcesInfo[0];
|
||||
fetchSourcesData(videoTitleRef.current)
|
||||
.then((rest) => {
|
||||
setAvailableSources((prev) => {
|
||||
const list = prev.length ? prev : rest;
|
||||
const seen = new Set(list.map((x) => `${x.source}:${x.id}`));
|
||||
const extras = rest.filter((x) => !seen.has(`${x.source}:${x.id}`));
|
||||
const hasDirect = list.some(
|
||||
(x) => x.source === directItem.source && x.id === directItem.id
|
||||
);
|
||||
return hasDirect
|
||||
? [...list, ...extras]
|
||||
: [directItem, ...list, ...extras];
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
setLoadingStage('ready');
|
||||
setLoadingMessage('✨ 准备就绪,即将开始播放...');
|
||||
|
||||
@@ -1747,7 +1787,11 @@ function PlayPageClient() {
|
||||
doubanId={detail.douban_id}
|
||||
area={detail.area}
|
||||
lang={detail.lang}
|
||||
genre={detail.class}
|
||||
isTv={(detail.episodes?.length || 0) > 1}
|
||||
desc={detail.desc}
|
||||
selfSource={currentSource}
|
||||
selfId={currentId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -24,8 +24,11 @@ export default function VideoMetaExtra({
|
||||
doubanId,
|
||||
area,
|
||||
lang,
|
||||
genre,
|
||||
isTv,
|
||||
desc,
|
||||
selfSource,
|
||||
selfId,
|
||||
}: {
|
||||
title: string;
|
||||
actor?: string;
|
||||
@@ -36,13 +39,18 @@ export default function VideoMetaExtra({
|
||||
doubanId?: number;
|
||||
area?: string;
|
||||
lang?: string;
|
||||
genre?: string;
|
||||
isTv?: boolean;
|
||||
desc?: string;
|
||||
/** 当前条目所属源与 id,用于相关推荐排除自己 */
|
||||
selfSource?: string;
|
||||
selfId?: string;
|
||||
}) {
|
||||
const [comments, setComments] = useState<DoubanComment[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [dbDetail, setDbDetail] = useState<any>(null);
|
||||
const [related, setRelated] = useState<any[]>([]);
|
||||
const [relatedLoading, setRelatedLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!doubanId) return;
|
||||
@@ -64,18 +72,47 @@ export default function VideoMetaExtra({
|
||||
if (alive && d?.code === 1) setDbDetail(d);
|
||||
})
|
||||
.catch(() => {});
|
||||
// 相关推荐
|
||||
fetch(`/api/douban-related?id=${encodeURIComponent(String(doubanId))}&type=${isTv ? 'tv' : 'movie'}`)
|
||||
.then((r) => r.json())
|
||||
.then((d) => {
|
||||
if (alive && d?.code === 1) setRelated(d.list || []);
|
||||
})
|
||||
.catch(() => {});
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [doubanId]);
|
||||
|
||||
// 相关推荐:本站片源,按 主演/导演/语言/地区/类型 匹配(不走豆瓣推荐接口)
|
||||
useEffect(() => {
|
||||
if (!title || (!actor && !director)) {
|
||||
setRelated([]);
|
||||
return;
|
||||
}
|
||||
let alive = true;
|
||||
setRelatedLoading(true);
|
||||
const params = new URLSearchParams({
|
||||
title,
|
||||
actor: actor || '',
|
||||
director: director || '',
|
||||
area: area || '',
|
||||
lang: lang || '',
|
||||
genre: genre || '',
|
||||
doubanId: String(doubanId || ''),
|
||||
selfSource: selfSource || '',
|
||||
selfId: selfId || '',
|
||||
});
|
||||
if (isTv !== undefined) params.set('isTv', isTv ? '1' : '0');
|
||||
fetch(`/api/related?${params.toString()}`)
|
||||
.then((r) => r.json())
|
||||
.then((d) => {
|
||||
if (alive) setRelated(Array.isArray(d?.items) ? d.items : []);
|
||||
})
|
||||
.catch(() => {
|
||||
if (alive) setRelated([]);
|
||||
})
|
||||
.finally(() => {
|
||||
if (alive) setRelatedLoading(false);
|
||||
});
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [title, actor, director, area, lang, genre, isTv, doubanId, selfSource, selfId]);
|
||||
|
||||
const actors = (actor || (dbDetail?.actors || []).join(','))
|
||||
.split(/[,,、\/|]/)
|
||||
.map((s: string) => s.trim())
|
||||
@@ -208,32 +245,60 @@ export default function VideoMetaExtra({
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
{related.length > 0 && (
|
||||
{/* 相关推荐:本站片源按元数据匹配,点击直达该条片源 */}
|
||||
{(related.length > 0 || relatedLoading) && (
|
||||
<div className='mt-4'>
|
||||
<div className='text-sm font-semibold mb-2 opacity-80'>相关推荐</div>
|
||||
<div className='grid grid-cols-5 gap-3'>
|
||||
{related.map((r: any) => (
|
||||
<a
|
||||
key={r.id}
|
||||
href={`/play?title=${encodeURIComponent(r.title)}`}
|
||||
target='_self'
|
||||
rel='noreferrer'
|
||||
className='group block'
|
||||
>
|
||||
{r.poster ? (
|
||||
<img
|
||||
src={`/api/image-proxy?url=${encodeURIComponent(r.poster)}`}
|
||||
alt={r.title}
|
||||
className='w-full aspect-[2/3] object-cover rounded-md mb-1'
|
||||
/>
|
||||
) : null}
|
||||
<div className='text-xs truncate group-hover:text-blue-500'>{r.title}</div>
|
||||
{r.rating > 0 && (
|
||||
<div className='text-xs text-amber-500'>{r.rating.toFixed(1)}</div>
|
||||
)}
|
||||
</a>
|
||||
))}
|
||||
<div className='flex items-baseline gap-2 flex-wrap text-sm font-semibold mb-2 opacity-80'>
|
||||
<span>相关推荐</span>
|
||||
<span className='text-[11px] font-normal opacity-60'>
|
||||
按主演 / 导演 / 语言 / 地区 / 类型匹配 · 本站片源直达
|
||||
</span>
|
||||
</div>
|
||||
{relatedLoading && related.length === 0 && (
|
||||
<div className='grid grid-cols-5 gap-3'>
|
||||
{[0, 1, 2, 3, 4].map((i) => (
|
||||
<div
|
||||
key={i}
|
||||
className='animate-pulse aspect-[2/3] rounded-md bg-gray-200/70 dark:bg-gray-700/50'
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{related.length > 0 && (
|
||||
<div className='grid grid-cols-5 gap-3'>
|
||||
{related.map((r: any) => (
|
||||
<a
|
||||
key={`${r.source}-${r.id}`}
|
||||
href={`/play?source=${encodeURIComponent(r.source)}&id=${encodeURIComponent(r.id)}&title=${encodeURIComponent(r.title)}${r.year ? `&year=${encodeURIComponent(r.year)}` : ''}`}
|
||||
target='_self'
|
||||
rel='noreferrer'
|
||||
className='group block'
|
||||
>
|
||||
{r.poster ? (
|
||||
<img
|
||||
src={`/api/image-proxy?url=${encodeURIComponent(r.poster)}`}
|
||||
alt={r.title}
|
||||
className='w-full aspect-[2/3] object-cover rounded-md mb-1'
|
||||
/>
|
||||
) : null}
|
||||
<div className='text-xs truncate group-hover:text-blue-500' title={r.title}>
|
||||
{r.title}
|
||||
</div>
|
||||
<div className='text-[10px] opacity-50 truncate'>
|
||||
{[r.year, r.source_name].filter(Boolean).join(' · ')}
|
||||
</div>
|
||||
{r.reasons?.length > 0 && (
|
||||
<div
|
||||
className='text-[10px] text-green-600/80 truncate'
|
||||
title={r.reasons.join('、')}
|
||||
>
|
||||
{r.reasons.slice(0, 2).join(' · ')}
|
||||
</div>
|
||||
)}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -174,6 +174,7 @@ function shouldSkipAuth(pathname: string): boolean {
|
||||
'/api/douban-comments',
|
||||
'/api/douban-detail',
|
||||
'/api/douban-related',
|
||||
'/api/related',
|
||||
];
|
||||
|
||||
return skipPaths.some((path) => pathname.startsWith(path));
|
||||
@@ -182,6 +183,6 @@ function shouldSkipAuth(pathname: string): boolean {
|
||||
// 配置middleware匹配规则
|
||||
export const config = {
|
||||
matcher: [
|
||||
'/((?!_next/static|_next/image|favicon.ico|login|warning|hls.min.js|mpegts.min.js|api/login|api/register|api/logout|api/cron|api/server-config|api/search|api/detail|api/image-proxy|api/license-config|api/douban-comments|api/douban-detail|api/douban-related).*)',
|
||||
'/((?!_next/static|_next/image|favicon.ico|login|warning|hls.min.js|mpegts.min.js|api/login|api/register|api/logout|api/cron|api/server-config|api/search|api/detail|api/image-proxy|api/license-config|api/douban-comments|api/douban-detail|api/douban-related|api/related).*)',
|
||||
],
|
||||
};
|
||||