SPB Git

Repository Public

route.ts 2.6 KB 63 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Vrai-Prix8 * File             : src/app/api/cost/estimate/route.ts9 * Module           : app10 * Repository       : https://git.spboucher.ai/vrai-prix11 * Created          : 2026-09-0812 * Last Modified    : 2026-09-0813 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: contact@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Vrai-Prix — méthode du coût : calcul d'une estimation (déterministe, sauvegardée avec son instantané de prix).43import { NextRequest, NextResponse } from "next/server";44import { runEstimate, sanitizeInput } from "@/lib/cost/estimate";45import { clientKey, rateLimit } from "@/lib/cost/cache";4647export const runtime = "nodejs";48export const maxDuration = 30;4950export async function POST(req: NextRequest) {51  if (!rateLimit(`estimate:${clientKey(req)}`, 60, 60_000)) return NextResponse.json({ error: "Trop de requêtes — réessayez dans une minute." }, { status: 429 });52  let body: unknown;53  try { body = await req.json(); } catch { return NextResponse.json({ error: "JSON invalide" }, { status: 400 }); }54  try {55    const input = sanitizeInput((body as { input?: unknown })?.input ?? body);56    const save = (body as { save?: boolean })?.save !== false;57    const est = runEstimate(input, { save, sessionId: req.headers.get("x-session-id") });58    return NextResponse.json(est);59  } catch (e) {60    return NextResponse.json({ error: (e as Error).message }, { status: 500 });61  }62}63
Files main
Menu

Theme