修正轮播图和videocard混用processImageUrl

This commit is contained in:
mtvpls
2026-01-08 01:04:07 +08:00
parent 2736c9e845
commit 4474c0c6f9
2 changed files with 104 additions and 11 deletions

View File

@@ -5,7 +5,6 @@ import Image from 'next/image';
import { useRouter } from 'next/navigation';
import { getTMDBImageUrl, getGenreNames, type TMDBItem } from '@/lib/tmdb.client';
import { ChevronLeft, ChevronRight, Play } from 'lucide-react';
import { processImageUrl, processVideoUrl } from '@/lib/utils';
interface BannerCarouselProps {
autoPlayInterval?: number; // 自动播放间隔(毫秒)
@@ -51,9 +50,9 @@ export default function BannerCarousel({ autoPlayInterval = 5000 }: BannerCarous
if (!path) return '';
// 如果是完整URLTX数据源或豆瓣需要判断是否需要代理
if (path.startsWith('http://') || path.startsWith('https://')) {
// 豆瓣图片需要通过代理
// 豆瓣图片直接使用服务器代理
if (path.includes('doubanio.com')) {
return processImageUrl(path);
return `/api/image-proxy?url=${encodeURIComponent(path)}`;
}
// TX等其他完整URL直接返回
return path;
@@ -65,9 +64,9 @@ export default function BannerCarousel({ autoPlayInterval = 5000 }: BannerCarous
// 获取视频URL处理豆瓣视频代理
const getVideoUrl = (url: string | null) => {
if (!url) return null;
// 豆瓣视频需要通过域名替换代理
// 豆瓣视频直接使用服务器代理
if (url.includes('doubanio.com')) {
return processVideoUrl(url);
return `/api/video-proxy?url=${encodeURIComponent(url)}`;
}
return url;
};

View File

@@ -12,6 +12,14 @@ function getDoubanImageProxyConfig(): {
| 'custom';
proxyUrl: string;
} {
// 确保在浏览器环境中执行
if (typeof window === 'undefined') {
return {
proxyType: 'cmliussss-cdn-tencent',
proxyUrl: '',
};
}
const doubanImageProxyType =
localStorage.getItem('doubanImageProxyType') ||
(window as any).RUNTIME_CONFIG?.DOUBAN_IMAGE_PROXY_TYPE ||
@@ -27,7 +35,7 @@ function getDoubanImageProxyConfig(): {
}
/**
* 处理图片 URL统一使用服务器代理
* 处理图片 URL根据用户设置使用相应的代理
*/
export function processImageUrl(originalUrl: string): string {
if (!originalUrl) return originalUrl;
@@ -42,12 +50,55 @@ export function processImageUrl(originalUrl: string): string {
return originalUrl;
}
// 统一使用服务器代理
return `/api/image-proxy?url=${encodeURIComponent(originalUrl)}`;
// 获取用户配置的代理设置
const { proxyType, proxyUrl } = getDoubanImageProxyConfig();
// 根据代理类型处理URL
switch (proxyType) {
case 'direct':
// 直连,不使用代理
return originalUrl;
case 'server':
// 使用服务器代理
return `/api/image-proxy?url=${encodeURIComponent(originalUrl)}`;
case 'img3':
// 使用 img3.doubanio.com 代理
return originalUrl.replace(/img\d\.doubanio\.com/g, 'img3.doubanio.com');
case 'cmliussss-cdn-tencent':
// 使用腾讯云CDN代理
return originalUrl.replace(
/https?:\/\/img\d\.doubanio\.com/g,
'https://douban-img.cmliussss.workers.dev'
);
case 'cmliussss-cdn-ali':
// 使用阿里云CDN代理
return originalUrl.replace(
/https?:\/\/img\d\.doubanio\.com/g,
'https://douban-img-ali.cmliussss.workers.dev'
);
case 'custom':
// 使用自定义代理
if (proxyUrl) {
return originalUrl.replace(/https?:\/\/img\d\.doubanio\.com/g, proxyUrl);
}
return originalUrl;
default:
// 默认使用腾讯云CDN代理
return originalUrl.replace(
/https?:\/\/img\d\.doubanio\.com/g,
'https://douban-img.cmliussss.workers.dev'
);
}
}
/**
* 处理视频 URL如果<EFBFBD><EFBFBD><EFBFBD>置了代理则使用代理与图片使用相的代理配置)
* 处理视频 URL根据用户设置使用相的代理
*/
export function processVideoUrl(originalUrl: string): string {
if (!originalUrl) return originalUrl;
@@ -57,8 +108,51 @@ export function processVideoUrl(originalUrl: string): string {
return originalUrl;
}
// 统一使用服务器代理
return `/api/video-proxy?url=${encodeURIComponent(originalUrl)}`;
// 获取用户配置的代理设置
const { proxyType, proxyUrl } = getDoubanImageProxyConfig();
// 根据代理类型处理URL
switch (proxyType) {
case 'direct':
// 直连,不使用代理
return originalUrl;
case 'server':
// 使用服务器代理
return `/api/video-proxy?url=${encodeURIComponent(originalUrl)}`;
case 'img3':
// 使用 img3.doubanio.com 代理
return originalUrl.replace(/img\d\.doubanio\.com/g, 'img3.doubanio.com');
case 'cmliussss-cdn-tencent':
// 使用腾讯云CDN代理
return originalUrl.replace(
/https?:\/\/img\d\.doubanio\.com/g,
'https://douban-img.cmliussss.workers.dev'
);
case 'cmliussss-cdn-ali':
// 使用阿里云CDN代理
return originalUrl.replace(
/https?:\/\/img\d\.doubanio\.com/g,
'https://douban-img-ali.cmliussss.workers.dev'
);
case 'custom':
// 使用自定义代理
if (proxyUrl) {
return originalUrl.replace(/https?:\/\/img\d\.doubanio\.com/g, proxyUrl);
}
return originalUrl;
default:
// 默认使用腾讯云CDN代理
return originalUrl.replace(
/https?:\/\/img\d\.doubanio\.com/g,
'https://douban-img.cmliussss.workers.dev'
);
}
}
/**