mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Replace existence check with optional chaining (#5742)
This commit is contained in:
parent
cc22fbc042
commit
1da9b548ac
10 changed files with 21 additions and 21 deletions
|
@ -178,7 +178,7 @@ function getItemImageUrls(item, imageOptions) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.ParentBackdropItemId && item.ParentBackdropImageTags && item.ParentBackdropImageTags.length) {
|
if (item.ParentBackdropItemId && item.ParentBackdropImageTags?.length) {
|
||||||
return item.ParentBackdropImageTags.map((imgTag, index) => {
|
return item.ParentBackdropImageTags.map((imgTag, index) => {
|
||||||
return apiClient.getScaledImageUrl(item.ParentBackdropItemId, Object.assign(imageOptions, {
|
return apiClient.getScaledImageUrl(item.ParentBackdropItemId, Object.assign(imageOptions, {
|
||||||
type: 'Backdrop',
|
type: 'Backdrop',
|
||||||
|
|
|
@ -277,16 +277,16 @@ export function getCardImageUrl(item, apiClient, options, shape) {
|
||||||
let itemId = null;
|
let itemId = null;
|
||||||
|
|
||||||
/* eslint-disable sonarjs/no-duplicated-branches */
|
/* eslint-disable sonarjs/no-duplicated-branches */
|
||||||
if (options.preferThumb && item.ImageTags && item.ImageTags.Thumb) {
|
if (options.preferThumb && item.ImageTags?.Thumb) {
|
||||||
imgType = 'Thumb';
|
imgType = 'Thumb';
|
||||||
imgTag = item.ImageTags.Thumb;
|
imgTag = item.ImageTags.Thumb;
|
||||||
} else if ((options.preferBanner || shape === 'banner') && item.ImageTags && item.ImageTags.Banner) {
|
} else if ((options.preferBanner || shape === 'banner') && item.ImageTags?.Banner) {
|
||||||
imgType = 'Banner';
|
imgType = 'Banner';
|
||||||
imgTag = item.ImageTags.Banner;
|
imgTag = item.ImageTags.Banner;
|
||||||
} else if (options.preferDisc && item.ImageTags && item.ImageTags.Disc) {
|
} else if (options.preferDisc && item.ImageTags?.Disc) {
|
||||||
imgType = 'Disc';
|
imgType = 'Disc';
|
||||||
imgTag = item.ImageTags.Disc;
|
imgTag = item.ImageTags.Disc;
|
||||||
} else if (options.preferLogo && item.ImageTags && item.ImageTags.Logo) {
|
} else if (options.preferLogo && item.ImageTags?.Logo) {
|
||||||
imgType = 'Logo';
|
imgType = 'Logo';
|
||||||
imgTag = item.ImageTags.Logo;
|
imgTag = item.ImageTags.Logo;
|
||||||
} else if (options.preferLogo && item.ParentLogoImageTag && item.ParentLogoItemId) {
|
} else if (options.preferLogo && item.ParentLogoImageTag && item.ParentLogoItemId) {
|
||||||
|
@ -301,11 +301,11 @@ export function getCardImageUrl(item, apiClient, options, shape) {
|
||||||
imgType = 'Thumb';
|
imgType = 'Thumb';
|
||||||
imgTag = item.ParentThumbImageTag;
|
imgTag = item.ParentThumbImageTag;
|
||||||
itemId = item.ParentThumbItemId;
|
itemId = item.ParentThumbItemId;
|
||||||
} else if (options.preferThumb && item.BackdropImageTags && item.BackdropImageTags.length) {
|
} else if (options.preferThumb && item.BackdropImageTags?.length) {
|
||||||
imgType = 'Backdrop';
|
imgType = 'Backdrop';
|
||||||
imgTag = item.BackdropImageTags[0];
|
imgTag = item.BackdropImageTags[0];
|
||||||
forceName = true;
|
forceName = true;
|
||||||
} else if (options.preferThumb && item.ParentBackdropImageTags && item.ParentBackdropImageTags.length && options.inheritThumb !== false && item.Type === 'Episode') {
|
} else if (options.preferThumb && item.ParentBackdropImageTags?.length && options.inheritThumb !== false && item.Type === 'Episode') {
|
||||||
imgType = 'Backdrop';
|
imgType = 'Backdrop';
|
||||||
imgTag = item.ParentBackdropImageTags[0];
|
imgTag = item.ParentBackdropImageTags[0];
|
||||||
itemId = item.ParentBackdropItemId;
|
itemId = item.ParentBackdropItemId;
|
||||||
|
@ -351,7 +351,7 @@ export function getCardImageUrl(item, apiClient, options, shape) {
|
||||||
if (primaryImageAspectRatio && uiAspect) {
|
if (primaryImageAspectRatio && uiAspect) {
|
||||||
coverImage = (Math.abs(primaryImageAspectRatio - uiAspect) / uiAspect) <= 0.2;
|
coverImage = (Math.abs(primaryImageAspectRatio - uiAspect) / uiAspect) <= 0.2;
|
||||||
}
|
}
|
||||||
} else if (item.Type === 'Season' && item.ImageTags && item.ImageTags.Thumb) {
|
} else if (item.Type === 'Season' && item.ImageTags?.Thumb) {
|
||||||
imgType = 'Thumb';
|
imgType = 'Thumb';
|
||||||
imgTag = item.ImageTags.Thumb;
|
imgTag = item.ImageTags.Thumb;
|
||||||
} else if (item.BackdropImageTags?.length) {
|
} else if (item.BackdropImageTags?.length) {
|
||||||
|
@ -571,7 +571,7 @@ function getCardFooterText(item, apiClient, options, footerClass, progressHtml,
|
||||||
|
|
||||||
if (showOtherText) {
|
if (showOtherText) {
|
||||||
if (options.showParentTitle && parentTitleUnderneath) {
|
if (options.showParentTitle && parentTitleUnderneath) {
|
||||||
if (flags.isOuterFooter && item.AlbumArtists && item.AlbumArtists.length) {
|
if (flags.isOuterFooter && item.AlbumArtists?.length) {
|
||||||
item.AlbumArtists[0].Type = 'MusicArtist';
|
item.AlbumArtists[0].Type = 'MusicArtist';
|
||||||
item.AlbumArtists[0].IsFolder = true;
|
item.AlbumArtists[0].IsFolder = true;
|
||||||
lines.push(getTextActionButton(item.AlbumArtists[0], null, serverId));
|
lines.push(getTextActionButton(item.AlbumArtists[0], null, serverId));
|
||||||
|
|
|
@ -152,7 +152,7 @@ export function seekOnPlaybackStart(instance, element, ticks, onMediaReady) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function applySrc(elem, src, options) {
|
export function applySrc(elem, src, options) {
|
||||||
if (window.Windows && options.mediaSource && options.mediaSource.IsLocal) {
|
if (window.Windows && options.mediaSource?.IsLocal) {
|
||||||
return Windows.Storage.StorageFile.getFileFromPathAsync(options.url).then(function (file) {
|
return Windows.Storage.StorageFile.getFileFromPathAsync(options.url).then(function (file) {
|
||||||
const playlist = new Windows.Media.Playback.MediaPlaybackList();
|
const playlist = new Windows.Media.Playback.MediaPlaybackList();
|
||||||
|
|
||||||
|
|
|
@ -316,7 +316,7 @@ export function getCommands(options) {
|
||||||
}
|
}
|
||||||
// Show Album Artist by default, as a song can have multiple artists, which specific one would this option refer to?
|
// Show Album Artist by default, as a song can have multiple artists, which specific one would this option refer to?
|
||||||
// Although some albums can have multiple artists, it's not as common as songs.
|
// Although some albums can have multiple artists, it's not as common as songs.
|
||||||
if (options.openArtist !== false && item.AlbumArtists && item.AlbumArtists.length) {
|
if (options.openArtist !== false && item.AlbumArtists?.length) {
|
||||||
commands.push({
|
commands.push({
|
||||||
name: globalize.translate('ViewAlbumArtist'),
|
name: globalize.translate('ViewAlbumArtist'),
|
||||||
id: 'artist',
|
id: 'artist',
|
||||||
|
@ -609,7 +609,7 @@ function play(item, resume, queue, queueNext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let startPosition = 0;
|
let startPosition = 0;
|
||||||
if (resume && item.UserData && item.UserData.PlaybackPositionTicks) {
|
if (resume && item.UserData?.PlaybackPositionTicks) {
|
||||||
startPosition = item.UserData.PlaybackPositionTicks;
|
startPosition = item.UserData.PlaybackPositionTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ function getMediaSourceHtml(user, item, version) {
|
||||||
if (version.Formats?.length) {
|
if (version.Formats?.length) {
|
||||||
html += `${createAttribute(globalize.translate('MediaInfoFormat'), version.Formats.join(','))}<br/>`;
|
html += `${createAttribute(globalize.translate('MediaInfoFormat'), version.Formats.join(','))}<br/>`;
|
||||||
}
|
}
|
||||||
if (version.Path && user && user.Policy.IsAdministrator) {
|
if (version.Path && user?.Policy.IsAdministrator) {
|
||||||
html += `${createAttribute(globalize.translate('MediaInfoPath'), version.Path, true)}<br/>`;
|
html += `${createAttribute(globalize.translate('MediaInfoPath'), version.Path, true)}<br/>`;
|
||||||
}
|
}
|
||||||
if (version.Size) {
|
if (version.Size) {
|
||||||
|
|
|
@ -737,12 +737,12 @@ export default function () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
context.querySelector('.btnAudioTracks').addEventListener('click', function (e) {
|
context.querySelector('.btnAudioTracks').addEventListener('click', function (e) {
|
||||||
if (currentPlayer && lastPlayerState && lastPlayerState.NowPlayingItem) {
|
if (currentPlayer && lastPlayerState?.NowPlayingItem) {
|
||||||
showAudioMenu(context, currentPlayer, e.target);
|
showAudioMenu(context, currentPlayer, e.target);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
context.querySelector('.btnSubtitles').addEventListener('click', function (e) {
|
context.querySelector('.btnSubtitles').addEventListener('click', function (e) {
|
||||||
if (currentPlayer && lastPlayerState && lastPlayerState.NowPlayingItem) {
|
if (currentPlayer && lastPlayerState?.NowPlayingItem) {
|
||||||
showSubtitleMenu(context, currentPlayer, e.target);
|
showSubtitleMenu(context, currentPlayer, e.target);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -92,7 +92,7 @@ function getImgUrl(item, user) {
|
||||||
if (item.BackdropImageTags?.length) {
|
if (item.BackdropImageTags?.length) {
|
||||||
return getBackdropImageUrl(item, imageOptions, apiClient);
|
return getBackdropImageUrl(item, imageOptions, apiClient);
|
||||||
} else {
|
} else {
|
||||||
if (item.MediaType === 'Photo' && user && user.Policy.EnableContentDownloading) {
|
if (item.MediaType === 'Photo' && user?.Policy.EnableContentDownloading) {
|
||||||
return apiClient.getItemDownloadUrl(item.Id);
|
return apiClient.getItemDownloadUrl(item.Id);
|
||||||
}
|
}
|
||||||
imageOptions.type = 'Primary';
|
imageOptions.type = 'Primary';
|
||||||
|
@ -171,7 +171,7 @@ export default function (options) {
|
||||||
if (actionButtonsOnTop) {
|
if (actionButtonsOnTop) {
|
||||||
html += getIcon('play_arrow', 'btnSlideshowPause slideshowButton', true);
|
html += getIcon('play_arrow', 'btnSlideshowPause slideshowButton', true);
|
||||||
|
|
||||||
if (appHost.supports('filedownload') && slideshowOptions.user && slideshowOptions.user.Policy.EnableContentDownloading) {
|
if (appHost.supports('filedownload') && slideshowOptions.user?.Policy.EnableContentDownloading) {
|
||||||
html += getIcon('file_download', 'btnDownload slideshowButton', true);
|
html += getIcon('file_download', 'btnDownload slideshowButton', true);
|
||||||
}
|
}
|
||||||
if (appHost.supports('sharing')) {
|
if (appHost.supports('sharing')) {
|
||||||
|
@ -189,7 +189,7 @@ export default function (options) {
|
||||||
html += '<div class="slideshowBottomBar hide">';
|
html += '<div class="slideshowBottomBar hide">';
|
||||||
|
|
||||||
html += getIcon('play_arrow', 'btnSlideshowPause slideshowButton', true, true);
|
html += getIcon('play_arrow', 'btnSlideshowPause slideshowButton', true, true);
|
||||||
if (appHost.supports('filedownload') && slideshowOptions.user && slideshowOptions.user.Policy.EnableContentDownloading) {
|
if (appHost.supports('filedownload') && slideshowOptions?.user.Policy.EnableContentDownloading) {
|
||||||
html += getIcon('file_download', 'btnDownload slideshowButton', true);
|
html += getIcon('file_download', 'btnDownload slideshowButton', true);
|
||||||
}
|
}
|
||||||
if (appHost.supports('sharing')) {
|
if (appHost.supports('sharing')) {
|
||||||
|
|
|
@ -293,7 +293,7 @@ const scrollerFactory = function (frame, options) {
|
||||||
immediate = true;
|
immediate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!immediate && o.skipSlideToWhenVisible && fullItemPos && fullItemPos.isVisible) {
|
if (!immediate && o.skipSlideToWhenVisible && fullItemPos?.isVisible) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -716,7 +716,7 @@ class ChromecastPlayer {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.items.length > 1 && options && options.ids) {
|
if (options.items.length > 1 && options?.ids) {
|
||||||
// Use the original request id array for sorting the result in the proper order
|
// Use the original request id array for sorting the result in the proper order
|
||||||
options.items.sort(function (a, b) {
|
options.items.sort(function (a, b) {
|
||||||
return options.ids.indexOf(a.Id) - options.ids.indexOf(b.Id);
|
return options.ids.indexOf(a.Id) - options.ids.indexOf(b.Id);
|
||||||
|
|
|
@ -105,7 +105,7 @@ function mergePlaybackQueries(obj1, obj2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function translateItemsForPlayback(apiClient, items, options) {
|
export function translateItemsForPlayback(apiClient, items, options) {
|
||||||
if (items.length > 1 && options && options.ids) {
|
if (items.length > 1 && options?.ids) {
|
||||||
// Use the original request id array for sorting the result in the proper order.
|
// Use the original request id array for sorting the result in the proper order.
|
||||||
items.sort(function (a, b) {
|
items.sort(function (a, b) {
|
||||||
return options.ids.indexOf(a.Id) - options.ids.indexOf(b.Id);
|
return options.ids.indexOf(a.Id) - options.ids.indexOf(b.Id);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue