feat: add cache control

This commit is contained in:
shinya
2025-06-19 12:45:46 +08:00
parent da46031ae6
commit 660b51d9bd
5 changed files with 48 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
import { NextResponse } from 'next/server';
import { API_CONFIG, ApiSite, getApiSites } from '@/lib/config';
import { API_CONFIG, ApiSite, getApiSites, getCacheTime } from '@/lib/config';
const M3U8_PATTERN = /(https?:\/\/[^"'\s]+?\.m3u8)/g;
@@ -218,7 +218,13 @@ export async function GET(request: Request) {
try {
const result = await getVideoDetail(id, sourceCode);
return NextResponse.json(result);
const cacheTime = getCacheTime();
return NextResponse.json(result, {
headers: {
'Cache-Control': `public, max-age=${cacheTime}`,
},
});
} catch (error) {
return NextResponse.json(
{ error: (error as Error).message },