mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 01:35:39 -04:00
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:
@@ -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;
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user