mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 03:55:38 -04:00
feat: generate and display thumbhash blur placeholders for TMDB images
This commit is contained in:
@@ -8,7 +8,7 @@ export type ImageCategory =
|
||||
const IMAGE_BASE_URL =
|
||||
process.env.TMDB_IMAGE_BASE_URL || "https://image.tmdb.org/t/p";
|
||||
|
||||
const CATEGORY_SIZES: Record<ImageCategory, string> = {
|
||||
export const IMAGE_CATEGORY_SIZES: Record<ImageCategory, string> = {
|
||||
posters: "w500",
|
||||
backdrops: "w1280",
|
||||
stills: "w1280",
|
||||
@@ -16,6 +16,16 @@ const CATEGORY_SIZES: Record<ImageCategory, string> = {
|
||||
profiles: "w185",
|
||||
};
|
||||
|
||||
export function tmdbCdnImageUrl(
|
||||
path: string | null,
|
||||
category: ImageCategory,
|
||||
sizeOverride?: string,
|
||||
) {
|
||||
if (!path) return null;
|
||||
const size = sizeOverride ?? IMAGE_CATEGORY_SIZES[category];
|
||||
return `${IMAGE_BASE_URL}/${size}${path}`;
|
||||
}
|
||||
|
||||
export function tmdbImageUrl(
|
||||
path: string | null,
|
||||
category: ImageCategory,
|
||||
@@ -23,10 +33,8 @@ export function tmdbImageUrl(
|
||||
) {
|
||||
if (!path) return null;
|
||||
|
||||
const size = sizeOverride ?? CATEGORY_SIZES[category];
|
||||
|
||||
if (process.env.IMAGE_CACHE_ENABLED === "false") {
|
||||
return `${IMAGE_BASE_URL}/${size}${path}`;
|
||||
return tmdbCdnImageUrl(path, category, sizeOverride);
|
||||
}
|
||||
|
||||
const filename = path.startsWith("/") ? path.slice(1) : path;
|
||||
|
||||
Reference in New Issue
Block a user