fixed80: 相关推荐10部(豆瓣) + 中间件白名单
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
574fa99fb4
commit
7a99890425
3 files changed
+78
-1
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const id = (searchParams.get('id') || '').trim();
|
||||
const type = (searchParams.get('type') || 'movie').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';
|
||||
const kind = type === 'tv' ? 'tv' : 'movie';
|
||||
|
||||
try {
|
||||
const r = await fetch(
|
||||
`https://m.douban.com/rexxar/api/v2/${kind}/${id}/recommendations?count=10&start=0`,
|
||||
{
|
||||
headers: { 'User-Agent': ua, Referer: `https://m.douban.com/${kind}/subject/${id}/`, Accept: 'application/json' },
|
||||
signal: AbortSignal.timeout(15000),
|
||||
}
|
||||
);
|
||||
if (!r.ok) return NextResponse.json({ code: 0, msg: '请求失败' });
|
||||
const arr: any = await r.json();
|
||||
if (!Array.isArray(arr)) return NextResponse.json({ code: 0, msg: '无数据' });
|
||||
const list = arr.slice(0, 10).map((x: any) => ({
|
||||
id: String(x.id || ''),
|
||||
title: x.title || '',
|
||||
poster: x?.pic?.large || x?.pic?.normal || '',
|
||||
rating: Number(x?.rating?.value || 0),
|
||||
subtitle: x.card_subtitle || '',
|
||||
url: x.url || '',
|
||||
}));
|
||||
return NextResponse.json({ code: 1, msg: 'ok', list });
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ code: 0, msg: e?.message || 'error' });
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ export default function VideoMetaExtra({
|
||||
doubanId,
|
||||
area,
|
||||
lang,
|
||||
isTv,
|
||||
}: {
|
||||
title: string;
|
||||
actor?: string;
|
||||
@@ -34,10 +35,12 @@ export default function VideoMetaExtra({
|
||||
doubanId?: number;
|
||||
area?: string;
|
||||
lang?: string;
|
||||
isTv?: boolean;
|
||||
}) {
|
||||
const [comments, setComments] = useState<DoubanComment[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [dbDetail, setDbDetail] = useState<any>(null);
|
||||
const [related, setRelated] = useState<any[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!doubanId) return;
|
||||
@@ -59,6 +62,13 @@ 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;
|
||||
};
|
||||
@@ -185,6 +195,34 @@ export default function VideoMetaExtra({
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
{related.length > 0 && (
|
||||
<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={r.url}
|
||||
target='_blank'
|
||||
rel='noreferrer'
|
||||
className='group block'
|
||||
>
|
||||
{r.poster ? (
|
||||
<img
|
||||
src={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>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+2
-1
@@ -172,6 +172,7 @@ function shouldSkipAuth(pathname: string): boolean {
|
||||
'/api/license-config',
|
||||
'/api/douban-comments',
|
||||
'/api/douban-detail',
|
||||
'/api/douban-related',
|
||||
];
|
||||
|
||||
return skipPaths.some((path) => pathname.startsWith(path));
|
||||
@@ -180,6 +181,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).*)',
|
||||
'/((?!_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).*)',
|
||||
],
|
||||
};
|
||||
Reference in new issue
Block a user