mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 03:55:38 -04:00
Background sparkline area charts on Movies and Episodes cards show watch activity distribution over the selected period. Periods now use rolling windows (past 24h/7d/30d/365d) instead of calendar boundaries. Bumped stats grid breakpoint to lg. Upgraded recharts 2.15.4 → 3.7.0 and fixed chart.tsx types for v3 (TooltipContentProps, LegendPayload). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { headers } from "next/headers";
|
|
import { NextResponse } from "next/server";
|
|
import { auth } from "@/lib/auth/server";
|
|
import {
|
|
getWatchCount,
|
|
getWatchHistory,
|
|
type TimePeriod,
|
|
} from "@/lib/services/discovery";
|
|
|
|
const validTypes = ["movies", "episodes"] as const;
|
|
const validPeriods: TimePeriod[] = [
|
|
"today",
|
|
"this_week",
|
|
"this_month",
|
|
"this_year",
|
|
];
|
|
|
|
export async function GET(request: Request) {
|
|
const session = await auth.api.getSession({ headers: await headers() });
|
|
if (!session)
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
|
|
const { searchParams } = new URL(request.url);
|
|
const type = searchParams.get("type");
|
|
const period = searchParams.get("period");
|
|
|
|
if (
|
|
!type ||
|
|
!period ||
|
|
!validTypes.includes(type as (typeof validTypes)[number]) ||
|
|
!validPeriods.includes(period as TimePeriod)
|
|
) {
|
|
return NextResponse.json({ error: "Invalid parameters" }, { status: 400 });
|
|
}
|
|
|
|
const typedType = type as "movies" | "episodes";
|
|
const typedPeriod = period as TimePeriod;
|
|
const count = getWatchCount(session.user.id, typedType, typedPeriod);
|
|
|
|
if (searchParams.get("history") === "true") {
|
|
const history = getWatchHistory(session.user.id, typedType, typedPeriod);
|
|
return NextResponse.json({ count, history });
|
|
}
|
|
|
|
return NextResponse.json({ count });
|
|
}
|