@@ -16,13 +16,40 @@ export async function GET(
1616 }
1717
1818 try {
19- const response = await fetch ( `${ backendUrl } /api/v1/evaluations/tts/datasets/${ dataset_id } ` , {
19+ // Forward query parameters to the backend
20+ const { searchParams } = new URL ( request . url ) ;
21+ const backendParams = new URLSearchParams ( ) ;
22+ for ( const [ key , value ] of searchParams . entries ( ) ) {
23+ backendParams . append ( key , value ) ;
24+ }
25+ const queryString = backendParams . toString ( ) ? `?${ backendParams . toString ( ) } ` : '' ;
26+
27+ const response = await fetch ( `${ backendUrl } /api/v1/evaluations/tts/datasets/${ dataset_id } ${ queryString } ` , {
2028 headers : {
2129 'X-API-KEY' : apiKey ,
2230 } ,
2331 } ) ;
2432
2533 const data = await response . json ( ) ;
34+ if ( ! response . ok ) {
35+ return NextResponse . json ( data , { status : response . status } ) ;
36+ }
37+
38+ // If fetch_content=true, download the CSV from the signed URL and return it
39+ const fetchContent = new URL ( request . url ) . searchParams . get ( 'fetch_content' ) ;
40+ if ( fetchContent === 'true' ) {
41+ const signedUrl = data ?. data ?. signed_url || data ?. signed_url ;
42+ if ( ! signedUrl ) {
43+ return NextResponse . json ( { error : 'No signed URL available' } , { status : 404 } ) ;
44+ }
45+ const csvResponse = await fetch ( signedUrl ) ;
46+ if ( ! csvResponse . ok ) {
47+ return NextResponse . json ( { error : 'Failed to fetch CSV file' } , { status : 502 } ) ;
48+ }
49+ const csvText = await csvResponse . text ( ) ;
50+ return NextResponse . json ( { ...data , csv_content : csvText } , { status : 200 } ) ;
51+ }
52+
2653 return NextResponse . json ( data , { status : response . status } ) ;
2754 } catch ( error ) {
2855 return NextResponse . json (
@@ -31,3 +58,28 @@ export async function GET(
3158 ) ;
3259 }
3360}
61+
62+ export async function DELETE (
63+ request : Request ,
64+ { params } : { params : Promise < { dataset_id : string } > }
65+ ) {
66+ const { dataset_id } = await params ;
67+ const backendUrl = process . env . NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000' ;
68+ const apiKey = request . headers . get ( 'X-API-KEY' ) ;
69+
70+ if ( ! apiKey ) {
71+ return NextResponse . json ( { success : false , error : 'Unauthorized: Missing API key' } , { status : 401 } ) ;
72+ }
73+
74+ try {
75+ const response = await fetch ( `${ backendUrl } /api/v1/evaluations/tts/datasets/${ dataset_id } ` , {
76+ method : 'DELETE' ,
77+ headers : { 'X-API-KEY' : apiKey } ,
78+ } ) ;
79+ let data ;
80+ try { data = await response . json ( ) ; } catch { data = { success : true } ; }
81+ return NextResponse . json ( data , { status : response . ok ? 200 : response . status } ) ;
82+ } catch ( error : any ) {
83+ return NextResponse . json ( { success : false , error : 'Failed to delete dataset' , details : error . message } , { status : 500 } ) ;
84+ }
85+ }
0 commit comments