Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/api/credentials/[provider]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export async function GET(
);
return NextResponse.json(data, { status });
} catch (e: unknown) {
return NextResponse.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500 });
return NextResponse.json(
{ error: e instanceof Error ? e.message : String(e) },
{ status: 500 },
);
}
}

Expand All @@ -34,6 +37,9 @@ export async function DELETE(

return NextResponse.json(data, { status });
} catch (e: unknown) {
return NextResponse.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500 });
return NextResponse.json(
{ error: e instanceof Error ? e.message : String(e) },
{ status: 500 },
);
}
}
15 changes: 12 additions & 3 deletions app/api/credentials/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ export async function GET(request: NextRequest) {
const { status, data } = await apiClient(request, "/api/v1/credentials/");
return NextResponse.json(data, { status });
} catch (e: unknown) {
return NextResponse.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500 });
return NextResponse.json(
{ error: e instanceof Error ? e.message : String(e) },
{ status: 500 },
);
}
}

Expand All @@ -19,7 +22,10 @@ export async function POST(request: NextRequest) {
});
return NextResponse.json(data, { status });
} catch (e: unknown) {
return NextResponse.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500 });
return NextResponse.json(
{ error: e instanceof Error ? e.message : String(e) },
{ status: 500 },
);
}
}

Expand All @@ -32,6 +38,9 @@ export async function PATCH(request: NextRequest) {
});
return NextResponse.json(data, { status });
} catch (e: unknown) {
return NextResponse.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500 });
return NextResponse.json(
{ error: e instanceof Error ? e.message : String(e) },
{ status: 500 },
);
}
}
53 changes: 16 additions & 37 deletions app/api/evaluations/stt/files/route.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,28 @@
import { NextRequest, NextResponse } from 'next/server';

import { apiClient } from "@/app/lib/apiClient";
import { NextRequest, NextResponse } from "next/server";

export async function POST(request: NextRequest) {
try {
// Get the API key from request headers
const apiKey = request.headers.get('X-API-KEY');

if (!apiKey) {
return NextResponse.json(
{ error: 'Missing X-API-KEY header' },
{ status: 401 }
);
}

// Get the form data from the request
const formData = await request.formData();

// Get backend URL from environment variable
const backendUrl = process.env.BACKEND_URL || 'http://localhost:8000';

// Forward the request to the actual backend
const response = await fetch(`${backendUrl}/api/v1/evaluations/stt/files`, {
method: 'POST',
body: formData,
headers: {
'X-API-KEY': apiKey,

const { status, data: responseData } = await apiClient(
request,
"/api/v1/evaluations/stt/files",
{
method: "POST",
body: formData,
},
});

// Handle empty responses (204 No Content, etc.)
const text = await response.text();
const data = text ? JSON.parse(text) : { success: true };

// Return the response with the same status code
if (!response.ok) {
return NextResponse.json(data, { status: response.status });
}
);

return NextResponse.json(data, { status: response.status });
return NextResponse.json(responseData, { status });
} catch (error: unknown) {
console.error('Proxy error:', error);
console.error("Proxy error:", error);
return NextResponse.json(
{ error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) },
{ status: 500 }
{
error: "Failed to forward request to backend",
details: error instanceof Error ? error.message : String(error),
},
{ status: 500 },
);
}
}
87 changes: 42 additions & 45 deletions app/api/evaluations/tts/datasets/[dataset_id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { NextResponse } from 'next/server';
import { apiClient } from "@/app/lib/apiClient";
import { NextResponse } from "next/server";

export async function GET(
request: Request,
{ params }: { params: Promise<{ dataset_id: string }> }
{ params }: { params: Promise<{ dataset_id: string }> },
) {
const { dataset_id } = await params;
const backendUrl = process.env.BACKEND_URL || 'http://localhost:8000';
const apiKey = request.headers.get('X-API-KEY');

if (!apiKey) {
return NextResponse.json(
{ success: false, error: 'Unauthorized: Missing API key', data: null },
{ status: 401 }
);
}

try {
// Forward query parameters to the backend
Expand All @@ -22,64 +14,69 @@ export async function GET(
for (const [key, value] of searchParams.entries()) {
backendParams.append(key, value);
}
const queryString = backendParams.toString() ? `?${backendParams.toString()}` : '';
const queryString = backendParams.toString()
? `?${backendParams.toString()}`
: "";

const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/datasets/${dataset_id}${queryString}`, {
headers: {
'X-API-KEY': apiKey,
},
});

const data = await response.json();
if (!response.ok) {
return NextResponse.json(data, { status: response.status });
}
const { data, status } = await apiClient(
request,
`/api/v1/evaluations/tts/datasets/${dataset_id}${queryString}`,
);

// If fetch_content=true, download the CSV from the signed URL and return it
const fetchContent = new URL(request.url).searchParams.get('fetch_content');
if (fetchContent === 'true') {
const fetchContent = new URL(request.url).searchParams.get("fetch_content");
if (fetchContent === "true") {
const signedUrl = data?.data?.signed_url || data?.signed_url;
if (!signedUrl) {
return NextResponse.json({ error: 'No signed URL available' }, { status: 404 });
return NextResponse.json(
{ error: "No signed URL available" },
{ status: 404 },
);
}
const csvResponse = await fetch(signedUrl);
if (!csvResponse.ok) {
return NextResponse.json({ error: 'Failed to fetch CSV file' }, { status: 502 });
return NextResponse.json(
{ error: "Failed to fetch CSV file" },
{ status: 502 },
);
}
const csvText = await csvResponse.text();
return NextResponse.json({ ...data, csv_content: csvText }, { status: 200 });
return NextResponse.json(
{ ...data, csv_content: csvText },
{ status: 200 },
);
Comment thread
Ayush8923 marked this conversation as resolved.
}

return NextResponse.json(data, { status: response.status });
return NextResponse.json(data, { status });
} catch (_error) {
return NextResponse.json(
{ success: false, error: 'Failed to fetch dataset', data: null },
{ status: 500 }
{ success: false, error: "Failed to fetch dataset", data: null },
{ status: 500 },
);
}
}

export async function DELETE(
request: Request,
{ params }: { params: Promise<{ dataset_id: string }> }
{ params }: { params: Promise<{ dataset_id: string }> },
) {
const { dataset_id } = await params;
const backendUrl = process.env.BACKEND_URL || 'http://localhost:8000';
const apiKey = request.headers.get('X-API-KEY');

if (!apiKey) {
return NextResponse.json({ success: false, error: 'Unauthorized: Missing API key' }, { status: 401 });
}

try {
const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/datasets/${dataset_id}`, {
method: 'DELETE',
headers: { 'X-API-KEY': apiKey },
});
let data;
try { data = await response.json(); } catch { data = { success: true }; }
return NextResponse.json(data, { status: response.ok ? 200 : response.status });
const { data, status } = await apiClient(
request,
`/api/v1/evaluations/tts/datasets/${dataset_id}`,
{ method: "DELETE" },
);
return NextResponse.json(data, { status });
Comment thread
Ayush8923 marked this conversation as resolved.
} catch (error: unknown) {
return NextResponse.json({ success: false, error: 'Failed to delete dataset', details: error instanceof Error ? error.message : String(error) }, { status: 500 });
return NextResponse.json(
{
success: false,
error: "Failed to delete dataset",
details: error instanceof Error ? error.message : String(error),
},
{ status: 500 },
);
}
}
56 changes: 22 additions & 34 deletions app/api/evaluations/tts/datasets/route.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,41 @@
import { NextResponse, NextRequest } from 'next/server';
import { apiClient } from "@/app/lib/apiClient";
import { NextResponse, NextRequest } from "next/server";

export async function GET(request: Request) {
const backendUrl = process.env.BACKEND_URL || 'http://localhost:8000';
const apiKey = request.headers.get('X-API-KEY');

try {
const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/datasets`, {
headers: {
'X-API-KEY': apiKey || '',
},
});

const data = await response.json();
return NextResponse.json(data, { status: response.status });
const { status, data } = await apiClient(
request,
"/api/v1/evaluations/tts/datasets",
);
return NextResponse.json(data, { status });
} catch (error) {
return NextResponse.json(
{ success: false, error: error, data: null },
{ status: 500 }
{ status: 500 },
);
}
}

export async function POST(request: NextRequest) {
try {
const apiKey = request.headers.get('X-API-KEY');
if (!apiKey) {
return NextResponse.json(
{ error: 'Missing X-API-KEY. Either generate an API Key. Contact Kaapi team for more details' },
{ status: 401 }
);
}
const body = await request.json();
const backendUrl = process.env.BACKEND_URL || 'http://localhost:8000';

const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/datasets`, {
method: 'POST',
body: JSON.stringify(body),
headers: {
'X-API-KEY': apiKey,
'Content-Type': 'application/json',
const { status, data } = await apiClient(
request,
"/api/v1/evaluations/tts/datasets",
{
method: "POST",
body: JSON.stringify(body),
},
});
const data = await response.json();
return NextResponse.json(data, { status: response.status });
);
return NextResponse.json(data, { status });
} catch (error) {
console.error('Proxy error:', error);
console.error("Proxy error:", error);
return NextResponse.json(
{ error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) },
{ status: 500 }
{
error: "Failed to forward request to backend",
details: error instanceof Error ? error.message : String(error),
},
{ status: 500 },
);
}
}
Loading
Loading