mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 07:12:12 +03:00
chore(duplication): share batch response formatter (#5488)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
30
src/app/api/v1/batches/formatBatchResponse.ts
Normal file
30
src/app/api/v1/batches/formatBatchResponse.ts
Normal 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,
|
||||
};
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user