import { NextRequest, NextResponse } from 'next/server';
export async function POST(req: NextRequest) {
try {
const formData = await req.formData();
const file = formData.get('audio');
const targetSongId = formData.get('target_song_id');
if (!file || !targetSongId) {
return NextResponse.json({ error: 'Audio file or target song ID is missing' }, { status: 400 });
}
// Envia a requisição para a API de comparação sem autorização
const response = await fetch(`${process.env.NEXT_PUBLIC_COMPARE_AUDIO_IA_URL}/compare-audio/`, {
method: 'POST',
body: formData,
});
if (!response.ok) {
const message = await response.text();
console.error('API responded with an error:', message);
return NextResponse.json({ error: `Failed to compare audio: ${message}` }, { status: response.status });
}
const result = await response.json();
return NextResponse.json(result, { status: 200 });
} catch (error) {
console.error('Upload error:', error);
return NextResponse.json({ error: 'Unexpected error occurred during upload' }, { status: 500 });
}
}