mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-13 08:37:07 +00:00
Simplify API implementation
This commit is contained in:
parent
7f59f25418
commit
6176d208b1
1 changed files with 14 additions and 11 deletions
|
|
@ -744,27 +744,30 @@ public class LibraryController : BaseJellyfinApiController
|
|||
return NotFound();
|
||||
}
|
||||
|
||||
var normalizedStartIndex = Math.Max(startIndex ?? 0, 0);
|
||||
var normalizedLimit = limit.HasValue ? Math.Max(limit.Value, 0) : int.MaxValue;
|
||||
|
||||
var dtoOptions = new DtoOptions { Fields = fields };
|
||||
|
||||
var collections = _collectionManager
|
||||
var visibleCollections = _collectionManager
|
||||
.GetCollectionsContainingItem(user, item.Id)
|
||||
.OrderBy(i => i.SortName, StringComparer.OrdinalIgnoreCase)
|
||||
.ThenBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
var pagedCollections = collections
|
||||
.Skip(normalizedStartIndex)
|
||||
.Take(normalizedLimit)
|
||||
.ToList();
|
||||
IEnumerable<BaseItem> pagedCollections = visibleCollections;
|
||||
if (startIndex.HasValue)
|
||||
{
|
||||
pagedCollections = pagedCollections.Skip(startIndex.Value);
|
||||
}
|
||||
|
||||
var dtos = _dtoService.GetBaseItemDtos(pagedCollections, dtoOptions, user);
|
||||
if (limit.HasValue)
|
||||
{
|
||||
pagedCollections = pagedCollections.Take(limit.Value);
|
||||
}
|
||||
|
||||
var dtos = _dtoService.GetBaseItemDtos(pagedCollections.ToList(), dtoOptions, user);
|
||||
|
||||
return new QueryResult<BaseItemDto>(
|
||||
normalizedStartIndex,
|
||||
collections.Count,
|
||||
startIndex,
|
||||
visibleCollections.Count,
|
||||
dtos);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue