Skip to content

Commit

Permalink
Manually fix remaining tseslint stylistic type checked issues
Browse files Browse the repository at this point in the history
  • Loading branch information
3flex committed Oct 30, 2024
1 parent d9f2311 commit 17be9f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/components/documentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ export abstract class DocumentManager {
private static setGenres(name: string | null): void {
const element = this.querySelector('.genres');

element.innerHTML = name || '';
element.innerHTML = name ?? '';
}

/**
Expand All @@ -555,7 +555,7 @@ export abstract class DocumentManager {
private static setOverview(name: string | null): void {
const element = this.querySelector('.overview');

element.innerHTML = name || '';
element.innerHTML = name ?? '';
}

/**
Expand Down
30 changes: 13 additions & 17 deletions src/components/maincontroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,11 @@ export function setSubtitleStreamIndex(
let positionTicks;

// FIXME: Possible index error when MediaStreams is undefined.
const currentSubtitleStream = state.mediaSource?.MediaStreams?.filter(
const currentSubtitleStream = state.mediaSource?.MediaStreams?.find(
(m: MediaStream) => {
return m.Index == state.subtitleStreamIndex && m.Type == 'Subtitle';
}
)[0];
);

const currentDeliveryMethod = currentSubtitleStream
? currentSubtitleStream.DeliveryMethod
Expand Down Expand Up @@ -515,17 +515,12 @@ export async function changeStream(

// @ts-expect-error is possible here
return await PlaybackManager.playItemInternal(state.item, {
audioStreamIndex:
params.AudioStreamIndex == null
? state.audioStreamIndex
: params.AudioStreamIndex,
audioStreamIndex: params.AudioStreamIndex ?? state.audioStreamIndex,
liveStreamId: state.liveStreamId,
mediaSourceId: state.mediaSourceId,
startPositionTicks: ticks,
subtitleStreamIndex:
params.SubtitleStreamIndex == null
? state.subtitleStreamIndex
: params.SubtitleStreamIndex
params.SubtitleStreamIndex ?? state.subtitleStreamIndex
});
}

Expand Down Expand Up @@ -704,24 +699,25 @@ export function showPlaybackInfoErrorMessage(error: string): void {
*/
export function getOptimalMediaSource(
versions: MediaSourceInfo[]
): MediaSourceInfo {
let optimalVersion = versions.filter((v) => {
): MediaSourceInfo | null {
let optimalVersion = versions.find((v) => {
checkDirectPlay(v);

return v.SupportsDirectPlay;
})[0];
});

if (!optimalVersion) {
optimalVersion = versions.filter((v) => {
optimalVersion = versions.find((v) => {
return v.SupportsDirectStream;
})[0];
});
}

return (
optimalVersion ||
versions.filter((s) => {
optimalVersion ??
versions.find((s) => {
return s.SupportsTranscoding;
})[0]
}) ??
null
);
}

Expand Down
30 changes: 15 additions & 15 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ export function getSenderReportingData(
const nowPlayingItem = state.NowPlayingItem;

nowPlayingItem.ServerId = item.ServerId;
nowPlayingItem.Chapters = item.Chapters || [];
nowPlayingItem.Chapters = item.Chapters ?? [];

const mediaSource = item.MediaSources?.filter((m: MediaSourceInfo) => {
const mediaSource = item.MediaSources?.find((m: MediaSourceInfo) => {
return m.Id == reportingData.MediaSourceId;
})[0];
});

nowPlayingItem.MediaStreams = mediaSource
? mediaSource.MediaStreams
Expand All @@ -116,7 +116,7 @@ export function getSenderReportingData(
nowPlayingItem.Album = item.Album;
nowPlayingItem.Artists = item.Artists;

const imageTags = item.ImageTags || {};
const imageTags = item.ImageTags ?? {};

if (item.SeriesPrimaryImageTag) {
nowPlayingItem.PrimaryImageItemId = item.SeriesId;
Expand Down Expand Up @@ -235,9 +235,9 @@ export function getMetadata(item: BaseItemDto): any {
}

// previously: p.PersonType == 'Type'.. wtf?
const composer = (item.People || []).filter(
const composer = (item.People ?? []).find(
(p: BaseItemPerson) => p.Type == 'Composer'
)[0];
);

if (composer) {
metadata.composer = composer.Name;
Expand Down Expand Up @@ -322,14 +322,14 @@ export function createStreamInfo(
`videos/${item.Id}/stream.${mediaSource.Container}?mediaSourceId=${mediaSource.Id}&api_key=${JellyfinApi.accessToken}&static=true${seekParam}`
);
isStatic = true;
playerStartPositionTicks = startPosition || 0;
playerStartPositionTicks = startPosition ?? 0;
} else {
// TODO deal with !TranscodingUrl
mediaUrl = JellyfinApi.createUrl(mediaSource.TranscodingUrl!);

Check failure on line 328 in src/helpers.ts

View workflow job for this annotation

GitHub Actions / Lint TS and CSS

Forbidden non-null assertion

if (isHlsStream(mediaSource)) {
mediaUrl += seekParam;
playerStartPositionTicks = startPosition || 0;
playerStartPositionTicks = startPosition ?? 0;
contentType = 'application/x-mpegURL';
streamContainer = 'm3u8';
} else {
Expand All @@ -347,13 +347,13 @@ export function createStreamInfo(
if (mediaSource.SupportsDirectPlay) {
mediaUrl = mediaSource.Path;
isStatic = true;
playerStartPositionTicks = startPosition || 0;
playerStartPositionTicks = startPosition ?? 0;
} else {
const isDirectStream = mediaSource.SupportsDirectStream;

if (isDirectStream) {
const outputContainer = (
mediaSource.Container || ''
mediaSource.Container ?? ''
).toLowerCase();

mediaUrl = JellyfinApi.createUrl(
Expand All @@ -372,7 +372,7 @@ export function createStreamInfo(

// TODO: Remove the second half of the expression by supporting changing the mediaElement src dynamically.
// It is a pain and will require unbinding all event handlers during the operation
const canSeek = (mediaSource.RunTimeTicks || 0) > 0;
const canSeek = (mediaSource.RunTimeTicks ?? 0) > 0;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const info: any = {
Expand Down Expand Up @@ -445,9 +445,9 @@ export function getStreamByIndex(
index: number
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): any {
return streams.filter((s) => {
return streams.find((s) => {
return s.Type == type && s.Index == index;
})[0];
});
}

// defined for use in the 3 next functions
Expand Down Expand Up @@ -550,7 +550,7 @@ export async function getItemsForPlayback(
query: ItemQuery
): Promise<BaseItemDtoQueryResult> {
query.UserId = userId;
query.Limit = query.Limit || 100;
query.Limit = query.Limit ?? 100;
query.Fields = requiredItemFields;
query.ExcludeLocationTypes = 'Virtual';

Expand Down Expand Up @@ -710,7 +710,7 @@ export async function translateRequestedItems(
}
);

episodesResult.TotalRecordCount = episodesResult.Items?.length || 0;
episodesResult.TotalRecordCount = episodesResult.Items?.length ?? 0;

return episodesResult;
}
Expand Down

0 comments on commit 17be9f6

Please sign in to comment.