import type { APIRoute } from "astro"; import db from "../../../lib/db"; export const POST: APIRoute = async ({ request }) => { let body: Record; try { body = await request.json(); } catch { return new Response("Bad request", { status: 400 }); } if (!db) return new Response("ok", { status: 200 }); try { await db` INSERT INTO usage ( date, time, user_id, palace, usr, butler, channel, model, domain, duration_ms, duration_min, tokens_in, tokens_out, cost_usd, num_turns ) VALUES ( ${body.date ?? null}, ${body.time ?? null}, ${body.user_id ?? null}, ${body.palace ?? null}, ${body.user ?? null}, ${body.butler ?? null}, ${body.channel ?? null}, ${body.model ?? null}, ${body.domain ?? null}, ${body.duration_ms ?? null}, ${body.duration_min ?? null}, ${body.tokens_in ?? null}, ${body.tokens_out ?? null}, ${body.cost_usd ?? null}, ${body.num_turns ?? null} ) `; } catch {} return new Response("ok", { status: 200 }); };