Skip to content

Commit 06fd669

Browse files
committed
fix: route iqiyizyimg and other external images through image-proxy and fix Referer header
1 parent bc83728 commit 06fd669

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/app/api/image-proxy/route.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,20 @@ async function fetchImage(
5454
): Promise<Response> {
5555
const isBangumiImage =
5656
options?.source === 'bangumi' || isBangumiImageUrl(imageUrl);
57-
const headers = {
57+
const isDoubanImage = imageUrl.includes('doubanio.com');
58+
59+
const headers: Record<string, string> = {
5860
'User-Agent':
5961
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
6062
Accept: 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
61-
Referer: isBangumiImage ? 'https://bgm.tv/' : 'https://movie.douban.com/',
6263
};
6364

65+
if (isBangumiImage) {
66+
headers.Referer = 'https://bgm.tv/';
67+
} else if (isDoubanImage) {
68+
headers.Referer = 'https://movie.douban.com/';
69+
}
70+
6471
const config = isBangumiImage ? await getConfig() : null;
6572
const targetUrl = isBangumiImage
6673
? applyBangumiImageBaseUrl(imageUrl, config?.SiteConfig.BangumiImageBaseUrl)

src/lib/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,16 @@ export function processImageUrl(originalUrl: string): string {
438438

439439
// 处理豆瓣图片代理
440440
if (!originalUrl.includes('doubanio.com')) {
441+
// 如果是爱奇艺资源站域名,或者用户开启了外部图片代理
442+
const isIqiyiImage = originalUrl.includes('iqiyizyimg.com');
443+
const enableExternalImageProxy =
444+
typeof window !== 'undefined' &&
445+
localStorage.getItem('enableExternalImageProxy') === 'true';
446+
447+
if (isIqiyiImage || enableExternalImageProxy) {
448+
return `/api/image-proxy?url=${encodeURIComponent(originalUrl)}`;
449+
}
450+
441451
// 升级 http 到 https 防止混合内容拦截,对非豆瓣/Bangumi 的外部图片不做代理直连返回
442452
return originalUrl.replace(/^http:/i, 'https:');
443453
}

0 commit comments

Comments
 (0)