From 36c1b87af42c9ad3afb58cff0c705999ad660fb0 Mon Sep 17 00:00:00 2001 From: mtvpls Date: Sat, 27 Dec 2025 22:25:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E7=BB=A7=E7=BB=AD=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E7=9A=84=E5=88=A0=E9=99=A4=E5=92=8C=E6=94=B6=E8=97=8F?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/tmdb/trending/route.ts | 6 ++- src/components/BannerCarousel.tsx | 64 ++++++++++++++++++++---------- src/components/VideoCard.tsx | 4 +- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/app/api/tmdb/trending/route.ts b/src/app/api/tmdb/trending/route.ts index 88ed143..059bd49 100644 --- a/src/app/api/tmdb/trending/route.ts +++ b/src/app/api/tmdb/trending/route.ts @@ -27,12 +27,14 @@ export async function GET() { return NextResponse.json(cache.data); } - let result; + let result: any; // 根据配置的数据源获取数据 if (bannerDataSource === 'TX') { // 使用TX数据源 result = await getTXBannerContent(); + // 添加数据源标识 + result.source = 'TX'; // 更新TX缓存 txCache = { data: result, @@ -52,6 +54,8 @@ export async function GET() { // 获取热门内容 result = await getTMDBTrendingContent(apiKey, proxy); + // 添加数据源标识 + result.source = 'TMDB'; // 更新TMDB缓存 tmdbCache = { data: result, diff --git a/src/components/BannerCarousel.tsx b/src/components/BannerCarousel.tsx index 3e99893..652ccbb 100644 --- a/src/components/BannerCarousel.tsx +++ b/src/components/BannerCarousel.tsx @@ -28,9 +28,13 @@ export default function BannerCarousel({ autoPlayInterval = 5000 }: BannerCarous const isManualChange = useRef(false); // 标记是否为手动切换 // LocalStorage 缓存配置 - const LOCALSTORAGE_KEY = 'tmdb_trending_cache'; const LOCALSTORAGE_DURATION = 24 * 60 * 60 * 1000; // 1天 + // 根据数据源获取缓存key + const getLocalStorageKey = (source: string) => { + return `banner_trending_cache_${source}`; + }; + // 跳转到播放页面 const handlePlay = (title: string) => { router.push(`/play?title=${encodeURIComponent(title)}`); @@ -51,34 +55,52 @@ export default function BannerCarousel({ autoPlayInterval = 5000 }: BannerCarous useEffect(() => { const fetchTrending = async () => { try { - // 先检查 localStorage 缓存 - const cached = localStorage.getItem(LOCALSTORAGE_KEY); - if (cached) { - try { - const { data, timestamp } = JSON.parse(cached); - const now = Date.now(); - - // 如果缓存未过期,直接使用 - if (now - timestamp < LOCALSTORAGE_DURATION) { - setItems(data); - setIsLoading(false); - return; + // 先尝试从所有可能的数据源缓存中读取 + const sources = ['TMDB', 'TX']; + let cachedData = null; + let validSource = null; + + for (const source of sources) { + const cacheKey = getLocalStorageKey(source); + const cached = localStorage.getItem(cacheKey); + + if (cached) { + try { + const { data, timestamp } = JSON.parse(cached); + const now = Date.now(); + + // 如果缓存未过期,使用缓存数据 + if (now - timestamp < LOCALSTORAGE_DURATION) { + cachedData = data; + validSource = source; + break; + } + } catch (e) { + console.error('解析缓存数据失败:', e); } - } catch (e) { - // 缓存解析失败,继续请求 API - console.error('解析缓存数据失败:', e); } } - // 从 API 获取数据 + // 如果有有效的缓存,直接使用,不请求API + if (cachedData) { + setItems(cachedData); + setIsLoading(false); + return; + } + + // 没有缓存或缓存过期,从 API 获取数据 const response = await fetch('/api/tmdb/trending'); const result = await response.json(); + if (result.code === 200 && result.list.length > 0) { + const dataSource = result.source || 'TMDB'; // 获取数据源标识 + const cacheKey = getLocalStorageKey(dataSource); + setItems(result.list); - - // 保存到 localStorage + + // 保存到 localStorage(使用数据源特定的key) try { - localStorage.setItem(LOCALSTORAGE_KEY, JSON.stringify({ + localStorage.setItem(cacheKey, JSON.stringify({ data: result.list, timestamp: Date.now() })); @@ -95,7 +117,7 @@ export default function BannerCarousel({ autoPlayInterval = 5000 }: BannerCarous }; fetchTrending(); - }, [LOCALSTORAGE_KEY, LOCALSTORAGE_DURATION]); + }, []); // 自动播放 useEffect(() => { diff --git a/src/components/VideoCard.tsx b/src/components/VideoCard.tsx index e580d96..b02d330 100644 --- a/src/components/VideoCard.tsx +++ b/src/components/VideoCard.tsx @@ -718,8 +718,8 @@ const VideoCard = forwardRef(function VideoCard )} - {/* 操作按钮 */} - {(config.showHeart || config.showCheckCircle) && ( + {/* 操作按钮 - 继续观看不显示桌面端悬停按钮 */} + {(config.showHeart || config.showCheckCircle) && from !== 'playrecord' && (