mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-23 23:52:18 +03:00
Stop usage analytics reads from backfilling missing API key attribution into historical rows so legacy records remain unchanged and surface as unknown instead of guessed ownership. Also require management authentication on admin concurrency and compression analytics endpoints, and preserve image payloads during lite compression unless a model is explicitly marked as non-vision.
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
/**
|
|
* GET /api/analytics/compression
|
|
*
|
|
* Returns aggregated compression analytics from the compression_analytics table.
|
|
* Supports ?since=24h|7d|30d|all (default: 24h).
|
|
*/
|
|
|
|
import { NextResponse } from "next/server";
|
|
import { getCompressionAnalyticsSummary } from "@/lib/db/compressionAnalytics";
|
|
import { requireManagementAuth } from "@/lib/api/requireManagementAuth";
|
|
|
|
export async function GET(req: Request) {
|
|
const authError = await requireManagementAuth(req);
|
|
if (authError) return authError;
|
|
|
|
try {
|
|
const url = new URL(req.url);
|
|
const sinceParam = url.searchParams.get("since") ?? "24h";
|
|
const validSince = ["24h", "7d", "30d", "all"].includes(sinceParam) ? sinceParam : "24h";
|
|
|
|
const summary = getCompressionAnalyticsSummary(validSince === "all" ? undefined : validSince);
|
|
|
|
return NextResponse.json(summary);
|
|
} catch (err: unknown) {
|
|
const msg = err instanceof Error ? err.message : String(err);
|
|
console.error("[/api/analytics/compression]", msg);
|
|
return NextResponse.json({ error: "Internal server error" }, { status: 500 });
|
|
}
|
|
}
|