mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-05 19:14:48 +02:00
consolidated some api code
This commit is contained in:
parent
7c677e0ee6
commit
177d9cc172
6 changed files with 72 additions and 123 deletions
|
@ -106,6 +106,7 @@
|
||||||
<Compile Include="ApiEntryPoint.cs" />
|
<Compile Include="ApiEntryPoint.cs" />
|
||||||
<Compile Include="SystemService.cs" />
|
<Compile Include="SystemService.cs" />
|
||||||
<Compile Include="UserLibrary\BaseItemsByNameService.cs" />
|
<Compile Include="UserLibrary\BaseItemsByNameService.cs" />
|
||||||
|
<Compile Include="UserLibrary\BaseItemsRequest.cs" />
|
||||||
<Compile Include="UserLibrary\GenresService.cs" />
|
<Compile Include="UserLibrary\GenresService.cs" />
|
||||||
<Compile Include="UserLibrary\ItemsService.cs" />
|
<Compile Include="UserLibrary\ItemsService.cs" />
|
||||||
<Compile Include="UserLibrary\PersonsService.cs" />
|
<Compile Include="UserLibrary\PersonsService.cs" />
|
||||||
|
|
|
@ -6,6 +6,7 @@ using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Model.Drawing;
|
using MediaBrowser.Model.Drawing;
|
||||||
using MediaBrowser.Model.Dto;
|
using MediaBrowser.Model.Dto;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using MediaBrowser.Server.Implementations.HttpServer;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
@ -14,7 +15,6 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Server.Implementations.HttpServer;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Api.Playback
|
namespace MediaBrowser.Api.Playback
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Model.Dto;
|
using MediaBrowser.Model.Dto;
|
||||||
using MediaBrowser.Model.Entities;
|
|
||||||
using MediaBrowser.Model.Querying;
|
using MediaBrowser.Model.Querying;
|
||||||
using MediaBrowser.Server.Implementations.HttpServer;
|
using MediaBrowser.Server.Implementations.HttpServer;
|
||||||
using ServiceStack.ServiceHost;
|
using ServiceStack.ServiceHost;
|
||||||
|
@ -24,12 +23,16 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
/// The _user manager
|
/// The _user manager
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly IUserManager UserManager;
|
protected readonly IUserManager UserManager;
|
||||||
|
/// <summary>
|
||||||
|
/// The library manager
|
||||||
|
/// </summary>
|
||||||
protected readonly ILibraryManager LibraryManager;
|
protected readonly ILibraryManager LibraryManager;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="BaseItemsByNameService{TItemType}" /> class.
|
/// Initializes a new instance of the <see cref="BaseItemsByNameService{TItemType}" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userManager">The user manager.</param>
|
/// <param name="userManager">The user manager.</param>
|
||||||
|
/// <param name="libraryManager">The library manager.</param>
|
||||||
protected BaseItemsByNameService(IUserManager userManager, ILibraryManager libraryManager)
|
protected BaseItemsByNameService(IUserManager userManager, ILibraryManager libraryManager)
|
||||||
{
|
{
|
||||||
UserManager = userManager;
|
UserManager = userManager;
|
||||||
|
@ -45,7 +48,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
{
|
{
|
||||||
var user = UserManager.GetUserById(request.UserId);
|
var user = UserManager.GetUserById(request.UserId);
|
||||||
|
|
||||||
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : DtoBuilder.GetItemByClientId(request.Id, UserManager, LibraryManager, user.Id);
|
var item = string.IsNullOrEmpty(request.ParentId) ? user.RootFolder : DtoBuilder.GetItemByClientId(request.ParentId, UserManager, LibraryManager, user.Id);
|
||||||
|
|
||||||
IEnumerable<BaseItem> items;
|
IEnumerable<BaseItem> items;
|
||||||
|
|
||||||
|
@ -158,54 +161,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Class GetItemsByName
|
/// Class GetItemsByName
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GetItemsByName : IReturn<ItemsResult>
|
public class GetItemsByName : BaseItemsRequest, IReturn<ItemsResult>
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the user id.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The user id.</value>
|
|
||||||
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
||||||
public Guid UserId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the start index.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The start index.</value>
|
|
||||||
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
|
|
||||||
public int? StartIndex { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the size of the page.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The size of the page.</value>
|
|
||||||
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
|
|
||||||
public int? Limit { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets a value indicating whether this <see cref="GetItemsByName" /> is recursive.
|
|
||||||
/// </summary>
|
|
||||||
/// <value><c>true</c> if recursive; otherwise, <c>false</c>.</value>
|
|
||||||
[ApiMember(Name = "Recursive", Description = "When searching within folders, this determines whether or not the search will be recursive. true/false", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
|
|
||||||
public bool Recursive { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the sort order.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The sort order.</value>
|
|
||||||
[ApiMember(Name = "SortOrder", Description = "Sort Order - Ascending,Descending", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
||||||
public SortOrder? SortOrder { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// If specified the search will be localized within a specific item or folder
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The item id.</value>
|
|
||||||
[ApiMember(Name = "Id", Description = "If specified the search will be localized within a specific item or folder", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
||||||
public string Id { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Fields to return within the items, in addition to basic information
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The fields.</value>
|
|
||||||
public string Fields { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
58
MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs
Normal file
58
MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
using MediaBrowser.Model.Entities;
|
||||||
|
using ServiceStack.ServiceHost;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Api.UserLibrary
|
||||||
|
{
|
||||||
|
public abstract class BaseItemsRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the user id.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The user id.</value>
|
||||||
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Skips over a given number of items within the results. Use for paging.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The start index.</value>
|
||||||
|
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
|
||||||
|
public int? StartIndex { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The maximum number of items to return
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The limit.</value>
|
||||||
|
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
|
||||||
|
public int? Limit { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not to perform the query recursively
|
||||||
|
/// </summary>
|
||||||
|
/// <value><c>true</c> if recursive; otherwise, <c>false</c>.</value>
|
||||||
|
[ApiMember(Name = "Recursive", Description = "When searching within folders, this determines whether or not the search will be recursive. true/false", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
|
||||||
|
public bool Recursive { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the sort order.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The sort order.</value>
|
||||||
|
[ApiMember(Name = "SortOrder", Description = "Sort Order - Ascending,Descending", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
||||||
|
public SortOrder? SortOrder { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specify this to localize the search to a specific item or folder. Omit to use the root.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The parent id.</value>
|
||||||
|
[ApiMember(Name = "ParentId", Description = "Specify this to localize the search to a specific item or folder. Omit to use the root", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
||||||
|
public string ParentId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fields to return within the items, in addition to basic information
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The fields.</value>
|
||||||
|
[ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: AudioInfo, Chapters, DateCreated, DisplayMediaType, DisplayPreferences, Genres, ItemCounts, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, SeriesInfo, SortName, Studios, Taglines, TrailerUrls, UserData", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
|
||||||
|
public string Fields { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Model.Dto;
|
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Querying;
|
using MediaBrowser.Model.Querying;
|
||||||
using MediaBrowser.Server.Implementations.HttpServer;
|
using MediaBrowser.Server.Implementations.HttpServer;
|
||||||
|
@ -17,43 +16,8 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Route("/Users/{UserId}/Items", "GET")]
|
[Route("/Users/{UserId}/Items", "GET")]
|
||||||
[ServiceStack.ServiceHost.Api(Description = "Gets items based on a query.")]
|
[ServiceStack.ServiceHost.Api(Description = "Gets items based on a query.")]
|
||||||
public class GetItems : IReturn<ItemsResult>
|
public class GetItems : BaseItemsRequest, IReturn<ItemsResult>
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the user id.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The user id.</value>
|
|
||||||
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
||||||
public Guid UserId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Specify this to localize the search to a specific item or folder. Omit to use the root.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The parent id.</value>
|
|
||||||
[ApiMember(Name = "ParentId", Description = "Specify this to localize the search to a specific item or folder. Omit to use the root", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
||||||
public string ParentId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Skips over a given number of items within the results. Use for paging.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The start index.</value>
|
|
||||||
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
|
|
||||||
public int? StartIndex { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The maximum number of items to return
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The limit.</value>
|
|
||||||
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
|
|
||||||
public int? Limit { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether or not to perform the query recursively
|
|
||||||
/// </summary>
|
|
||||||
/// <value><c>true</c> if recursive; otherwise, <c>false</c>.</value>
|
|
||||||
[ApiMember(Name = "Recursive", Description = "When searching within folders, this determines whether or not the search will be recursive. true/false", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
|
|
||||||
public bool Recursive { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Limit results to items containing a specific person
|
/// Limit results to items containing a specific person
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -88,13 +52,6 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
[ApiMember(Name = "SortBy", Description = "Optional. Specify one or more sort orders, comma delimeted. Options: Album, AlbumArtist, Artist, CommunityRating, DateCreated, DatePlayed, PremiereDate, ProductionYear, SortName, Random, Runtime", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
|
[ApiMember(Name = "SortBy", Description = "Optional. Specify one or more sort orders, comma delimeted. Options: Album, AlbumArtist, Artist, CommunityRating, DateCreated, DatePlayed, PremiereDate, ProductionYear, SortName, Random, Runtime", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
|
||||||
public string SortBy { get; set; }
|
public string SortBy { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The sort order to return results with
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The sort order.</value>
|
|
||||||
[ApiMember(Name = "SortOrder", Description = "Optional. Ascending / Descending sort order", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
||||||
public string SortOrder { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Filters to apply to the results
|
/// Filters to apply to the results
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -102,13 +59,6 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
[ApiMember(Name = "Filters", Description = "Optional. Specify additional filters to apply. This allows multiple, comma delimeted. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsRecentlyAdded, IsResumable", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
|
[ApiMember(Name = "Filters", Description = "Optional. Specify additional filters to apply. This allows multiple, comma delimeted. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsRecentlyAdded, IsResumable", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
|
||||||
public string Filters { get; set; }
|
public string Filters { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Fields to return within the items, in addition to basic information
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The fields.</value>
|
|
||||||
[ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: AudioInfo, Chapters, DateCreated, DisplayMediaType, DisplayPreferences, Genres, ItemCounts, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, SeriesInfo, SortName, Studios, Taglines, TrailerUrls, UserData", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
|
|
||||||
public string Fields { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Limit results to items containing specific genres
|
/// Limit results to items containing specific genres
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -262,7 +212,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
{
|
{
|
||||||
var orderBy = GetOrderBy(request).ToArray();
|
var orderBy = GetOrderBy(request).ToArray();
|
||||||
|
|
||||||
return orderBy.Length == 0 ? items : _libraryManager.Sort(items, user, orderBy, GetSortOrder(request) ?? SortOrder.Ascending);
|
return orderBy.Length == 0 ? items : _libraryManager.Sort(items, user, orderBy, request.SortOrder ?? SortOrder.Ascending);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -466,21 +416,6 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the sort order.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">The request.</param>
|
|
||||||
/// <returns>System.Nullable{SortOrder}.</returns>
|
|
||||||
private SortOrder? GetSortOrder(GetItems request)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(request.SortOrder))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (SortOrder)Enum.Parse(typeof(SortOrder), request.SortOrder, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the filters.
|
/// Gets the filters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using MediaBrowser.Model.Dto;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Entities;
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace MediaBrowser.Model.Querying
|
namespace MediaBrowser.Model.Querying
|
||||||
|
@ -35,10 +34,10 @@ namespace MediaBrowser.Model.Querying
|
||||||
/// <value>The sort order.</value>
|
/// <value>The sort order.</value>
|
||||||
public SortOrder? SortOrder { get; set; }
|
public SortOrder? SortOrder { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If specified the search will be localized within a specific item or folder
|
/// Gets or sets the parent id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The item id.</value>
|
/// <value>The parent id.</value>
|
||||||
public string ItemId { get; set; }
|
public string ParentId { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fields to return within the items, in addition to basic information
|
/// Fields to return within the items, in addition to basic information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in a new issue