|
@@ -2,6 +2,21 @@ import { NextResponse } from "next/server";
|
|
|
import { REEL_POSTER_COUNT } from "@/lib/constants";
|
|
import { REEL_POSTER_COUNT } from "@/lib/constants";
|
|
|
import { fetchTMDBMovies } from "@/lib/tmdb-fetch";
|
|
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.
|
|
// Fallback: fetch popular movies for reel posters.
|
|
|
// In production, the cron job populates the landing_reel_posters table.
|
|
// In production, the cron job populates the landing_reel_posters table.
|
|
|
export async function GET() {
|
|
export async function GET() {
|
|
@@ -18,12 +33,21 @@ export async function GET() {
|
|
|
return NextResponse.json({ error }, { status: status ?? 502 });
|
|
return NextResponse.json({ error }, { status: status ?? 502 });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const posters = movies.slice(0, REEL_POSTER_COUNT).map((m) => ({
|
|
|
|
|
|
|
+ const popular: ReelPoster[] = movies.map((m) => ({
|
|
|
tmdb_id: m.id,
|
|
tmdb_id: m.id,
|
|
|
poster_path: m.poster_path!,
|
|
poster_path: m.poster_path!,
|
|
|
title: m.title,
|
|
title: m.title,
|
|
|
}));
|
|
}));
|
|
|
|
|
|
|
|
|
|
+ const seen = new Set<number>();
|
|
|
|
|
+ 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 });
|
|
return NextResponse.json({ posters });
|
|
|
} catch {
|
|
} catch {
|
|
|
return NextResponse.json({ error: "Internal server error" }, { status: 500 });
|
|
return NextResponse.json({ error: "Internal server error" }, { status: 500 });
|