Skip to content

Commit 388089d

Browse files
senshinyaclaude
andcommitted
release 100.1.3
- 修复首页热门数据在番剧接口失败时一并空白:改为 Promise.allSettled - 番剧日历改走服务端代理 /api/bangumi/calendar,规避 bgm.tv CORS Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent af8caa2 commit 388089d

7 files changed

Lines changed: 94 additions & 13 deletions

File tree

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## [100.1.3] - 2026-05-28
2+
3+
### Fixed
4+
5+
- 修复首页热门电影、热门剧集、热门综艺在番剧接口失败时一并空白的问题
6+
- 番剧日历改为通过服务端代理请求,规避 bgm.tv 的 CORS 限制
7+
18
## [100.1.2] - 2026-03-15
29

310
### Changed

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
100.1.2
1+
100.1.3
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { NextResponse } from 'next/server';
2+
3+
import { getCacheTime } from '@/lib/config';
4+
5+
export const runtime = 'nodejs';
6+
7+
export async function GET() {
8+
const controller = new AbortController();
9+
const timeoutId = setTimeout(() => controller.abort(), 10000);
10+
11+
try {
12+
const response = await fetch('https://api.bgm.tv/calendar', {
13+
signal: controller.signal,
14+
headers: {
15+
'User-Agent':
16+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
17+
Accept: 'application/json',
18+
},
19+
});
20+
clearTimeout(timeoutId);
21+
22+
if (!response.ok) {
23+
throw new Error(`HTTP error! Status: ${response.status}`);
24+
}
25+
26+
const data = await response.json();
27+
const cacheTime = await getCacheTime();
28+
29+
return NextResponse.json(data, {
30+
headers: {
31+
'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`,
32+
'CDN-Cache-Control': `public, s-maxage=${cacheTime}`,
33+
'Vercel-CDN-Cache-Control': `public, s-maxage=${cacheTime}`,
34+
},
35+
});
36+
} catch (error) {
37+
clearTimeout(timeoutId);
38+
return NextResponse.json(
39+
{ error: '获取番剧日历失败', details: (error as Error).message },
40+
{ status: 500 }
41+
);
42+
}
43+
}

src/app/page.tsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ function HomeClient() {
7272
try {
7373
setLoading(true);
7474

75-
// 并行获取热门电影、热门剧集和热门综艺
76-
const [moviesData, tvShowsData, varietyShowsData, bangumiCalendarData] =
77-
await Promise.all([
75+
// 并行获取热门电影、热门剧集、热门综艺和番剧日历
76+
// 使用 allSettled 避免单个请求失败导致全部数据为空
77+
const [moviesRes, tvShowsRes, varietyShowsRes, bangumiRes] =
78+
await Promise.allSettled([
7879
getDoubanCategories({
7980
kind: 'movie',
8081
category: '热门',
@@ -85,19 +86,32 @@ function HomeClient() {
8586
GetBangumiCalendarData(),
8687
]);
8788

88-
if (moviesData.code === 200) {
89-
setHotMovies(moviesData.list);
89+
if (moviesRes.status === 'fulfilled' && moviesRes.value.code === 200) {
90+
setHotMovies(moviesRes.value.list);
91+
} else if (moviesRes.status === 'rejected') {
92+
console.error('获取热门电影失败:', moviesRes.reason);
9093
}
9194

92-
if (tvShowsData.code === 200) {
93-
setHotTvShows(tvShowsData.list);
95+
if (tvShowsRes.status === 'fulfilled' && tvShowsRes.value.code === 200) {
96+
setHotTvShows(tvShowsRes.value.list);
97+
} else if (tvShowsRes.status === 'rejected') {
98+
console.error('获取热门剧集失败:', tvShowsRes.reason);
9499
}
95100

96-
if (varietyShowsData.code === 200) {
97-
setHotVarietyShows(varietyShowsData.list);
101+
if (
102+
varietyShowsRes.status === 'fulfilled' &&
103+
varietyShowsRes.value.code === 200
104+
) {
105+
setHotVarietyShows(varietyShowsRes.value.list);
106+
} else if (varietyShowsRes.status === 'rejected') {
107+
console.error('获取热门综艺失败:', varietyShowsRes.reason);
98108
}
99109

100-
setBangumiCalendarData(bangumiCalendarData);
110+
if (bangumiRes.status === 'fulfilled') {
111+
setBangumiCalendarData(bangumiRes.value);
112+
} else {
113+
console.error('获取番剧日历失败:', bangumiRes.reason);
114+
}
101115
} catch (error) {
102116
console.error('获取推荐数据失败:', error);
103117
} finally {

src/lib/bangumi.client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export interface BangumiCalendarData {
2323
}
2424

2525
export async function GetBangumiCalendarData(): Promise<BangumiCalendarData[]> {
26-
const response = await fetch('https://api.bgm.tv/calendar');
26+
const response = await fetch('/api/bangumi/calendar');
27+
if (!response.ok) {
28+
throw new Error(`获取番剧日历失败: HTTP ${response.status}`);
29+
}
2730
const data = await response.json();
2831
const filteredData = data.map((item: BangumiCalendarData) => ({
2932
...item,

src/lib/changelog.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ export interface ChangelogEntry {
1010
}
1111

1212
export const changelog: ChangelogEntry[] = [
13+
{
14+
version: "100.1.3",
15+
date: "2026-05-28",
16+
added: [
17+
// 无新增内容
18+
],
19+
changed: [
20+
// 无变更内容
21+
],
22+
fixed: [
23+
"修复首页热门电影、热门剧集、热门综艺在番剧接口失败时一并空白的问题",
24+
"番剧日历改为通过服务端代理请求,规避 bgm.tv 的 CORS 限制"
25+
]
26+
},
1327
{
1428
version: "100.1.2",
1529
date: "2026-03-15",

src/lib/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-console */
22

3-
const CURRENT_VERSION = '100.1.2';
3+
const CURRENT_VERSION = '100.1.3';
44

55
// 导出当前版本号供其他地方使用
66
export { CURRENT_VERSION };

0 commit comments

Comments
 (0)