Merge pull request #692 from 3flex/axios-authAjaxUser

Migrate calls to authAjaxUser to jellyfin-sdk-typescript
This commit is contained in:
Niels van Velzen 2024-11-10 12:13:03 +01:00 committed by GitHub
commit 8c99ff424f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 33 deletions

View File

@ -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<void> {
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,
// Although we're limiting to what the user has access to,
// not everyone will want to see adult backdrops rotating on their TV.
maxOfficialRating: 'PG-13',
recursive: true,
sortBy: ['Random']
});
const result = response.data;
let src: string | null = null;
let item: BaseItemDto | null = null;

View File

@ -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,
@ -631,12 +631,15 @@ export async function onStopPlayerBeforePlaybackDone(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
options: any
): Promise<void> {
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;

View File

@ -17,7 +17,8 @@ import type {
import {
getInstantMixApi,
getItemsApi,
getTvShowsApi
getTvShowsApi,
getUserApi
} from '@jellyfin/sdk/lib/utils/api';
import { JellyfinApi } from './components/jellyfinApi';
import { PlaybackManager, PlaybackState } from './components/playbackManager';
@ -593,11 +594,10 @@ export async function getEpisodesForPlayback(
* Get user object for the current user
* @returns user object
*/
export function getUser(): Promise<UserDto> {
return JellyfinApi.authAjaxUser('', {
dataType: 'json',
type: 'GET'
});
export async function getUser(): Promise<UserDto> {
const response = await getUserApi(JellyfinApi.jellyfinApi).getCurrentUser();
return response.data;
}
/**