chore(duplication): share batch response formatter (#5488)

This commit is contained in:
Jan Leon
2026-06-30 02:58:32 +02:00
committed by GitHub
parent e124b50922
commit 15eeaa31c5
4 changed files with 33 additions and 93 deletions

View File

@@ -2,37 +2,7 @@ import { CORS_HEADERS, handleCorsOptions } from "@/shared/utils/cors";
import { getBatch, updateBatch } from "@/lib/localDb";
import { NextResponse } from "next/server";
import { getApiKeyRequestScope } from "@/app/api/v1/_helpers/apiKeyScope";
function formatBatchResponse(batch: any) {
return {
id: batch.id,
object: "batch",
endpoint: batch.endpoint,
errors: batch.errors || null,
input_file_id: batch.inputFileId,
completion_window: batch.completionWindow,
status: batch.status,
output_file_id: batch.outputFileId || null,
error_file_id: batch.errorFileId || null,
created_at: batch.createdAt,
in_progress_at: batch.inProgressAt || null,
expires_at: batch.expiresAt || null,
finalizing_at: batch.finalizingAt || null,
completed_at: batch.completedAt || null,
failed_at: batch.failedAt || null,
expired_at: batch.expiredAt || null,
cancelling_at: batch.cancellingAt || null,
cancelled_at: batch.cancelledAt || null,
request_counts: {
total: batch.requestCountsTotal || 0,
completed: batch.requestCountsCompleted || 0,
failed: batch.requestCountsFailed || 0,
},
metadata: batch.metadata || null,
model: batch.model || null,
usage: batch.usage || null,
};
}
import { formatBatchResponse } from "../../formatBatchResponse";
export async function OPTIONS() {
return handleCorsOptions();

View File

@@ -2,37 +2,7 @@ import { CORS_HEADERS, handleCorsOptions } from "@/shared/utils/cors";
import { getBatch, deleteBatch } from "@/lib/localDb";
import { NextResponse } from "next/server";
import { getApiKeyRequestScope } from "@/app/api/v1/_helpers/apiKeyScope";
function formatBatchResponse(batch: any) {
return {
id: batch.id,
object: "batch",
endpoint: batch.endpoint,
errors: batch.errors || null,
input_file_id: batch.inputFileId,
completion_window: batch.completionWindow,
status: batch.status,
output_file_id: batch.outputFileId || null,
error_file_id: batch.errorFileId || null,
created_at: batch.createdAt,
in_progress_at: batch.inProgressAt || null,
expires_at: batch.expiresAt || null,
finalizing_at: batch.finalizingAt || null,
completed_at: batch.completedAt || null,
failed_at: batch.failedAt || null,
expired_at: batch.expiredAt || null,
cancelling_at: batch.cancellingAt || null,
cancelled_at: batch.cancelledAt || null,
request_counts: {
total: batch.requestCountsTotal || 0,
completed: batch.requestCountsCompleted || 0,
failed: batch.requestCountsFailed || 0,
},
metadata: batch.metadata || null,
model: batch.model || null,
usage: batch.usage || null,
};
}
import { formatBatchResponse } from "../formatBatchResponse";
export async function OPTIONS() {
return handleCorsOptions();

View File

@@ -0,0 +1,30 @@
export function formatBatchResponse(batch: any) {
return {
id: batch.id,
object: "batch",
endpoint: batch.endpoint,
errors: batch.errors || null,
input_file_id: batch.inputFileId,
completion_window: batch.completionWindow,
status: batch.status,
output_file_id: batch.outputFileId || null,
error_file_id: batch.errorFileId || null,
created_at: batch.createdAt,
in_progress_at: batch.inProgressAt || null,
expires_at: batch.expiresAt || null,
finalizing_at: batch.finalizingAt || null,
completed_at: batch.completedAt || null,
failed_at: batch.failedAt || null,
expired_at: batch.expiredAt || null,
cancelling_at: batch.cancellingAt || null,
cancelled_at: batch.cancelledAt || null,
request_counts: {
total: batch.requestCountsTotal || 0,
completed: batch.requestCountsCompleted || 0,
failed: batch.requestCountsFailed || 0,
},
metadata: batch.metadata || null,
model: batch.model || null,
usage: batch.usage || null,
};
}

View File

@@ -3,37 +3,7 @@ import { createBatch, getFile, listBatches, countBatches } from "@/lib/localDb";
import { v1BatchCreateSchema } from "@/shared/validation/schemas";
import { NextResponse } from "next/server";
import { getApiKeyRequestScope } from "@/app/api/v1/_helpers/apiKeyScope";
function formatBatchResponse(batch: any) {
return {
id: batch.id,
object: "batch",
endpoint: batch.endpoint,
errors: batch.errors || null,
input_file_id: batch.inputFileId,
completion_window: batch.completionWindow,
status: batch.status,
output_file_id: batch.outputFileId || null,
error_file_id: batch.errorFileId || null,
created_at: batch.createdAt,
in_progress_at: batch.inProgressAt || null,
expires_at: batch.expiresAt || null,
finalizing_at: batch.finalizingAt || null,
completed_at: batch.completedAt || null,
failed_at: batch.failedAt || null,
expired_at: batch.expiredAt || null,
cancelling_at: batch.cancellingAt || null,
cancelled_at: batch.cancelledAt || null,
request_counts: {
total: batch.requestCountsTotal || 0,
completed: batch.requestCountsCompleted || 0,
failed: batch.requestCountsFailed || 0,
},
metadata: batch.metadata || null,
model: batch.model || null,
usage: batch.usage || null,
};
}
import { formatBatchResponse } from "./formatBatchResponse";
export async function OPTIONS() {
return handleCorsOptions();