mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-27 08:10:34 +00:00
Fix too long URLs on getItems with many ids
This commit is contained in:
parent
5e51616e18
commit
d5e9541010
@ -59,6 +59,7 @@
|
||||
- [Vankerkom](https://github.com/vankerkom)
|
||||
- [edvwib](https://github.com/edvwib)
|
||||
- [Rob Farraher](https://github.com/farraherbg)
|
||||
- [Merlin Sievers](https://github.com/dann-merlin)
|
||||
|
||||
# Emby Contributors
|
||||
|
||||
|
@ -2,6 +2,7 @@ import serverNotifications from '../../scripts/serverNotifications';
|
||||
import { playbackManager } from '../playback/playbackmanager';
|
||||
import Events from '../../utils/events.ts';
|
||||
import globalize from '../../scripts/globalize';
|
||||
import { getItems } from '../../utils/jellyfin-apiclient/getItemsHelper.ts';
|
||||
|
||||
import NotificationIcon from './notificationicon.png';
|
||||
|
||||
@ -130,7 +131,9 @@ function onLibraryChanged(data, apiClient) {
|
||||
newItems.length = 12;
|
||||
}
|
||||
|
||||
apiClient.getItems(apiClient.getCurrentUserId(), {
|
||||
// call getItems from getItemsHelper instead of apiClient.getItems()
|
||||
// to split up into multiple requests if necessary (URL might get too long)
|
||||
getItems(apiClient, apiClient.getCurrentUserId(), {
|
||||
|
||||
Recursive: true,
|
||||
Limit: 3,
|
||||
|
@ -12,6 +12,7 @@ import Screenfull from 'screenfull';
|
||||
import ServerConnections from '../ServerConnections';
|
||||
import alert from '../alert';
|
||||
import { includesAny } from '../../utils/container.ts';
|
||||
import { getItems } from '../../utils/jellyfin-apiclient/getItemsHelper.ts';
|
||||
|
||||
const UNLIMITED_ITEMS = -1;
|
||||
|
||||
@ -126,7 +127,9 @@ function getItemsForPlayback(serverId, query) {
|
||||
query.EnableTotalRecordCount = false;
|
||||
query.CollapseBoxSetItems = false;
|
||||
|
||||
return apiClient.getItems(apiClient.getCurrentUserId(), query);
|
||||
// call getItems from getItemsHelper instead of apiClient.getItems()
|
||||
// to split up into multiple requests if necessary (URL might get too long)
|
||||
return getItems(apiClient, apiClient.getCurrentUserId(), query);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import castSenderApiLoader from './castSenderApi';
|
||||
import ServerConnections from '../../components/ServerConnections';
|
||||
import alert from '../../components/alert';
|
||||
import Events from '../../utils/events.ts';
|
||||
import { getItems } from '../../utils/jellyfin-apiclient/getItemsHelper.ts';
|
||||
|
||||
// Based on https://github.com/googlecast/CastVideos-chrome/blob/master/CastVideos.js
|
||||
|
||||
@ -481,7 +482,9 @@ function getItemsForPlayback(apiClient, query) {
|
||||
query.ExcludeLocationTypes = 'Virtual';
|
||||
query.EnableTotalRecordCount = false;
|
||||
|
||||
return apiClient.getItems(userId, query);
|
||||
// call getItems from getItemsHelper instead of apiClient.getItems()
|
||||
// to split up into multiple requests if necessary (URL might get too long)
|
||||
return getItems(apiClient, userId, query);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import Events from '../../../utils/events.ts';
|
||||
import { getItems } from '../../../utils/jellyfin-apiclient/getItemsHelper.ts';
|
||||
|
||||
/**
|
||||
* Constants
|
||||
@ -88,7 +89,9 @@ export function getItemsForPlayback(apiClient, query) {
|
||||
query.EnableTotalRecordCount = false;
|
||||
query.CollapseBoxSetItems = false;
|
||||
|
||||
return apiClient.getItems(apiClient.getCurrentUserId(), query);
|
||||
// call getItems from getItemsHelper instead of apiClient.getItems()
|
||||
// to split up into multiple requests if necessary (URL might get too long)
|
||||
return getItems(apiClient, apiClient.getCurrentUserId(), query);
|
||||
}
|
||||
}
|
||||
|
||||
|
63
src/utils/jellyfin-apiclient/getItemsHelper.ts
Normal file
63
src/utils/jellyfin-apiclient/getItemsHelper.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import type {BaseItemDtoQueryResult} from '@jellyfin/sdk/lib/generated-client';
|
||||
import {ApiClient} from 'jellyfin-apiclient';
|
||||
|
||||
const idsPerItemRequestLimit = 25;
|
||||
|
||||
function getItemsSplit(apiClient: ApiClient, userId: string, options: any) {
|
||||
const optionsTemplate = {...options};
|
||||
const ids = options.Ids.split(',');
|
||||
const results = [];
|
||||
|
||||
let nextI;
|
||||
for (let i = 0; i < ids.length && i < options.Limit; i = nextI) {
|
||||
nextI = i + idsPerItemRequestLimit;
|
||||
if (nextI > options.Limit) {
|
||||
nextI = options.Limit;
|
||||
}
|
||||
const idsSlice = ids.slice(i, nextI);
|
||||
console.log(idsSlice);
|
||||
optionsTemplate.Ids = idsSlice.join(',');
|
||||
results.push(apiClient.getItems(userId, optionsTemplate));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
function mergeResults(results: BaseItemDtoQueryResult[]) {
|
||||
const merged: BaseItemDtoQueryResult = {};
|
||||
merged.Items = [];
|
||||
merged.TotalRecordCount = 0;
|
||||
merged.StartIndex = 0;
|
||||
|
||||
for (const result of results) {
|
||||
if (result.Items == null) {
|
||||
console.log(`Retrieved Items array is invalid: ${result.Items}`);
|
||||
continue;
|
||||
}
|
||||
if (result.TotalRecordCount == null) {
|
||||
console.log(`Retrieved TotalRecordCount is invalid: ${
|
||||
result.TotalRecordCount}`);
|
||||
continue;
|
||||
}
|
||||
if (result.StartIndex == null) {
|
||||
console.log(
|
||||
`Retrieved StartIndex is invalid: ${result.StartIndex}`);
|
||||
continue;
|
||||
}
|
||||
merged.Items = merged.Items.concat(result.Items);
|
||||
merged.TotalRecordCount += result.TotalRecordCount;
|
||||
merged.StartIndex = Math.min(merged.StartIndex, result.StartIndex);
|
||||
}
|
||||
return merged;
|
||||
}
|
||||
|
||||
export function getItems(apiClient: ApiClient, userId: string, options?: any):
|
||||
Promise<BaseItemDtoQueryResult> {
|
||||
if (options.Ids === undefined ||
|
||||
options.Ids.split(',').ength <= idsPerItemRequestLimit) {
|
||||
return apiClient.getItems(apiClient.getCurrentUserId(), options);
|
||||
}
|
||||
const results = getItemsSplit(apiClient, userId, options);
|
||||
|
||||
return Promise.all(results).then(mergeResults);
|
||||
}
|
Loading…
Reference in New Issue
Block a user