kv-tube/frontend/app/api/stream/route.ts
KV-Tube Deployer 66d95e0fb4
Some checks failed
CI / lint (push) Failing after 5s
CI / test (push) Failing after 0s
CI / build (push) Has been skipped
fix: use NEXT_PUBLIC_API_URL and add yt-dlp to fix backend info fetching
2026-02-22 19:52:51 +07:00

31 lines
1 KiB
TypeScript
Executable file

import { NextRequest, NextResponse } from 'next/server';
export async function GET(request: NextRequest) {
const videoId = request.nextUrl.searchParams.get('v');
if (!videoId) {
return NextResponse.json({ error: 'No video ID' }, { status: 400 });
}
try {
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL || 'http://127.0.0.1:8080'}/api/get_stream_info?v=${videoId}`, {
cache: 'no-store',
});
if (!res.ok) {
return NextResponse.json({ error: 'Failed to fetch' }, { status: 500 });
}
const data = await res.json();
const streamUrl = data.original_url || data.stream_url;
const proxyUrl = streamUrl ? `/api/proxy-stream?url=${encodeURIComponent(streamUrl)}` : null;
return NextResponse.json({
streamUrl: proxyUrl,
title: data.title,
thumbnail: data.thumbnail
});
} catch (error) {
return NextResponse.json({ error: 'Failed to fetch stream' }, { status: 500 });
}
}