Files
katelyatv/src/app/api/anime/route.ts
T
3970260761 e766391534
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
Release / release (push) Canceled after 0s
Release / docker (push) Canceled after 0s
fixed96: 新增/动漫页与/api/browse第三方分类浏览,修复动漫页首屏空列表
- 新增 src/app/anime + src/app/api/anime: 多源并行抓取、地区归一化、title+year去重、update_time降序、pg分页
- 新增 src/app/api/browse + src/lib/vodcat.ts: kind/cat|area/pg 统一第三方分类浏览接口
- douban 电影/剧集/综艺 选择器改走 /api/browse, 分类全量切第三方分类语义
- PageLayout/MobileBottomNav 增加 动漫 导航入口(源码实现)
- 修复 /anime reset=true 时 base 置空导致新数据被丢弃(接口200页面空)
- 版本 NEXT_PUBLIC_SITE_VERSION=fixed96; README/CHANGELOG 更新
2026-11-09 03:02:13 +08:00

86 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { NextRequest, NextResponse } from 'next/server';
import { getAvailableApiSites, getCacheTime } from '@/lib/config';
import { fetchSiteKind, mapItem, Site } from '@/lib/vodcat';
// ---------- /api/anime 动漫聚合接口(源码化) ----------
// 数据来源:各第三方采集站(maccms 10 协议),非豆瓣精选
// 逻辑:按「动漫/动画/卡通」分类名跨站筛分类 -> 逐类取分页 -> 合并去重(全量)
// 参数:region('' | 国产 | 日韩 | 欧美 | 港台 | 海外)、pg
const EXCLUDE_SITES = new Set(['xiaojizy', '155api']);
// 地区 -> 各站分类名里的关键词(国产动漫 / 中国动漫 / 国产动漫…)
const REGION_MAP: Record<string, string> = {
国产: '国产',
日韩: '日韩',
欧美: '欧美',
港台: '港台',
海外: '海外',
};
export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url);
const region = searchParams.get('region') || '';
const pg = Math.max(1, parseInt(searchParams.get('pg') || '1', 10));
try {
const all = await getAvailableApiSites(true);
const sites = all.filter(
(s) => !EXCLUDE_SITES.has(s.key) && !String(s.name || '').startsWith('AV-')
) as unknown as Site[];
const cacheTime = await getCacheTime();
const cat = REGION_MAP[region] || '';
const settled = await Promise.all(
sites.map(async (s) => {
try {
return await fetchSiteKind(s, 'anime', cat, pg);
} catch {
return { items: [] as any[], hasMore: false };
}
})
);
const seen = new Set<string>();
const list: any[] = [];
let hasMore = false;
settled.forEach((r, i) => {
if (r.hasMore) hasMore = true;
const site = sites[i];
r.items.forEach((it) => {
const m = mapItem(it, site);
if (!m.title) return;
const k = `${m.title}|${m.year}`;
if (seen.has(k)) return;
seen.add(k);
list.push(m);
});
});
return NextResponse.json(
{ source: 'all', region, pg, list, next_pg: pg + 1, has_more: hasMore },
{
headers: {
'Cache-Control': `public, max-age=${Math.min(cacheTime, 300)}, s-maxage=${Math.min(cacheTime, 300)}`,
},
}
);
} catch (e: any) {
return NextResponse.json(
{ error: '动漫聚合请求失败', details: e?.message || String(e) },
{ status: 500 }
);
}
}
export async function OPTIONS() {
return new NextResponse(null, {
status: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
},
});
}