mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 03:55:38 -04:00
- Overhaul `lib/auth/server.ts` and `lib/auth/session.ts`; update all API routes and server actions to use the revised session pattern - Refactor server actions (settings, titles, watchlist, setup) for consistency with new auth layer - Extract `SetupForm` into its own client component with `useActionState`, animated steps, and copyable env snippets - Move landing page redirect logic into `app/page.tsx`; slim down `LandingPage` component - Add `proxy.ts` for local dev proxying - Minor cleanup to `NavBar`, `MobileTabBar`, and `TitleCard`
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { getSession } from "@/lib/auth/session";
|
|
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 getSession();
|
|
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 });
|
|
}
|