mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 03:55:38 -04:00
Movies and Episodes cards now have an interactive dropdown to switch between Today, This Week, This Month, and This Year. Extracts reusable getWatchCount helper in discovery service and adds /api/stats route. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { headers } from "next/headers";
|
|
import { NextResponse } from "next/server";
|
|
import { auth } from "@/lib/auth/server";
|
|
import { getWatchCount, 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 count = getWatchCount(
|
|
session.user.id,
|
|
type as "movies" | "episodes",
|
|
period as TimePeriod,
|
|
);
|
|
|
|
return NextResponse.json({ count });
|
|
}
|