From d1ca0cb4c7161b420c32e48824cc5065054b1869 Mon Sep 17 00:00:00 2001 From: crobibero Date: Sat, 20 Jun 2020 16:03:19 -0600 Subject: [PATCH] Use proper DtoOptions extensions --- .../Controllers/PlaylistsController.cs | 33 ++++++++++--------- Jellyfin.Api/Extensions/DtoExtensions.cs | 2 +- Jellyfin.Api/Helpers/RequestHelpers.cs | 18 ++++++++++ 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/Jellyfin.Api/Controllers/PlaylistsController.cs b/Jellyfin.Api/Controllers/PlaylistsController.cs index 0d73962de..9e2a91e10 100644 --- a/Jellyfin.Api/Controllers/PlaylistsController.cs +++ b/Jellyfin.Api/Controllers/PlaylistsController.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using System.Threading.Tasks; +using Jellyfin.Api.Extensions; using Jellyfin.Api.Helpers; using Jellyfin.Api.Models.PlaylistDtos; using MediaBrowser.Controller.Dto; @@ -80,17 +81,17 @@ namespace Jellyfin.Api.Controllers /// The playlist id. /// Item id, comma delimited. /// The userId. - /// Items added to playlist. - /// An on success. + /// Items added to playlist. + /// An on success. [HttpPost("{playlistId}/Items")] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] public ActionResult AddToPlaylist( [FromRoute] string playlistId, [FromQuery] string ids, [FromQuery] Guid userId) { _playlistManager.AddToPlaylist(playlistId, RequestHelpers.GetGuids(ids), userId); - return Ok(); + return NoContent(); } /// @@ -99,17 +100,17 @@ namespace Jellyfin.Api.Controllers /// The playlist id. /// The item id. /// The new index. - /// Item moved to new index. - /// An on success. + /// Item moved to new index. + /// An on success. [HttpPost("{playlistId}/Items/{itemId}/Move/{newIndex}")] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] public ActionResult MoveItem( [FromRoute] string playlistId, [FromRoute] string itemId, [FromRoute] int newIndex) { _playlistManager.MoveItem(playlistId, itemId, newIndex); - return Ok(); + return NoContent(); } /// @@ -117,14 +118,14 @@ namespace Jellyfin.Api.Controllers /// /// The playlist id. /// The item ids, comma delimited. - /// Items removed. - /// An on success. + /// Items removed. + /// An on success. [HttpDelete("{playlistId}/Items")] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] public ActionResult RemoveFromPlaylist([FromRoute] string playlistId, [FromQuery] string entryIds) { _playlistManager.RemoveFromPlaylist(playlistId, entryIds.Split(',')); - return Ok(); + return NoContent(); } /// @@ -151,7 +152,7 @@ namespace Jellyfin.Api.Controllers [FromRoute] string fields, [FromRoute] bool? enableImages, [FromRoute] bool? enableUserData, - [FromRoute] bool? imageTypeLimit, + [FromRoute] int? imageTypeLimit, [FromRoute] string enableImageTypes) { var playlist = (Playlist)_libraryManager.GetItemById(playlistId); @@ -176,8 +177,10 @@ namespace Jellyfin.Api.Controllers items = items.Take(limit.Value).ToArray(); } - // TODO var dtoOptions = GetDtoOptions(_authContext, request); - var dtoOptions = new DtoOptions(); + var dtoOptions = new DtoOptions() + .AddItemFields(fields) + .AddClientFields(Request) + .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); var dtos = _dtoService.GetBaseItemDtos(items.Select(i => i.Item2).ToList(), dtoOptions, user); diff --git a/Jellyfin.Api/Extensions/DtoExtensions.cs b/Jellyfin.Api/Extensions/DtoExtensions.cs index 4c587391f..ac248109d 100644 --- a/Jellyfin.Api/Extensions/DtoExtensions.cs +++ b/Jellyfin.Api/Extensions/DtoExtensions.cs @@ -122,7 +122,7 @@ namespace Jellyfin.Api.Extensions /// Enable image types. /// Modified DtoOptions object. internal static DtoOptions AddAdditionalDtoOptions( - in DtoOptions dtoOptions, + this DtoOptions dtoOptions, bool? enableImages, bool? enableUserData, int? imageTypeLimit, diff --git a/Jellyfin.Api/Helpers/RequestHelpers.cs b/Jellyfin.Api/Helpers/RequestHelpers.cs index 2ff40a8a5..e2a0cf4fa 100644 --- a/Jellyfin.Api/Helpers/RequestHelpers.cs +++ b/Jellyfin.Api/Helpers/RequestHelpers.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Jellyfin.Data.Enums; using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Session; @@ -73,5 +74,22 @@ namespace Jellyfin.Api.Helpers return session; } + + /// + /// Get Guid array from string. + /// + /// String value. + /// Guid array. + internal static Guid[] GetGuids(string? value) + { + if (value == null) + { + return Array.Empty(); + } + + return value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) + .Select(i => new Guid(i)) + .ToArray(); + } } }