Spaces:
Paused
Paused
Download src/app/api/pricing/sync/route.ts from igorkurgin/omniroute: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/spaces/igorkurgin/omniroute/resolve/main/src/app/api/pricing/sync/route.ts
- Command line
-
hf download hf://spaces/igorkurgin/omniroute/src/app/api/pricing/sync/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/igorkurgin/omniroute/resolve/main/src/app/api/pricing/sync/route.ts
2.1 kB
| /** | |
| * API Route: /api/pricing/sync | |
| * | |
| * POST — Trigger a manual pricing sync from external sources. | |
| * GET — Get current sync status. | |
| * DELETE — Clear all synced pricing data. | |
| */ | |
| import { NextRequest, NextResponse } from "next/server"; | |
| import { pricingSyncRequestSchema } from "@/shared/validation/schemas"; | |
| import { isValidationFailure, validateBody } from "@/shared/validation/helpers"; | |
| export async function POST(request: NextRequest) { | |
| let rawBody: unknown; | |
| 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(pricingSyncRequestSchema, rawBody); | |
| if (isValidationFailure(validation)) { | |
| return NextResponse.json({ error: validation.error }, { status: 400 }); | |
| } | |
| const { sources, dryRun = false } = validation.data; | |
| const { syncPricingFromSources } = await import("@/lib/pricingSync"); | |
| const result = await syncPricingFromSources({ sources, dryRun }); | |
| return NextResponse.json(result, { status: result.success ? 200 : 502 }); | |
| } catch (err) { | |
| const message = err instanceof Error ? err.message : String(err); | |
| return NextResponse.json({ error: message }, { status: 500 }); | |
| } | |
| } | |
| export async function GET() { | |
| try { | |
| const { getSyncStatus } = await import("@/lib/pricingSync"); | |
| return NextResponse.json(getSyncStatus()); | |
| } catch (err) { | |
| const message = err instanceof Error ? err.message : String(err); | |
| return NextResponse.json({ error: message }, { status: 500 }); | |
| } | |
| } | |
| export async function DELETE() { | |
| try { | |
| const { clearSyncedPricing } = await import("@/lib/pricingSync"); | |
| clearSyncedPricing(); | |
| return NextResponse.json({ success: true, message: "Synced pricing data cleared" }); | |
| } catch (err) { | |
| const message = err instanceof Error ? err.message : String(err); | |
| return NextResponse.json({ error: message }, { status: 500 }); | |
| } | |
| } | |