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
+21 -2
View File
@@ -1,7 +1,26 @@
import type { ImageCategory } from "@/lib/services/image-cache";
const IMAGE_BASE_URL =
process.env.TMDB_IMAGE_BASE_URL || "https://image.tmdb.org/t/p";
export function tmdbImageUrl(path: string | null, size = "w500") {
function sizeToCategory(size: string): ImageCategory {
if (size === "w92") return "logos";
if (size === "w1280") return "backdrops";
return "posters";
}
export function tmdbImageUrl(
path: string | null,
size = "w500",
category?: ImageCategory,
) {
if (!path) return null;
return `${IMAGE_BASE_URL}/${size}${path}`;
if (process.env.IMAGE_CACHE_ENABLED === "false") {
return `${IMAGE_BASE_URL}/${size}${path}`;
}
const resolved = category ?? sizeToCategory(size);
const filename = path.startsWith("/") ? path.slice(1) : path;
return `/api/images/${resolved}/${filename}`;
}