File size: 746 Bytes
88c4c60 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import { NextResponse } from "next/server";
import { getUsageStats } from "@/lib/usageDb";
const VALID_PERIODS = new Set(["today", "24h", "7d", "30d", "60d", "all"]);
export const dynamic = "force-dynamic";
export async function GET(request) {
try {
const { searchParams } = new URL(request.url);
const period = searchParams.get("period") || "7d";
if (!VALID_PERIODS.has(period)) {
return NextResponse.json({ error: "Invalid period" }, { status: 400 });
}
const stats = await getUsageStats(period);
return NextResponse.json(stats);
} catch (error) {
console.error("[API] Failed to get usage stats:", error);
return NextResponse.json({ error: "Failed to fetch usage stats" }, { status: 500 });
}
}
|