Files
sofa/lib/tmdb/image.ts
T
jake ad8ec62317 Refactor tmdbImageUrl to accept semantic category instead of size string
- 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
2026-03-08 12:33:07 -04:00

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}`;
}