fixed79: 豆瓣详情兜底评分/演员/导演 + 新增 douban-detail 路由
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
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
This commit is contained in:
1 parent
428b4b73d0
commit
574fa99fb4
3 files changed
+64
-9
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
// 从豆瓣 rexxar 获取条目详情(评分/演员/导演等)
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const id = (searchParams.get('id') || '').trim();
|
||||
if (!id) return NextResponse.json({ code: 0, msg: '缺少豆瓣ID' });
|
||||
|
||||
const ua =
|
||||
'Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1';
|
||||
|
||||
for (const kind of ['movie', 'tv']) {
|
||||
try {
|
||||
const r = await fetch(`https://m.douban.com/rexxar/api/v2/${kind}/${id}`, {
|
||||
headers: { 'User-Agent': ua, Referer: `https://m.douban.com/${kind}/subject/${id}/`, Accept: 'application/json' },
|
||||
signal: AbortSignal.timeout(15000),
|
||||
});
|
||||
if (!r.ok) continue;
|
||||
const d: any = await r.json();
|
||||
if (!d || !d.id) continue;
|
||||
const actors = (Array.isArray(d.actors) ? d.actors : [])
|
||||
.map((a: any) => a?.name || a?.title)
|
||||
.filter(Boolean);
|
||||
const directors = (Array.isArray(d.directors) ? d.directors : [])
|
||||
.map((a: any) => a?.name || a?.title)
|
||||
.filter(Boolean);
|
||||
return NextResponse.json({
|
||||
code: 1,
|
||||
msg: 'ok',
|
||||
title: d.title || '',
|
||||
rating: Number(d?.rating?.value || 0),
|
||||
ratingCount: Number(d?.rating?.count || 0),
|
||||
actors,
|
||||
directors,
|
||||
area: Array.isArray(d.regions) ? d.regions.join(' / ') : d.regions || '',
|
||||
year: d.year || '',
|
||||
});
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return NextResponse.json({ code: 0, msg: '未找到', rating: 0, actors: [], directors: [] });
|
||||
}
|
||||
@@ -37,6 +37,7 @@ export default function VideoMetaExtra({
|
||||
}) {
|
||||
const [comments, setComments] = useState<DoubanComment[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [dbDetail, setDbDetail] = useState<any>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!doubanId) return;
|
||||
@@ -51,30 +52,38 @@ export default function VideoMetaExtra({
|
||||
.finally(() => {
|
||||
if (alive) setLoading(false);
|
||||
});
|
||||
// 豆瓣详情(评分/演员兜底)
|
||||
fetch(`/api/douban-detail?id=${encodeURIComponent(String(doubanId))}`)
|
||||
.then((r) => r.json())
|
||||
.then((d) => {
|
||||
if (alive && d?.code === 1) setDbDetail(d);
|
||||
})
|
||||
.catch(() => {});
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [doubanId]);
|
||||
|
||||
const actors = (actor || '')
|
||||
const actors = (actor || (dbDetail?.actors || []).join(','))
|
||||
.split(/[,,、\/|]/)
|
||||
.map((s) => s.trim())
|
||||
.map((s: string) => s.trim())
|
||||
.filter(Boolean)
|
||||
.slice(0, 20);
|
||||
const scoreNum1 = parseFloat(score || '') || 0;
|
||||
const dbNum = parseFloat(doubanScore || '') || 0;
|
||||
const dbNum = parseFloat(doubanScore || '') || dbDetail?.rating || 0;
|
||||
const showScore = scoreNum1 > 0 ? scoreNum1.toFixed(1) : dbNum > 0 ? dbNum.toFixed(1) : '';
|
||||
|
||||
if (!actors.length && !director && !showScore && !area && !loading && !comments.length) return null;
|
||||
const showDirector = director || (dbDetail?.directors || []).join('、');
|
||||
if (!actors.length && !showDirector && !showScore && !area && !loading && !comments.length) return null;
|
||||
|
||||
return (
|
||||
<div className='mt-4 space-y-4'>
|
||||
{/* 导演 / 地区 / 语言 */}
|
||||
{(director || area || lang) && (
|
||||
{(showDirector || area || lang) && (
|
||||
<div className='text-sm opacity-80 space-x-4'>
|
||||
{director && (
|
||||
{showDirector && (
|
||||
<span>
|
||||
导演:<span className='font-medium'>{director}</span>
|
||||
导演:<span className='font-medium'>{showDirector}</span>
|
||||
</span>
|
||||
)}
|
||||
{area && <span>地区:{area}</span>}
|
||||
@@ -113,7 +122,7 @@ export default function VideoMetaExtra({
|
||||
<div>
|
||||
<div className='text-sm font-semibold mb-2 opacity-80'>演员({actors.length})</div>
|
||||
<div className='flex flex-wrap gap-2'>
|
||||
{actors.map((a) => (
|
||||
{actors.map((a: string) => (
|
||||
<Link
|
||||
key={a}
|
||||
href={`/search?q=${encodeURIComponent(a)}`}
|
||||
|
||||
+2
-1
@@ -171,6 +171,7 @@ function shouldSkipAuth(pathname: string): boolean {
|
||||
'/api/filter',
|
||||
'/api/license-config',
|
||||
'/api/douban-comments',
|
||||
'/api/douban-detail',
|
||||
];
|
||||
|
||||
return skipPaths.some((path) => pathname.startsWith(path));
|
||||
@@ -179,6 +180,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).*)',
|
||||
'/((?!_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).*)',
|
||||
],
|
||||
};
|
||||
Reference in new issue
Block a user