File size: 1,688 Bytes
1fbd3b4
 
 
 
 
5228494
1fbd3b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// 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 }
    );
  }
}