Skip to content

Commit

Permalink
Remove userId where not required
Browse files Browse the repository at this point in the history
  • Loading branch information
3flex committed Nov 10, 2024
1 parent 81463a8 commit af3db76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
8 changes: 2 additions & 6 deletions src/components/maincontroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,7 @@ export async function translateItems(
): Promise<void> {
const playNow = method != 'PlayNext' && method != 'PlayLast';

const result = await translateRequestedItems(
data.userId,
options.items,
playNow
);
const result = await translateRequestedItems(options.items, playNow);

if (result.Items) {
options.items = result.Items;
Expand Down Expand Up @@ -616,7 +612,7 @@ export async function shuffle(
options: PlayRequest,
item: BaseItemDto
): Promise<void> {
const result = await getShuffleItems(data.userId, item);
const result = await getShuffleItems(item);

options.items = result.Items ?? [];
PlaybackManager.playFromOptions(data.options);
Expand Down
26 changes: 8 additions & 18 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,14 +479,10 @@ const requiredItemFields: ItemFields[] = ['MediaSources', 'Chapters'];
* of the provided one.
*
* It's used only in maincomponents.shuffle.
*
* TODO: JellyfinApi.userId should be fine for this.
* @param userId - User ID to look up items with
* @param item - Parent item of shuffle search
* @returns items for the queue
*/
export function getShuffleItems(
userId: string,
item: BaseItemDto
): Promise<BaseItemDtoQueryResult> {
const query: ItemsApiGetItemsRequest = {
Expand Down Expand Up @@ -515,7 +511,7 @@ export function getShuffleItems(
};
}

return getItemsForPlayback(userId, {
return getItemsForPlayback({
...query,
...additionalParams
});
Expand Down Expand Up @@ -564,20 +560,17 @@ export async function getInstantMixItems(

/**
* Get items to be played back
* @param userId - user for the search
* @param query - specification on what to search for
* @returns items to be played back
*/
export async function getItemsForPlayback(
userId: string,
query: ItemsApiGetItemsRequest
): Promise<BaseItemDtoQueryResult> {
const response = await getItemsApi(JellyfinApi.jellyfinApi).getItems({
...query,
excludeLocationTypes: ['Virtual'],
fields: requiredItemFields,
limit: query.limit ?? 100,
userId
limit: query.limit ?? 100
});

return response.data;
Expand Down Expand Up @@ -612,41 +605,39 @@ export function getUser(): Promise<UserDto> {
/**
* Process a list of items for playback
* by resolving things like folders to playable items.
* @param userId - userId to use
* @param items - items to resolve
* @param smart - If enabled it will try to find the next episode given the current one,
* if the connected user has enabled that in their settings
* @returns Promise for search result containing items to play
*/
export async function translateRequestedItems(
userId: string,
items: BaseItemDto[],
smart = false
): Promise<BaseItemDtoQueryResult> {
const firstItem = items[0];

if (firstItem.Type == 'Playlist') {
return await getItemsForPlayback(userId, {
return await getItemsForPlayback({
parentId: firstItem.Id
});
} else if (firstItem.Type == 'MusicArtist') {
return await getItemsForPlayback(userId, {
return await getItemsForPlayback({
artistIds: firstItem.Id ? [firstItem.Id] : undefined,
filters: ['IsNotFolder'],
mediaTypes: ['Audio'],
recursive: true,
sortBy: ['SortName']
});
} else if (firstItem.Type == 'MusicGenre') {
return await getItemsForPlayback(userId, {
return await getItemsForPlayback({
filters: ['IsNotFolder'],
genres: firstItem.Name ? [firstItem.Name] : undefined,
mediaTypes: ['Audio'],
recursive: true,
sortBy: ['SortName']
});
} else if (firstItem.IsFolder) {
return await getItemsForPlayback(userId, {
return await getItemsForPlayback({
filters: ['IsNotFolder'],
mediaTypes: ['Audio', 'Video'],
parentId: firstItem.Id,
Expand All @@ -662,7 +653,7 @@ export async function translateRequestedItems(
};
}

const result = await getItemsForPlayback(userId, {
const result = await getItemsForPlayback({
ids: firstItem.Id ? [firstItem.Id] : undefined
});

Expand All @@ -678,8 +669,7 @@ export async function translateRequestedItems(

const episodesResult = await getEpisodesForPlayback({
isMissing: false,
seriesId: episode.SeriesId,
userId: userId
seriesId: episode.SeriesId
});

let foundItem = false;
Expand Down

0 comments on commit af3db76

Please sign in to comment.