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:
2026-03-06 17:31:14 -05:00
parent 73b07f5ff6
commit 8d8c49a7f0
21 changed files with 396 additions and 630 deletions
+23
View File
@@ -1,9 +1,16 @@
"use server";
import { and, eq } from "drizzle-orm";
import { z } from "zod";
import { getSession, requireSession } from "@/lib/auth/session";
import { db } from "@/lib/db/client";
import { userTitleStatus } from "@/lib/db/schema";
import {
getWatchCount,
getWatchHistory,
type HistoryBucket,
type TimePeriod,
} from "@/lib/services/discovery";
import { importTitle } from "@/lib/services/metadata";
import {
getEpisodeProgressByTmdbIds,
@@ -55,3 +62,19 @@ export async function quickAddToWatchlist(
setTitleStatus(userId, title.id, "watchlist");
return { success: true, titleId: title.id, alreadyAdded: false };
}
const statsSchema = z.object({
type: z.enum(["movies", "episodes"]),
period: z.enum(["today", "this_week", "this_month", "this_year"]),
});
export async function getStatsAction(
type: "movies" | "episodes",
period: TimePeriod,
): Promise<{ count: number; history: HistoryBucket[] }> {
const session = await requireSession();
const parsed = statsSchema.parse({ type, period });
const count = getWatchCount(session.user.id, parsed.type, parsed.period);
const history = getWatchHistory(session.user.id, parsed.type, parsed.period);
return { count, history };
}