diff --git a/src/components/documentManager.ts b/src/components/documentManager.ts index 598b56e5..de3d47f6 100644 --- a/src/components/documentManager.ts +++ b/src/components/documentManager.ts @@ -1,4 +1,5 @@ import type { BaseItemDto } from '@jellyfin/sdk/lib/generated-client'; +import { getItemsApi, getUserLibraryApi } from '@jellyfin/sdk/lib/utils/api'; import { AppStatus } from '../types/appStatus'; import { parseISO8601Date, TicksPerSecond, ticksToSeconds } from '../helpers'; import { JellyfinApi } from './jellyfinApi'; @@ -223,15 +224,14 @@ export abstract class DocumentManager { return; } - const item: BaseItemDto = await JellyfinApi.authAjaxUser( - `Items/${itemId}`, - { - dataType: 'json', - type: 'GET' - } - ); + const response = await getUserLibraryApi( + JellyfinApi.jellyfinApi + ).getItem({ + itemId, + userId: JellyfinApi.userId + }); - DocumentManager.showItem(item); + DocumentManager.showItem(response.data); } /** @@ -353,21 +353,19 @@ export abstract class DocumentManager { * @returns promise waiting for the backdrop to be set */ private static async setRandomUserBackdrop(): Promise { - const result = await JellyfinApi.authAjaxUser('Items', { - dataType: 'json', - query: { - ImageTypes: 'Backdrop', - IncludeItemTypes: 'Movie,Series', - Limit: 1, - MaxOfficialRating: 'PG-13', - Recursive: true, - SortBy: 'Random' - // Although we're limiting to what the user has access to, - // not everyone will want to see adult backdrops rotating on their TV. - }, - type: 'GET' + const response = await getItemsApi(JellyfinApi.jellyfinApi).getItems({ + imageTypes: ['Backdrop'], + includeItemTypes: ['Movie', 'Series'], + limit: 1, + maxOfficialRating: 'PG-13', + recursive: true, + sortBy: ['Random'] + // Although we're limiting to what the user has access to, + // not everyone will want to see adult backdrops rotating on their TV. }); + const result = response.data; + let src: string | null = null; let item: BaseItemDto | null = null; diff --git a/src/components/maincontroller.ts b/src/components/maincontroller.ts index ca35e943..7137ad3b 100644 --- a/src/components/maincontroller.ts +++ b/src/components/maincontroller.ts @@ -3,7 +3,7 @@ import type { MediaStream, MediaSourceInfo } from '@jellyfin/sdk/lib/generated-client'; -import { getSessionApi } from '@jellyfin/sdk/lib/utils/api'; +import { getSessionApi, getUserLibraryApi } from '@jellyfin/sdk/lib/utils/api'; import { getCurrentPositionTicks, getReportingParams, @@ -635,12 +635,15 @@ export async function onStopPlayerBeforePlaybackDone( // eslint-disable-next-line @typescript-eslint/no-explicit-any options: any ): Promise { - const data = await JellyfinApi.authAjaxUser(`Items/${item.Id}`, { - dataType: 'json', - type: 'GET' - }); + if (item.Id) { + const response = await getUserLibraryApi( + JellyfinApi.jellyfinApi + ).getItem({ + itemId: item.Id + }); - PlaybackManager.playItemInternal(data, options); + PlaybackManager.playItemInternal(response.data, options); + } } let lastBitrateDetect = 0; diff --git a/src/helpers.ts b/src/helpers.ts index c28e11f7..51f20525 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -9,7 +9,11 @@ import type { UserDto, ItemFields } from '@jellyfin/sdk/lib/generated-client'; -import { getItemsApi, getTvShowsApi } from '@jellyfin/sdk/lib/utils/api'; +import { + getItemsApi, + getTvShowsApi, + getUserApi +} from '@jellyfin/sdk/lib/utils/api'; import { ItemsApiGetItemsRequest } from '@jellyfin/sdk/lib/generated-client/api/items-api'; import { JellyfinApi } from './components/jellyfinApi'; import { PlaybackManager, PlaybackState } from './components/playbackManager'; @@ -607,11 +611,10 @@ export async function getEpisodesForPlayback( * Get user object for the current user * @returns user object */ -export function getUser(): Promise { - return JellyfinApi.authAjaxUser('', { - dataType: 'json', - type: 'GET' - }); +export async function getUser(): Promise { + const response = await getUserApi(JellyfinApi.jellyfinApi).getCurrentUser(); + + return response.data; } /**