Serve compact TMDB image sizes on home so posters and heroes download faster.
This commit is contained in:
parent
da7b5df51f
commit
21efba1af1
2 changed files with 51 additions and 5 deletions
42
apps/master-api/src/viewer/image-urls.ts
Normal file
42
apps/master-api/src/viewer/image-urls.ts
Normal file
|
|
@ -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<T extends WithImages>(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) } : {}),
|
||||
};
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue