From 21efba1af1f08a3280d45feeffaa9b1e93b77601 Mon Sep 17 00:00:00 2001 From: Jos Vooges | STH Date: Thu, 17 Sep 2026 04:36:05 +0200 Subject: [PATCH] Serve compact TMDB image sizes on home so posters and heroes download faster. --- apps/master-api/src/viewer/image-urls.ts | 42 ++++++++++++++++++++++++ apps/master-api/src/viewer/service.ts | 14 +++++--- 2 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 apps/master-api/src/viewer/image-urls.ts diff --git a/apps/master-api/src/viewer/image-urls.ts b/apps/master-api/src/viewer/image-urls.ts new file mode 100644 index 0000000..22fa567 --- /dev/null +++ b/apps/master-api/src/viewer/image-urls.ts @@ -0,0 +1,42 @@ +/** TMDB-URL's verkleinen voor lijsten/home — zelfde look op TV, veel minder MB. */ + +export function compactPosterUrl(url: string | null | undefined): string | null { + if (!url) return null; + return url + .replace(/\/t\/p\/original\//g, "/t/p/w342/") + .replace(/\/t\/p\/w780\//g, "/t/p/w342/") + .replace(/\/t\/p\/w500\//g, "/t/p/w342/"); +} + +export function compactBackdropUrl(url: string | null | undefined): string | null { + if (!url) return null; + return url + .replace(/\/t\/p\/original\//g, "/t/p/w1280/") + .replace(/\/t\/p\/w1920\//g, "/t/p/w1280/"); +} + +export function compactLogoUrl(url: string | null | undefined): string | null { + if (!url) return null; + return url + .replace(/\/t\/p\/original\//g, "/t/p/w500/") + .replace(/\/t\/p\/w780\//g, "/t/p/w500/"); +} + +type WithImages = { + posterUrl?: string | null; + backdropUrl?: string | null; + logoUrl?: string | null; +}; + +export function compactListImages(item: T): T { + return { + ...item, + ...(item.posterUrl !== undefined + ? { posterUrl: compactPosterUrl(item.posterUrl) } + : {}), + ...(item.backdropUrl !== undefined + ? { backdropUrl: compactBackdropUrl(item.backdropUrl) } + : {}), + ...(item.logoUrl !== undefined ? { logoUrl: compactLogoUrl(item.logoUrl) } : {}), + }; +} diff --git a/apps/master-api/src/viewer/service.ts b/apps/master-api/src/viewer/service.ts index 9207b7e..9db88d1 100644 --- a/apps/master-api/src/viewer/service.ts +++ b/apps/master-api/src/viewer/service.ts @@ -31,6 +31,7 @@ import { setCachedHome, invalidateHomeForProfile, } from "./home-cache"; +import { compactListImages } from "./image-urls"; const CODE_TTL_MS = 10 * 60 * 1000; const CODE_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"; @@ -794,7 +795,7 @@ export class ViewerService { const [shelfPayloads, favorites] = await Promise.all([ Promise.all( ordered.map(async (shelf) => { - const page = await this.shelfItemsPage(shelf.id, shelf.kind, 0, 48, kidsMode, { + const page = await this.shelfItemsPage(shelf.id, shelf.kind, 0, 24, kidsMode, { sort: "recent", skipTotal: true, }); @@ -819,10 +820,13 @@ export class ViewerService { } const payload = { - continueWatching: continueItems, - spotlight, - shelves: rows, - favorites, + continueWatching: continueItems.map(compactListImages), + spotlight: spotlight.map(compactListImages), + shelves: rows.map((row) => ({ + ...row, + items: row.items.map(compactListImages), + })), + favorites: favorites.map(compactListImages), }; setCachedHome(profileId, kidsMode, payload); return payload;