Files
katelyatv/src/app/api/douban-comments/route.ts
T
3970260761 428b4b73d0
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
fixed78: 详情页改为豆瓣短评+豆瓣跳转按钮(演员/评分/演员搜索保留)
2026-11-08 14:35:25 +08:00

55 lines
2.0 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
export const dynamic = 'force-dynamic';
interface DoubanComment {
id: string;
user: string;
avatar: string;
rating: number;
content: string;
time: string;
location: string;
}
// 从豆瓣 rexxar 移动 API 获取短评(热门优先)
export async function GET(req: NextRequest) {
const { searchParams } = new URL(req.url);
const id = (searchParams.get('id') || '').trim();
const sort = (searchParams.get('sort') || 'hot').trim(); // hot | new
const count = Math.min(parseInt(searchParams.get('count') || '10') || 10, 20);
if (!id) return NextResponse.json({ code: 0, msg: '缺少豆瓣ID', list: [] });
const order = sort === 'new' ? 'time' : 'hot';
const url = `https://m.douban.com/rexxar/api/v2/movie/${id}/interests?count=${count}&order_by=${order}&status=done`;
try {
const r = await fetch(url, {
headers: {
'User-Agent':
'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',
Referer: `https://m.douban.com/movie/subject/${id}/`,
Accept: 'application/json',
},
signal: AbortSignal.timeout(15000),
});
if (!r.ok) throw new Error(`HTTP ${r.status}`);
const d: any = await r.json();
const list: DoubanComment[] = (Array.isArray(d?.interests) ? d.interests : [])
.map((x: any) => ({
id: String(x?.id || ''),
user: String(x?.user?.name || ''),
avatar: String(x?.user?.avatar || ''),
rating: Number(x?.rating?.value || 0),
content: String(x?.comment || '').trim(),
time: String(x?.create_time || ''),
location: String(x?.ip_location || ''),
}))
.filter((c: DoubanComment) => c.content.length > 0);
return NextResponse.json({ code: 1, msg: 'ok', total: d?.total || list.length, list });
} catch (e: any) {
return NextResponse.json({ code: 0, msg: e?.message || 'fetch fail', list: [] });
}
}