mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 03:55:38 -04:00
Replace API route handlers with server actions across the app
- Delete 10 API routes (stats, system-health, update-check, jobs/trigger, backup/restore, person, titles import/resolve, registration/status) and move logic into server actions in lib/actions/settings.ts and lib/actions/watchlist.ts - Refactor SystemHealthCards to accept initialData prop and hydrate Jotai atoms via useHydrateAtoms; replace useSystemHealth SWR hook with a lightweight useSystemHealthRefresh that calls getSystemHealthAction - Convert BackupRestoreSection to use restoreBackupAction + useTransition instead of a raw fetch call - Split SystemStatusCard, BackgroundJobsCard, and StorageCard into standalone components reading from systemHealthDataAtom - Make SetupPage async with connection() to opt into dynamic rendering
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
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 });
|
||||
}
|
||||
Reference in New Issue
Block a user