From f1058893674f10a628561c49268a1bcd36b97eb2 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sun, 10 Nov 2024 10:08:38 +1100 Subject: [PATCH 1/4] Migrate showItemId to jellyfin-sdk-typescript --- src/components/documentManager.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/documentManager.ts b/src/components/documentManager.ts index 598b56e5..0d86a373 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 { 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); } /** From 478e7c80aedf15d595c61e45b7938fb5e925c25e Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sun, 10 Nov 2024 10:37:35 +1100 Subject: [PATCH 2/4] Migrate setRandomUserBackdrop to jellyfin-sdk-typescript --- src/components/documentManager.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/components/documentManager.ts b/src/components/documentManager.ts index 0d86a373..de3d47f6 100644 --- a/src/components/documentManager.ts +++ b/src/components/documentManager.ts @@ -1,5 +1,5 @@ import type { BaseItemDto } from '@jellyfin/sdk/lib/generated-client'; -import { getUserLibraryApi } from '@jellyfin/sdk/lib/utils/api'; +import { getItemsApi, getUserLibraryApi } from '@jellyfin/sdk/lib/utils/api'; import { AppStatus } from '../types/appStatus'; import { parseISO8601Date, TicksPerSecond, ticksToSeconds } from '../helpers'; import { JellyfinApi } from './jellyfinApi'; @@ -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; From f177c2610425a3ea141e0b8f0df85a4ab961ff64 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sun, 10 Nov 2024 11:59:24 +1100 Subject: [PATCH 3/4] Migrate onStopPlayerBeforePlaybackDone to jellyfin-sdk-typescript --- src/components/maincontroller.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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; From 09154adee8b86479be67860e33f9017b75c8fa6d Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sun, 10 Nov 2024 12:01:40 +1100 Subject: [PATCH 4/4] Migrate getUser to jellyfin-sdk-typescript --- src/helpers.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index 392ed439..ad149377 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -8,7 +8,7 @@ import type { TvShowsApiGetEpisodesRequest, UserDto } from '@jellyfin/sdk/lib/generated-client'; -import { getTvShowsApi } from '@jellyfin/sdk/lib/utils/api'; +import { getTvShowsApi, getUserApi } from '@jellyfin/sdk/lib/utils/api'; import { JellyfinApi } from './components/jellyfinApi'; import { PlaybackManager, PlaybackState } from './components/playbackManager'; import { BusMessage, ItemQuery } from './types/global'; @@ -613,11 +613,10 @@ export function getIntros( * 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; } /**