mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
apply suggested changes from code review
This commit is contained in:
parent
2b547f5a53
commit
5d6756778b
3 changed files with 13 additions and 13 deletions
|
@ -14,7 +14,7 @@ import alert from '../alert';
|
||||||
import { PluginType } from '../../types/plugin.ts';
|
import { PluginType } from '../../types/plugin.ts';
|
||||||
import { includesAny } from '../../utils/container.ts';
|
import { includesAny } from '../../utils/container.ts';
|
||||||
import { getItems } from '../../utils/jellyfin-apiclient/getItems.ts';
|
import { getItems } from '../../utils/jellyfin-apiclient/getItems.ts';
|
||||||
import { getItemBackdropImageUrl } from '../../utils/jellyfin-apiclient/BackdropImage';
|
import { getItemBackdropImageUrl } from '../../utils/jellyfin-apiclient/backdropImage';
|
||||||
|
|
||||||
const UNLIMITED_ITEMS = -1;
|
const UNLIMITED_ITEMS = -1;
|
||||||
|
|
||||||
|
@ -2672,7 +2672,7 @@ class PlaybackManager {
|
||||||
title: item.Name
|
title: item.Name
|
||||||
};
|
};
|
||||||
|
|
||||||
const backdropUrl = getItemBackdropImageUrl(apiClient, item, true);
|
const backdropUrl = getItemBackdropImageUrl(apiClient, item, {}, true);
|
||||||
if (backdropUrl) {
|
if (backdropUrl) {
|
||||||
resultInfo.backdropUrl = backdropUrl;
|
resultInfo.backdropUrl = backdropUrl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ import Dashboard from '../../utils/dashboard';
|
||||||
import ServerConnections from '../../components/ServerConnections';
|
import ServerConnections from '../../components/ServerConnections';
|
||||||
import confirm from '../../components/confirm/confirm';
|
import confirm from '../../components/confirm/confirm';
|
||||||
import { download } from '../../scripts/fileDownloader';
|
import { download } from '../../scripts/fileDownloader';
|
||||||
import { getItemBackdropImageUrl } from '../../utils/jellyfin-apiclient/BackdropImage';
|
import { getItemBackdropImageUrl } from '../../utils/jellyfin-apiclient/backdropImage';
|
||||||
|
|
||||||
function autoFocus(container) {
|
function autoFocus(container) {
|
||||||
import('../../components/autoFocuser').then(({ default: autoFocuser }) => {
|
import('../../components/autoFocuser').then(({ default: autoFocuser }) => {
|
||||||
|
@ -505,7 +505,7 @@ function renderDetailPageBackdrop(page, item, apiClient) {
|
||||||
let hasbackdrop = false;
|
let hasbackdrop = false;
|
||||||
const itemBackdropElement = page.querySelector('#itemBackdrop');
|
const itemBackdropElement = page.querySelector('#itemBackdrop');
|
||||||
|
|
||||||
const imgUrl = getItemBackdropImageUrl(apiClient, item, false, { maxWitdh: dom.getScreenWidth() });
|
const imgUrl = getItemBackdropImageUrl(apiClient, item, { maxWitdh: dom.getScreenWidth() }, false);
|
||||||
|
|
||||||
if (imgUrl) {
|
if (imgUrl) {
|
||||||
imageLoader.lazyImage(itemBackdropElement, imgUrl);
|
imageLoader.lazyImage(itemBackdropElement, imgUrl);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { BaseItemDto } from '@jellyfin/sdk/lib/generated-client';
|
import type { BaseItemDto } from '@jellyfin/sdk/lib/generated-client/models/base-item-dto';
|
||||||
|
import type { ApiClient } from 'jellyfin-apiclient';
|
||||||
|
import { ImageType } from '@jellyfin/sdk/lib/generated-client/models/image-type';
|
||||||
import { randomInt } from '../number';
|
import { randomInt } from '../number';
|
||||||
import { ApiClient } from 'jellyfin-apiclient';
|
|
||||||
|
|
||||||
export interface ScaleImageOptions {
|
export interface ScaleImageOptions {
|
||||||
maxWidth?: number;
|
maxWidth?: number;
|
||||||
|
@ -19,15 +20,15 @@ export interface ScaleImageOptions {
|
||||||
* Returns undefined if no usable image was found.
|
* Returns undefined if no usable image was found.
|
||||||
* @param apiClient The ApiClient to generate the url.
|
* @param apiClient The ApiClient to generate the url.
|
||||||
* @param item The item for which the backdrop image is requested.
|
* @param item The item for which the backdrop image is requested.
|
||||||
* @param random If set to true and the item has more than one backdrop, a random image is returned.
|
|
||||||
* @param options Optional; allows to scale the backdrop image.
|
* @param options Optional; allows to scale the backdrop image.
|
||||||
|
* @param random If set to true and the item has more than one backdrop, a random image is returned.
|
||||||
* @returns The url of the first or a random backdrop image of the provided item.
|
* @returns The url of the first or a random backdrop image of the provided item.
|
||||||
*/
|
*/
|
||||||
export const getItemBackdropImageUrl = (apiClient: ApiClient, item: BaseItemDto, random = false, options: ScaleImageOptions = {}): string | undefined => {
|
export const getItemBackdropImageUrl = (apiClient: ApiClient, item: BaseItemDto, options: ScaleImageOptions = {}, random = false): string | undefined => {
|
||||||
if (item.Id && item.BackdropImageTags?.length) {
|
if (item.Id && item.BackdropImageTags?.length) {
|
||||||
const backdropImgIndex = random ? randomInt(0, item.BackdropImageTags.length - 1) : 0;
|
const backdropImgIndex = random ? randomInt(0, item.BackdropImageTags.length - 1) : 0;
|
||||||
return apiClient.getScaledImageUrl(item.Id, {
|
return apiClient.getScaledImageUrl(item.Id, {
|
||||||
type: 'Backdrop',
|
type: ImageType.Backdrop,
|
||||||
index: backdropImgIndex,
|
index: backdropImgIndex,
|
||||||
tag: item.BackdropImageTags[backdropImgIndex],
|
tag: item.BackdropImageTags[backdropImgIndex],
|
||||||
...options
|
...options
|
||||||
|
@ -35,18 +36,17 @@ export const getItemBackdropImageUrl = (apiClient: ApiClient, item: BaseItemDto,
|
||||||
} else if (item.ParentBackdropItemId && item.ParentBackdropImageTags?.length) {
|
} else if (item.ParentBackdropItemId && item.ParentBackdropImageTags?.length) {
|
||||||
const backdropImgIndex = random ? randomInt(0, item.ParentBackdropImageTags.length - 1) : 0;
|
const backdropImgIndex = random ? randomInt(0, item.ParentBackdropImageTags.length - 1) : 0;
|
||||||
return apiClient.getScaledImageUrl(item.ParentBackdropItemId, {
|
return apiClient.getScaledImageUrl(item.ParentBackdropItemId, {
|
||||||
type: 'Backdrop',
|
type: ImageType.Backdrop,
|
||||||
index: backdropImgIndex,
|
index: backdropImgIndex,
|
||||||
tag: item.ParentBackdropImageTags[backdropImgIndex],
|
tag: item.ParentBackdropImageTags[backdropImgIndex],
|
||||||
...options
|
...options
|
||||||
});
|
});
|
||||||
} else if (item.Id && item.ImageTags?.Primary) {
|
} else if (item.Id && item.ImageTags?.Primary) {
|
||||||
return apiClient.getScaledImageUrl(item.Id, {
|
return apiClient.getScaledImageUrl(item.Id, {
|
||||||
type: 'Primary',
|
type: ImageType.Primary,
|
||||||
tag: item.ImageTags.Primary,
|
tag: item.ImageTags.Primary,
|
||||||
...options
|
...options
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
return undefined;
|
||||||
};
|
};
|
Loading…
Add table
Add a link
Reference in a new issue