mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 02:45:39 -04:00
- Change primary argument from TMDB size string (`w500`, `w1280`, etc.) to category name (`posters`, `backdrops`, `stills`, `logos`, `profiles`); optional size override remains as third argument - Update all call sites across services, actions, pages, and route handlers to use the new category-based API - Update image.test.ts to match the new signature and replace size-mapping test descriptions with category-name descriptions
30 lines
726 B
TypeScript
30 lines
726 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";
|
|
|
|
const CATEGORY_SIZES: Record<ImageCategory, string> = {
|
|
posters: "w500",
|
|
backdrops: "w1280",
|
|
stills: "w1280",
|
|
logos: "w92",
|
|
profiles: "w185",
|
|
};
|
|
|
|
export function tmdbImageUrl(
|
|
path: string | null,
|
|
category: ImageCategory,
|
|
sizeOverride?: string,
|
|
) {
|
|
if (!path) return null;
|
|
|
|
const size = sizeOverride ?? CATEGORY_SIZES[category];
|
|
|
|
if (process.env.IMAGE_CACHE_ENABLED === "false") {
|
|
return `${IMAGE_BASE_URL}/${size}${path}`;
|
|
}
|
|
|
|
const filename = path.startsWith("/") ? path.slice(1) : path;
|
|
return `/api/images/${category}/${filename}`;
|
|
}
|