// app/api/file/upload/route.ts import { cookies } from 'next/headers'; import type { NextRequest } from 'next/server'; import { NextResponse } from 'next/server'; export async function DELETE(request: NextRequest) { try { // Get FormData from request const { searchParams } = new URL(request.url); const filename = searchParams.get('filename'); // Get auth token from cookies const cookieStore = await cookies(); const token = cookieStore.get('auth_token')?.value; if (!token) { return NextResponse.json( { message: 'Not authenticated' }, { status: 401 } ); } const url = new URL( `https://byteriot-candidateexplorer.hf.space/CandidateExplorer/file/${filename}` ); // Forward the FormData to external API const response = await fetch( url.toString(), { method: 'DELETE', headers: { Authorization: `Bearer ${token}`, }, } ); if (!response.ok) { const errorData = await response.json().catch(() => null); return NextResponse.json( { message: errorData?.message, error: errorData }, { status: response.status } ); } // Get response data from external API const data = await response.json(); return NextResponse.json( { success: true, message: 'Extract uploaded file successfully', data: data }, { status: 200 } ); } catch (error) { console.error('Extract uploaded file error:', error); return NextResponse.json( { message: 'Failed to extract uploaded file ', error: String(error) }, { status: 500 } ); } }