mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 23:32:12 +03:00
Extracted validateBody, isValidationFailure, and loginSchema from the 935-line schemas.ts barrel file into a dedicated helpers.ts module. Updated 70 API route files to import directly from helpers.ts. Root cause: webpack on certain environments fails to resolve exports from the bottom of large barrel files (schemas.ts), causing '(0, O.Jb) is not a function' errors in production builds. Fix: Split validation helpers into a small dedicated module (helpers.ts) so webpack can correctly resolve all exports regardless of file size. - TypeScript compiles with 0 errors - All API routes updated to import from helpers.ts - schemas.ts re-exports from helpers.ts for backward compatibility
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import {
|
|
getAvailabilityReport,
|
|
clearModelUnavailability,
|
|
getUnavailableCount,
|
|
} from "@/domain/modelAvailability";
|
|
import { clearModelAvailabilitySchema } from "@/shared/validation/schemas";
|
|
import { isValidationFailure, validateBody } from "@/shared/validation/helpers";
|
|
|
|
export async function GET() {
|
|
try {
|
|
const report = getAvailabilityReport();
|
|
const count = getUnavailableCount();
|
|
return NextResponse.json({ unavailableCount: count, models: report });
|
|
} catch (error) {
|
|
console.error("Error getting model availability:", error);
|
|
return NextResponse.json({ error: "Failed to get model availability" }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function POST(request) {
|
|
let rawBody;
|
|
try {
|
|
rawBody = await request.json();
|
|
} catch {
|
|
return NextResponse.json(
|
|
{
|
|
error: {
|
|
message: "Invalid request",
|
|
details: [{ field: "body", message: "Invalid JSON body" }],
|
|
},
|
|
},
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
try {
|
|
const validation = validateBody(clearModelAvailabilitySchema, rawBody);
|
|
if (isValidationFailure(validation)) {
|
|
return NextResponse.json({ error: validation.error }, { status: 400 });
|
|
}
|
|
const { provider, model } = validation.data;
|
|
|
|
const removed = clearModelUnavailability(provider, model);
|
|
return NextResponse.json({ success: true, removed });
|
|
} catch (error) {
|
|
console.error("Error clearing model availability:", error);
|
|
return NextResponse.json({ error: "Failed to clear model availability" }, { status: 500 });
|
|
}
|
|
}
|