Skip to content

Commit

Permalink
Merge branch 'axios-authAjaxUser' into fork
Browse files Browse the repository at this point in the history
  • Loading branch information
3flex committed Nov 10, 2024
2 parents a67b4a1 + 09154ad commit b718e31
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
40 changes: 19 additions & 21 deletions src/components/documentManager.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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,
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;

Expand Down
15 changes: 9 additions & 6 deletions src/components/maincontroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -635,12 +635,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;
Expand Down
15 changes: 9 additions & 6 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -607,11 +611,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;
}

/**
Expand Down

0 comments on commit b718e31

Please sign in to comment.