| | |
| | import { cookies } from 'next/headers'; |
| | import type { NextRequest } from 'next/server'; |
| | import { NextResponse } from 'next/server'; |
| |
|
| | export async function DELETE(request: NextRequest) { |
| | try { |
| | |
| | const { searchParams } = new URL(request.url); |
| | const filename = searchParams.get('filename'); |
| | |
| | |
| | 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}` |
| | ); |
| |
|
| | |
| | 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 } |
| | ); |
| | } |
| |
|
| | |
| | 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 } |
| | ); |
| | } |
| | } |