mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 02:45:39 -04:00
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>
27 lines
718 B
TypeScript
27 lines
718 B
TypeScript
import type { ImageCategory } from "@/lib/services/image-cache";
|
|
|
|
const IMAGE_BASE_URL =
|
|
process.env.TMDB_IMAGE_BASE_URL || "https://image.tmdb.org/t/p";
|
|
|
|
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;
|
|
|
|
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}`;
|
|
}
|