修正轮播图和videocard混用processImageUrl
This commit is contained in:
@@ -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 '';
|
||||
// 如果是完整URL(TX数据源或豆瓣),需要判断是否需要代理
|
||||
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;
|
||||
};
|
||||
|
||||
106
src/lib/utils.ts
106
src/lib/utils.ts
@@ -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'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user