mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 01:35:39 -04:00
- Convert discover, stats, status, and system-health server actions to proper API route handlers under `app/api/`; delete `lib/actions/explore.ts`, `lib/actions/settings.ts`, and `lib/actions/setup.ts` - Add `use-discover`, `use-stats`, and `use-system-health` SWR hooks that call the new routes; update `command-palette`, `title-card`, `update-toast`, and `stats-display` to consume them - Lift auth centering wrapper from individual login/register pages into `(auth)/layout.tsx`; switch both pages from `auth.api.getSession` to the cached `getSession()` helper - Relocate setup wizard from `app/(auth)/setup/` to `app/setup/` (outside auth group) with dedicated `copy-button` and `refresh-button` client components - Move `not-found.tsx` and `error.tsx` to app root so they apply globally instead of only within the pages route group
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { type NextRequest, NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import { getSession } from "@/lib/auth/session";
|
|
import { getWatchCount, getWatchHistory } from "@/lib/services/discovery";
|
|
|
|
const paramsSchema = z.object({
|
|
type: z.enum(["movies", "episodes"]),
|
|
period: z.enum(["today", "this_week", "this_month", "this_year"]),
|
|
});
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const session = await getSession();
|
|
if (!session) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
}
|
|
|
|
const parsed = paramsSchema.safeParse({
|
|
type: req.nextUrl.searchParams.get("type"),
|
|
period: req.nextUrl.searchParams.get("period"),
|
|
});
|
|
|
|
if (!parsed.success) {
|
|
return NextResponse.json(
|
|
{ error: "Invalid type or period parameter" },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
const { type, period } = parsed.data;
|
|
const count = getWatchCount(session.user.id, type, period);
|
|
const history = getWatchHistory(session.user.id, type, period);
|
|
|
|
return NextResponse.json({ count, history });
|
|
}
|