Files
sofa/app/api/person/[id]/route.ts
T
jakeandClaude Opus 4.6 cd5d773e98 Add actor/cast information with person pages and search support
Integrate TMDB credits data into the app: cast carousels on title detail
pages, person detail pages with biography and filmography, and person
search results in the command palette. Includes new persons/titleCast
DB tables, profile image caching, and a nightly credits refresh cron job.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 14:36:39 -05:00

36 lines
976 B
TypeScript

import { headers } from "next/headers";
import { type NextRequest, NextResponse } from "next/server";
import { auth } from "@/lib/auth/server";
import {
getLocalFilmography,
getOrFetchPerson,
getOrFetchPersonByTmdbId,
} from "@/lib/services/person";
const TMDB_PATTERN = /^tmdb-(\d+)$/;
export async function GET(
_req: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) {
const session = await auth.api.getSession({ headers: await headers() });
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const { id } = await params;
const tmdbMatch = TMDB_PATTERN.exec(id);
const person = tmdbMatch
? await getOrFetchPersonByTmdbId(Number(tmdbMatch[1]))
: await getOrFetchPerson(id);
if (!person) {
return NextResponse.json({ error: "Person not found" }, { status: 404 });
}
const filmography = getLocalFilmography(person.id);
return NextResponse.json({ person, filmography });
}