kv-tube/frontend/app/api/download/route.ts
KV-Tube Deployer 95cfe06f2c
Some checks failed
CI / lint (push) Failing after 6s
CI / test (push) Failing after 1s
Docker Build & Push / build (push) Failing after 1s
CI / build (push) Has been skipped
chore: setup Dockerfiles and CI for Forgejo and Synology
2026-02-22 17:29:42 +07:00

29 lines
1,003 B
TypeScript
Executable file

import { NextRequest, NextResponse } from 'next/server';
const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'http://127.0.0.1:8080';
export async function GET(request: NextRequest) {
const videoId = request.nextUrl.searchParams.get('v');
const formatId = request.nextUrl.searchParams.get('f');
if (!videoId) {
return NextResponse.json({ error: 'No video ID' }, { status: 400 });
}
try {
const url = `${API_BASE}/api/download?v=${encodeURIComponent(videoId)}${formatId ? `&f=${encodeURIComponent(formatId)}` : ''}`;
const res = await fetch(url, {
cache: 'no-store',
});
const data = await res.json();
if (!res.ok) {
return NextResponse.json({ error: data.error || 'Download failed' }, { status: 500 });
}
return NextResponse.json(data);
} catch (error) {
return NextResponse.json({ error: 'Failed to get download link' }, { status: 500 });
}
}