1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Replace deprecated getItemImageUrl with imageUrlsApi.getItemImageUrlById

This commit is contained in:
grafixeyehero 2024-02-01 19:41:08 +03:00
parent 876fbee53e
commit ed46ee5254
4 changed files with 28 additions and 31 deletions

View file

@ -32,7 +32,7 @@ const CardContent: FC<CardContentProps> = ({
return ( return (
<div <div
className={`${cardContentClass}`} className={cardContentClass}
> >
<CardImageContainer <CardImageContainer
item={item} item={item}

View file

@ -5,6 +5,7 @@ import {
ImageType ImageType
} from '@jellyfin/sdk/lib/generated-client'; } from '@jellyfin/sdk/lib/generated-client';
import { Api } from '@jellyfin/sdk'; import { Api } from '@jellyfin/sdk';
import { getImageApi } from '@jellyfin/sdk/lib/utils/api/image-api';
import escapeHTML from 'escape-html'; import escapeHTML from 'escape-html';
import { appRouter } from 'components/router/appRouter'; import { appRouter } from 'components/router/appRouter';
@ -45,7 +46,7 @@ export function getCardLogoUrl(
} }
if (api && imgTag && imgType && itemId) { if (api && imgTag && imgType && itemId) {
const response = api.getItemImageUrl(itemId, imgType, { const response = getImageApi(api).getItemImageUrlById(itemId, imgType, {
height: logoHeight, height: logoHeight,
tag: imgTag tag: imgTag
}); });

View file

@ -1,12 +1,11 @@
import { BaseItemKind, ImageType } from '@jellyfin/sdk/lib/generated-client'; import { BaseItemKind, ImageType } from '@jellyfin/sdk/lib/generated-client';
import { getImageApi } from '@jellyfin/sdk/lib/utils/api/image-api';
import { useApi } from 'hooks/useApi'; import { useApi } from 'hooks/useApi';
import { getDesiredAspect } from '../cardBuilderUtils'; import { getDesiredAspect } from '../cardBuilderUtils';
import type { ItemDto } from 'types/itemDto'; import type { ItemDto, NullableNumber, NullableString } from 'types/itemDto';
import type { CardOptions } from 'types/cardOptions'; import type { CardOptions } from 'types/cardOptions';
type ShapeType = string | null | undefined;
function getPreferThumbInfo(item: ItemDto, cardOptions: CardOptions) { function getPreferThumbInfo(item: ItemDto, cardOptions: CardOptions) {
let imgType; let imgType;
let itemId; let itemId;
@ -73,11 +72,11 @@ function getPreferLogoInfo(item: ItemDto) {
} }
function getCalculatedHeight( function getCalculatedHeight(
width: number | undefined, itemWidth: NullableNumber,
primaryImageAspectRatio: number | null | undefined itemPrimaryImageAspectRatio: NullableNumber
) { ) {
if (width && primaryImageAspectRatio) { if (itemWidth && itemPrimaryImageAspectRatio) {
return Math.round(width / primaryImageAspectRatio); return Math.round(itemWidth / itemPrimaryImageAspectRatio);
} }
} }
@ -86,20 +85,20 @@ function isForceName(cardOptions: CardOptions) {
} }
function isCoverImage( function isCoverImage(
primaryImageAspectRatio: number | null | undefined, itemPrimaryImageAspectRatio: NullableNumber,
uiAspect: number | null uiAspect: NullableNumber
) { ) {
if (primaryImageAspectRatio && uiAspect) { if (itemPrimaryImageAspectRatio && uiAspect) {
return Math.abs(primaryImageAspectRatio - uiAspect) / uiAspect <= 0.2; return Math.abs(itemPrimaryImageAspectRatio - uiAspect) / uiAspect <= 0.2;
} }
return false; return false;
} }
function shouldShowPreferBanner( function shouldShowPreferBanner(
imageTagsBanner: string | undefined, imageTagsBanner: NullableString,
cardOptions: CardOptions, cardOptions: CardOptions,
shape: ShapeType shape: NullableString
): boolean { ): boolean {
return ( return (
(cardOptions.preferBanner || shape === 'banner') (cardOptions.preferBanner || shape === 'banner')
@ -125,20 +124,20 @@ function shouldShowImageTagsThumb(item: ItemDto): boolean {
} }
function shouldShowSeriesThumbImageTag( function shouldShowSeriesThumbImageTag(
item: ItemDto, itemSeriesThumbImageTag: NullableString,
cardOptions: CardOptions cardOptions: CardOptions
): boolean { ): boolean {
return ( return (
Boolean(item.SeriesThumbImageTag) && cardOptions.inheritThumb !== false Boolean(itemSeriesThumbImageTag) && cardOptions.inheritThumb !== false
); );
} }
function shouldShowParentThumbImageTag( function shouldShowParentThumbImageTag(
item: ItemDto, itemParentThumbItemId: NullableString,
cardOptions: CardOptions cardOptions: CardOptions
): boolean { ): boolean {
return ( return (
Boolean(item.ParentThumbItemId) && cardOptions.inheritThumb !== false Boolean(itemParentThumbItemId) && cardOptions.inheritThumb !== false
); );
} }
@ -146,14 +145,14 @@ function shouldShowParentBackdropImageTags(item: ItemDto): boolean {
return Boolean(item.AlbumId) && Boolean(item.AlbumPrimaryImageTag); return Boolean(item.AlbumId) && Boolean(item.AlbumPrimaryImageTag);
} }
function shouldShowPreferThumb(type: string | null | undefined, cardOptions: CardOptions): boolean { function shouldShowPreferThumb(itemType: NullableString, cardOptions: CardOptions): boolean {
return Boolean(cardOptions.preferThumb) && !(type === BaseItemKind.Program || type === BaseItemKind.Episode); return Boolean(cardOptions.preferThumb) && !(itemType === BaseItemKind.Program || itemType === BaseItemKind.Episode);
} }
function getCardImageInfo( function getCardImageInfo(
item: ItemDto, item: ItemDto,
cardOptions: CardOptions, cardOptions: CardOptions,
shape: ShapeType shape: NullableString
) { ) {
const width = cardOptions.width; const width = cardOptions.width;
let height; let height;
@ -221,15 +220,11 @@ function getCardImageInfo(
imgType = ImageType.Backdrop; imgType = ImageType.Backdrop;
imgTag = item.BackdropImageTags[0]; imgTag = item.BackdropImageTags[0];
itemId = item.Id; itemId = item.Id;
/*} else if (item.ImageTags?.Thumb) { } else if (shouldShowSeriesThumbImageTag(item.SeriesThumbImageTag, cardOptions)) {
imgType = ImageType.Thumb;
imgTag = item.ImageTags.Thumb;
itemId = item.Id;*/
} else if (shouldShowSeriesThumbImageTag(item, cardOptions)) {
imgType = ImageType.Thumb; imgType = ImageType.Thumb;
imgTag = item.SeriesThumbImageTag; imgTag = item.SeriesThumbImageTag;
itemId = item.SeriesId; itemId = item.SeriesId;
} else if (shouldShowParentThumbImageTag(item, cardOptions)) { } else if (shouldShowParentThumbImageTag(item.ParentThumbItemId, cardOptions)) {
imgType = ImageType.Thumb; imgType = ImageType.Thumb;
imgTag = item.ParentThumbImageTag; imgTag = item.ParentThumbImageTag;
itemId = item.ParentThumbItemId; itemId = item.ParentThumbItemId;
@ -256,7 +251,7 @@ function getCardImageInfo(
interface UseCardImageUrlProps { interface UseCardImageUrlProps {
item: ItemDto; item: ItemDto;
cardOptions: CardOptions; cardOptions: CardOptions;
shape: ShapeType; shape: NullableString;
} }
function useCardImageUrl({ item, cardOptions, shape }: UseCardImageUrlProps) { function useCardImageUrl({ item, cardOptions, shape }: UseCardImageUrlProps) {
@ -280,7 +275,7 @@ function useCardImageUrl({ item, cardOptions, shape }: UseCardImageUrlProps) {
if (height) { if (height) {
height = Math.round(height * ratio); height = Math.round(height * ratio);
} }
imgUrl = api?.getItemImageUrl(itemId, imgType, { imgUrl = getImageApi(api).getItemImageUrlById(itemId, imgType, {
quality: 96, quality: 96,
fillWidth: width, fillWidth: width,
fillHeight: height, fillHeight: height,

View file

@ -1,5 +1,6 @@
import { Api } from '@jellyfin/sdk'; import { Api } from '@jellyfin/sdk';
import { BaseItemKind, ImageType } from '@jellyfin/sdk/lib/generated-client'; import { BaseItemKind, ImageType } from '@jellyfin/sdk/lib/generated-client';
import { getImageApi } from '@jellyfin/sdk/lib/utils/api/image-api';
import globalize from 'scripts/globalize'; import globalize from 'scripts/globalize';
import type { ItemDto } from 'types/itemDto'; import type { ItemDto } from 'types/itemDto';
@ -110,7 +111,7 @@ export function getImageUrl(
} }
if (api && imgTag && imgType && itemId) { if (api && imgTag && imgType && itemId) {
const response = api.getItemImageUrl(itemId, imgType, { const response = getImageApi(api).getItemImageUrlById(itemId, imgType, {
fillWidth: fillWidth, fillWidth: fillWidth,
fillHeight: fillHeight, fillHeight: fillHeight,
tag: imgTag tag: imgTag