首页增加tmdb热门轮播图
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { getTMDBTrendingContent } from '@/lib/tmdb.client';
|
||||
import { getConfig } from '@/lib/config';
|
||||
|
||||
// 缓存配置 - 服务器内存缓存3小时
|
||||
const CACHE_DURATION = 3 * 60 * 60 * 1000; // 3小时
|
||||
let cachedData: { data: any; timestamp: number } | null = null;
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (cachedData && Date.now() - cachedData.timestamp < CACHE_DURATION) {
|
||||
return NextResponse.json(cachedData.data);
|
||||
}
|
||||
|
||||
// 获取配置
|
||||
const config = await getConfig();
|
||||
const apiKey = config.SiteConfig?.TMDBApiKey;
|
||||
const proxy = config.SiteConfig?.TMDBProxy;
|
||||
|
||||
if (!apiKey) {
|
||||
return NextResponse.json(
|
||||
{ code: 400, message: 'TMDB API Key 未配置' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// 获取热门内容
|
||||
const result = await getTMDBTrendingContent(apiKey, proxy);
|
||||
|
||||
// 更新缓存
|
||||
cachedData = {
|
||||
data: result,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
|
||||
return NextResponse.json(result);
|
||||
} catch (error) {
|
||||
console.error('获取 TMDB 热门内容失败:', error);
|
||||
return NextResponse.json(
|
||||
{ code: 500, message: '获取热门内容失败' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
+9
-1
@@ -28,6 +28,7 @@ import ScrollableRow from '@/components/ScrollableRow';
|
||||
import { useSite } from '@/components/SiteProvider';
|
||||
import VideoCard from '@/components/VideoCard';
|
||||
import HttpWarningDialog from '@/components/HttpWarningDialog';
|
||||
import BannerCarousel from '@/components/BannerCarousel';
|
||||
|
||||
function HomeClient() {
|
||||
const [activeTab, setActiveTab] = useState<'home' | 'favorites'>('home');
|
||||
@@ -222,8 +223,15 @@ function HomeClient() {
|
||||
|
||||
return (
|
||||
<PageLayout>
|
||||
{/* TMDB 热门轮播图 - 只在首页显示,且占满宽度 */}
|
||||
{activeTab === 'home' && (
|
||||
<div className='w-full mb-6 sm:mb-8'>
|
||||
<BannerCarousel />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className='px-2 sm:px-10 py-4 sm:py-8 overflow-visible'>
|
||||
{/* 顶部 Tab 切换 */}
|
||||
{/* Tab 切换移到轮播图下方 */}
|
||||
<div className='mb-8 flex justify-center'>
|
||||
<CapsuleSwitch
|
||||
options={[
|
||||
|
||||
Reference in New Issue
Block a user