TypeScript 97.4%
SQL 1%
JavaScript 0.9%
CSS 0.6%
1import { withUser } from "@/lib/api";2import { usageRecordsForExport, usageCsv, usageQueryFromUrl } from "@/lib/usage/service";34export const dynamic = "force-dynamic";56/** GET /api/usage/export.csv?<same params as /api/usage> → `text/csv` attachment of the raw usage records (max 50 000 rows). */7export const GET = withUser(async ({ req, user }) => {8 const { range, rows } = await usageRecordsForExport(user.id, usageQueryFromUrl(req.url));9 const from = range.from ? range.from.toISOString().slice(0, 10) : "all";10 const to = new Date(range.to.getTime() - 1).toISOString().slice(0, 10);11 const body = usageCsv(rows);12 return new Response(body, {13 status: 200,14 headers: {15 "Content-Type": "text/csv; charset=utf-8",16 "Content-Disposition": `attachment; filename="polyllm-usage-${from}_${to}.csv"`,17 "Cache-Control": "no-store",18 "X-Row-Count": String(rows.length),19 },20 });21});22