Add TMDB image caching pipeline and resolve image URLs server-side

Introduce a local disk cache for TMDB images served through a proxy API
route (/api/images/[...path]), eliminating direct client-side CDN
dependencies. Images are cached by category (posters, backdrops, stills,
logos) and served with immutable cache headers.

Move all tmdbImageUrl() calls from client components to API routes and
server components so clients receive ready-to-use URLs. This removes the
need to expose TMDB_IMAGE_BASE_URL and IMAGE_CACHE_ENABLED via
next.config.ts env block. The landing page is split into a server
wrapper (app/page.tsx) and client component (components/landing-page.tsx).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-02 13:10:17 -05:00
co-authored by Claude Opus 4.6
parent cb0f366d44
commit ee723e41d6
27 changed files with 665 additions and 242 deletions
+19 -3
View File
@@ -1,7 +1,13 @@
import path from "node:path";
import { eq } from "drizzle-orm";
import { Vibrant } from "node-vibrant/node";
import { db } from "@/lib/db/client";
import { titles } from "@/lib/db/schema";
import {
getLocalImagePath,
imageCacheEnabled,
isImageCached,
} from "@/lib/services/image-cache";
import { tmdbImageUrl } from "@/lib/tmdb/image";
export interface ColorPalette {
@@ -17,11 +23,21 @@ export async function extractAndStoreColors(
titleId: string,
posterPath: string | null,
): Promise<ColorPalette | null> {
const url = tmdbImageUrl(posterPath, "w300");
if (!url) return null;
if (!posterPath) return null;
// Prefer local file when image cache is active
let source: string;
const filename = path.basename(posterPath);
if (imageCacheEnabled() && isImageCached("posters", filename)) {
source = getLocalImagePath("posters", filename);
} else {
const url = tmdbImageUrl(posterPath, "w300");
if (!url) return null;
source = url;
}
try {
const palette = await Vibrant.from(url).getPalette();
const palette = await Vibrant.from(source).getPalette();
const colors: ColorPalette = {
vibrant: palette.Vibrant?.hex ?? null,