Add cost metrics to analytics dashboard
This commit is contained in:
@@ -1,12 +1,22 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getTrends } from "@/lib/queries";
|
||||
import { getTrends, type TrendGranularity } from "@/lib/queries";
|
||||
|
||||
const GRANULARITIES: TrendGranularity[] = ["hour", "day", "week", "month"];
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const sp = req.nextUrl.searchParams;
|
||||
const granularity = (sp.get("granularity") || "day") as "day" | "week" | "month";
|
||||
const requestedGranularity = sp.get("granularity");
|
||||
const granularity = GRANULARITIES.includes(requestedGranularity as TrendGranularity)
|
||||
? requestedGranularity as TrendGranularity
|
||||
: "day";
|
||||
const startTs = sp.get("start") ? Number(sp.get("start")) : undefined;
|
||||
const endTs = sp.get("end") ? Number(sp.get("end")) : undefined;
|
||||
const channelId = sp.get("channel_id") ? Number(sp.get("channel_id")) : undefined;
|
||||
|
||||
const data = await getTrends(granularity, startTs, endTs);
|
||||
const data = await getTrends(granularity, startTs, endTs, {
|
||||
username: sp.get("username") || undefined,
|
||||
model: sp.get("model") || undefined,
|
||||
channelId: Number.isFinite(channelId) ? channelId : undefined,
|
||||
});
|
||||
return NextResponse.json(data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user