import { NextResponse } from "next/server"; import { REEL_POSTER_COUNT } from "@/lib/constants"; import { fetchTMDBMovies } from "@/lib/tmdb-fetch"; interface ReelPoster { tmdb_id: number; poster_path: string; title: string; } // Always-pinned entries that lead the carousel. const PINNED_REEL_POSTERS: ReelPoster[] = [ { tmdb_id: 615, title: "The Passion of the Christ", poster_path: "/rBM5o2HpmCfDejuIPybI09tkY3V.jpg", }, ]; // Fallback: fetch popular movies for reel posters. // In production, the cron job populates the landing_reel_posters table. export async function GET() { try { const params = new URLSearchParams({ language: "en-US", page: "1", include_adult: "false", }); const { movies, error, status } = await fetchTMDBMovies("/movie/popular", params); if (error) { return NextResponse.json({ error }, { status: status ?? 502 }); } const popular: ReelPoster[] = movies.map((m) => ({ tmdb_id: m.id, poster_path: m.poster_path!, title: m.title, })); const seen = new Set(); const posters: ReelPoster[] = []; for (const p of [...PINNED_REEL_POSTERS, ...popular]) { if (seen.has(p.tmdb_id)) continue; seen.add(p.tmdb_id); posters.push(p); if (posters.length >= REEL_POSTER_COUNT) break; } return NextResponse.json({ posters }); } catch { return NextResponse.json({ error: "Internal server error" }, { status: 500 }); } }