diff options
Diffstat (limited to 'MediaBrowser.Api')
| -rw-r--r-- | MediaBrowser.Api/Movies/CollectionService.cs | 31 | ||||
| -rw-r--r-- | MediaBrowser.Api/Playback/BaseStreamingService.cs | 8 |
2 files changed, 32 insertions, 7 deletions
diff --git a/MediaBrowser.Api/Movies/CollectionService.cs b/MediaBrowser.Api/Movies/CollectionService.cs index f09992e00f..b9e3888fda 100644 --- a/MediaBrowser.Api/Movies/CollectionService.cs +++ b/MediaBrowser.Api/Movies/CollectionService.cs @@ -1,13 +1,16 @@ using MediaBrowser.Controller.Collections; +using MediaBrowser.Controller.Dto; +using MediaBrowser.Model.Querying; using ServiceStack; using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace MediaBrowser.Api.Movies { [Route("/Collections", "POST", Summary = "Creates a new collection")] - public class CreateCollection : IReturnVoid + public class CreateCollection : IReturn<CollectionCreationResult> { [ApiMember(Name = "IsLocked", Description = "Whether or not to lock the new collection.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")] public bool IsLocked { get; set; } @@ -17,6 +20,9 @@ namespace MediaBrowser.Api.Movies [ApiMember(Name = "ParentId", Description = "Optional - create the collection within a specific folder", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] public Guid? ParentId { get; set; } + + [ApiMember(Name = "Ids", Description = "Item Ids to add to the collection", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST", AllowMultiple = true)] + public string Ids { get; set; } } [Route("/Collections/{Id}/Items", "POST", Summary = "Adds items to a collection")] @@ -42,22 +48,32 @@ namespace MediaBrowser.Api.Movies public class CollectionService : BaseApiService { private readonly ICollectionManager _collectionManager; + private readonly IDtoService _dtoService; - public CollectionService(ICollectionManager collectionManager) + public CollectionService(ICollectionManager collectionManager, IDtoService dtoService) { _collectionManager = collectionManager; + _dtoService = dtoService; } - public void Post(CreateCollection request) + public object Post(CreateCollection request) { var task = _collectionManager.CreateCollection(new CollectionCreationOptions { IsLocked = request.IsLocked, Name = request.Name, - ParentId = request.ParentId + ParentId = request.ParentId, + ItemIdList = (request.Ids ?? string.Empty).Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).Select(i => new Guid(i)).ToList() }); - Task.WaitAll(task); + var item = task.Result; + + var dto = _dtoService.GetBaseItemDto(item, new List<ItemFields>()); + + return ToOptimizedResult(new CollectionCreationResult + { + Id = dto.Id + }); } public void Post(AddToCollection request) @@ -74,4 +90,9 @@ namespace MediaBrowser.Api.Movies Task.WaitAll(task); } } + + public class CollectionCreationResult + { + public string Id { get; set; } + } } diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 9f7c1a6c4f..89d50e9a3d 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1065,8 +1065,12 @@ namespace MediaBrowser.Api.Playback /// <returns>System.String.</returns> private string GetUserAgentParam(StreamState state) { - string useragent; - state.RemoteHttpHeaders.TryGetValue("User-Agent", out useragent); + string useragent = null; + + if (state.RemoteHttpHeaders != null) + { + state.RemoteHttpHeaders.TryGetValue("User-Agent", out useragent); + } if (string.IsNullOrWhiteSpace(useragent)) { |
