mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-02-14 20:04:43 +08:00
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
/* eslint-disable no-console,@typescript-eslint/no-explicit-any */
|
|
|
|
import { NextResponse } from "next/server";
|
|
|
|
import { getConfig } from "@/lib/config";
|
|
|
|
export const runtime = 'nodejs';
|
|
|
|
export async function GET(request: Request) {
|
|
const { searchParams } = new URL(request.url);
|
|
const url = searchParams.get('url');
|
|
const source = searchParams.get('moontv-source');
|
|
if (!url) {
|
|
return NextResponse.json({ error: 'Missing url' }, { status: 400 });
|
|
}
|
|
|
|
const config = await getConfig();
|
|
const liveSource = config.LiveConfig?.find((s: any) => s.key === source);
|
|
if (!liveSource) {
|
|
return NextResponse.json({ error: 'Source not found' }, { status: 404 });
|
|
}
|
|
const ua = liveSource.ua || 'AptvPlayer/1.4.10';
|
|
|
|
try {
|
|
const decodedUrl = decodeURIComponent(url);
|
|
console.log(decodedUrl);
|
|
const response = await fetch(decodedUrl, {
|
|
headers: {
|
|
'User-Agent': ua,
|
|
},
|
|
});
|
|
if (!response.ok) {
|
|
return NextResponse.json({ error: 'Failed to fetch key' }, { status: 500 });
|
|
}
|
|
const keyData = await response.arrayBuffer();
|
|
return new Response(keyData, {
|
|
headers: {
|
|
'Content-Type': 'application/octet-stream',
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
|
'Cache-Control': 'public, max-age=3600'
|
|
},
|
|
});
|
|
} catch (error) {
|
|
return NextResponse.json({ error: 'Failed to fetch key' }, { status: 500 });
|
|
}
|
|
} |