Replace tmdb-* URL routing with resolveTitle/resolvePerson server actions

- Add `resolveTitle` and `resolvePerson` server actions that import
  from TMDB and return the internal DB id
- Remove `tmdb-{id}-{type}` URL pattern and server-side redirect logic
  from TitleDetailPage and PersonDetailPage
- Rename `importTitle` → `getOrFetchTitleByTmdbId`; add `getOrFetchTitle`
  combining fetch + children lookup
- Update HeroBanner, TitleCard, and CommandPalette to call resolve
  actions client-side before pushing to router
- Batch availability offer inserts into a single transaction
This commit is contained in:
2026-03-07 14:27:03 -05:00
parent ccd482db4e
commit 8a45aa1c36
17 changed files with 552 additions and 419 deletions
+10
View File
@@ -0,0 +1,10 @@
"use server";
import { requireSession } from "@/lib/auth/session";
import { getOrFetchPersonByTmdbId } from "@/lib/services/person";
export async function resolvePerson(tmdbId: number): Promise<string | null> {
await requireSession();
const person = await getOrFetchPersonByTmdbId(tmdbId);
return person?.id ?? null;
}
+10
View File
@@ -5,6 +5,7 @@ import { z } from "zod";
import { requireSession } from "@/lib/auth/session";
import { db } from "@/lib/db/client";
import { episodes } from "@/lib/db/schema";
import { getOrFetchTitleByTmdbId } from "@/lib/services/metadata";
import {
logEpisodeWatch,
logEpisodeWatchBatch,
@@ -22,6 +23,15 @@ async function getSessionUserId() {
return session.user.id;
}
export async function resolveTitle(
tmdbId: number,
type: "movie" | "tv",
): Promise<string | null> {
await requireSession();
const title = await getOrFetchTitleByTmdbId(tmdbId, type);
return title?.id ?? null;
}
export async function updateTitleStatus(
titleId: string,
status: "in_progress" | null,
+2 -2
View File
@@ -11,7 +11,7 @@ import {
type HistoryBucket,
type TimePeriod,
} from "@/lib/services/discovery";
import { importTitle } from "@/lib/services/metadata";
import { getOrFetchTitleByTmdbId } from "@/lib/services/metadata";
import {
getEpisodeProgressByTmdbIds,
getUserStatusesByTmdbIds,
@@ -41,7 +41,7 @@ export async function quickAddToWatchlist(
const session = await requireSession();
const userId = session.user.id;
const title = await importTitle(tmdbId, type);
const title = await getOrFetchTitleByTmdbId(tmdbId, type);
if (!title) throw new Error("Failed to import title");
const existing = db