From 7424f0ca8cef9ca1850420a5f3a5761ce764680b Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Sat, 9 Apr 2022 08:45:13 -0600 Subject: Merge pull request #7561 from DMouse10462/named-config-api-fix Fix NamedConfiguration API Generation (cherry picked from commit d7c548f3dbb74c03903cd9bb86ab3af33e295d15) Signed-off-by: Joshua Boniface --- Jellyfin.Api/Controllers/ConfigurationController.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'Jellyfin.Api/Controllers/ConfigurationController.cs') diff --git a/Jellyfin.Api/Controllers/ConfigurationController.cs b/Jellyfin.Api/Controllers/ConfigurationController.cs index 60529e990..464fadc06 100644 --- a/Jellyfin.Api/Controllers/ConfigurationController.cs +++ b/Jellyfin.Api/Controllers/ConfigurationController.cs @@ -86,21 +86,23 @@ namespace Jellyfin.Api.Controllers /// Updates named configuration. /// /// Configuration key. + /// Configuration. /// Named configuration updated. /// Update status. [HttpPost("Configuration/{key}")] [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status204NoContent)] - public async Task UpdateNamedConfiguration([FromRoute, Required] string key) + public ActionResult UpdateNamedConfiguration([FromRoute, Required] string key, [FromBody, Required] JsonDocument configuration) { var configurationType = _configurationManager.GetConfigurationType(key); - var configuration = await JsonSerializer.DeserializeAsync(Request.Body, configurationType, _serializerOptions).ConfigureAwait(false); - if (configuration == null) + var deserializedConfiguration = configuration.Deserialize(configurationType, _serializerOptions); + + if (deserializedConfiguration == null) { throw new ArgumentException("Body doesn't contain a valid configuration"); } - _configurationManager.SaveConfiguration(key, configuration); + _configurationManager.SaveConfiguration(key, deserializedConfiguration); return NoContent(); } -- cgit v1.2.3 From d2e18547b16fa30684d7c9ceb8a117d5d9bcef56 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Sun, 11 Sep 2022 17:47:01 -0600 Subject: Require properly typed ActionResult (#8382) --- Jellyfin.Api/BaseJellyfinApiController.cs | 37 ++++++++++++++++++++++ .../Controllers/ConfigurationController.cs | 1 - Jellyfin.Api/Controllers/DlnaServerController.cs | 8 ++--- Jellyfin.Api/Controllers/MediaInfoController.cs | 1 - Jellyfin.Api/Controllers/MoviesController.cs | 2 +- Jellyfin.Api/Controllers/UserLibraryController.cs | 1 - Jellyfin.Api/Controllers/UserViewsController.cs | 10 ++---- Jellyfin.Api/Results/OkResultOfT.cs | 21 ++++++++++++ 8 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 Jellyfin.Api/Results/OkResultOfT.cs (limited to 'Jellyfin.Api/Controllers/ConfigurationController.cs') diff --git a/Jellyfin.Api/BaseJellyfinApiController.cs b/Jellyfin.Api/BaseJellyfinApiController.cs index 59d6b7513..0c63d24b7 100644 --- a/Jellyfin.Api/BaseJellyfinApiController.cs +++ b/Jellyfin.Api/BaseJellyfinApiController.cs @@ -1,4 +1,6 @@ +using System.Collections.Generic; using System.Net.Mime; +using Jellyfin.Api.Results; using Jellyfin.Extensions.Json; using Microsoft.AspNetCore.Mvc; @@ -15,5 +17,40 @@ namespace Jellyfin.Api JsonDefaults.PascalCaseMediaType)] public class BaseJellyfinApiController : ControllerBase { + /// + /// Create a new . + /// + /// The value to return. + /// The type to return. + /// The . + protected ActionResult> Ok(List value) + => new OkResult>(value); + + /// + /// Create a new . + /// + /// The value to return. + /// The type to return. + /// The . + protected ActionResult> Ok(IReadOnlyList value) + => new OkResult>(value); + + /// + /// Create a new . + /// + /// The value to return. + /// The type to return. + /// The . + protected ActionResult> Ok(IEnumerable? value) + => new OkResult?>(value); + + /// + /// Create a new . + /// + /// The value to return. + /// The type to return. + /// The . + protected ActionResult Ok(T value) + => new OkResult(value); } } diff --git a/Jellyfin.Api/Controllers/ConfigurationController.cs b/Jellyfin.Api/Controllers/ConfigurationController.cs index 464fadc06..bbe163312 100644 --- a/Jellyfin.Api/Controllers/ConfigurationController.cs +++ b/Jellyfin.Api/Controllers/ConfigurationController.cs @@ -2,7 +2,6 @@ using System; using System.ComponentModel.DataAnnotations; using System.Net.Mime; using System.Text.Json; -using System.Threading.Tasks; using Jellyfin.Api.Attributes; using Jellyfin.Api.Constants; using Jellyfin.Api.Models.ConfigurationDtos; diff --git a/Jellyfin.Api/Controllers/DlnaServerController.cs b/Jellyfin.Api/Controllers/DlnaServerController.cs index 401c0197a..8859d6020 100644 --- a/Jellyfin.Api/Controllers/DlnaServerController.cs +++ b/Jellyfin.Api/Controllers/DlnaServerController.cs @@ -54,7 +54,7 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status503ServiceUnavailable)] [Produces(MediaTypeNames.Text.Xml)] [ProducesFile(MediaTypeNames.Text.Xml)] - public ActionResult GetDescriptionXml([FromRoute, Required] string serverId) + public ActionResult GetDescriptionXml([FromRoute, Required] string serverId) { var url = GetAbsoluteUri(); var serverAddress = url.Substring(0, url.IndexOf("/dlna/", StringComparison.OrdinalIgnoreCase)); @@ -77,7 +77,7 @@ namespace Jellyfin.Api.Controllers [Produces(MediaTypeNames.Text.Xml)] [ProducesFile(MediaTypeNames.Text.Xml)] [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")] - public ActionResult GetContentDirectory([FromRoute, Required] string serverId) + public ActionResult GetContentDirectory([FromRoute, Required] string serverId) { return Ok(_contentDirectory.GetServiceXml()); } @@ -97,7 +97,7 @@ namespace Jellyfin.Api.Controllers [Produces(MediaTypeNames.Text.Xml)] [ProducesFile(MediaTypeNames.Text.Xml)] [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")] - public ActionResult GetMediaReceiverRegistrar([FromRoute, Required] string serverId) + public ActionResult GetMediaReceiverRegistrar([FromRoute, Required] string serverId) { return Ok(_mediaReceiverRegistrar.GetServiceXml()); } @@ -117,7 +117,7 @@ namespace Jellyfin.Api.Controllers [Produces(MediaTypeNames.Text.Xml)] [ProducesFile(MediaTypeNames.Text.Xml)] [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")] - public ActionResult GetConnectionManager([FromRoute, Required] string serverId) + public ActionResult GetConnectionManager([FromRoute, Required] string serverId) { return Ok(_connectionManager.GetServiceXml()); } diff --git a/Jellyfin.Api/Controllers/MediaInfoController.cs b/Jellyfin.Api/Controllers/MediaInfoController.cs index 75df18204..d2852ed01 100644 --- a/Jellyfin.Api/Controllers/MediaInfoController.cs +++ b/Jellyfin.Api/Controllers/MediaInfoController.cs @@ -12,7 +12,6 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Devices; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Net; -using MediaBrowser.Model.Dlna; using MediaBrowser.Model.MediaInfo; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; diff --git a/Jellyfin.Api/Controllers/MoviesController.cs b/Jellyfin.Api/Controllers/MoviesController.cs index 420dd9923..466944704 100644 --- a/Jellyfin.Api/Controllers/MoviesController.cs +++ b/Jellyfin.Api/Controllers/MoviesController.cs @@ -170,7 +170,7 @@ namespace Jellyfin.Api.Controllers } } - return Ok(categories.OrderBy(i => i.RecommendationType)); + return Ok(categories.OrderBy(i => i.RecommendationType).AsEnumerable()); } private IEnumerable GetWithDirector( diff --git a/Jellyfin.Api/Controllers/UserLibraryController.cs b/Jellyfin.Api/Controllers/UserLibraryController.cs index e45f9b58c..1656a1e98 100644 --- a/Jellyfin.Api/Controllers/UserLibraryController.cs +++ b/Jellyfin.Api/Controllers/UserLibraryController.cs @@ -8,7 +8,6 @@ using Jellyfin.Api.Constants; using Jellyfin.Api.Extensions; using Jellyfin.Api.ModelBinders; using Jellyfin.Data.Enums; -using Jellyfin.Extensions; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; diff --git a/Jellyfin.Api/Controllers/UserViewsController.cs b/Jellyfin.Api/Controllers/UserViewsController.cs index 5cc8c906f..04732ccf2 100644 --- a/Jellyfin.Api/Controllers/UserViewsController.cs +++ b/Jellyfin.Api/Controllers/UserViewsController.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Globalization; using System.Linq; -using System.Threading.Tasks; using Jellyfin.Api.Constants; using Jellyfin.Api.Extensions; using Jellyfin.Api.ModelBinders; @@ -11,9 +10,7 @@ using Jellyfin.Api.Models.UserViewDtos; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Net; using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Entities; using MediaBrowser.Model.Library; using MediaBrowser.Model.Querying; using Microsoft.AspNetCore.Authorization; @@ -32,7 +29,6 @@ namespace Jellyfin.Api.Controllers private readonly IUserManager _userManager; private readonly IUserViewManager _userViewManager; private readonly IDtoService _dtoService; - private readonly IAuthorizationContext _authContext; private readonly ILibraryManager _libraryManager; /// @@ -41,19 +37,16 @@ namespace Jellyfin.Api.Controllers /// Instance of the interface. /// Instance of the interface. /// Instance of the interface. - /// Instance of the interface. /// Instance of the interface. public UserViewsController( IUserManager userManager, IUserViewManager userViewManager, IDtoService dtoService, - IAuthorizationContext authContext, ILibraryManager libraryManager) { _userManager = userManager; _userViewManager = userViewManager; _dtoService = dtoService; - _authContext = authContext; _libraryManager = libraryManager; } @@ -138,7 +131,8 @@ namespace Jellyfin.Api.Controllers Name = i.Name, Id = i.Id.ToString("N", CultureInfo.InvariantCulture) }) - .OrderBy(i => i.Name)); + .OrderBy(i => i.Name) + .AsEnumerable()); } } } diff --git a/Jellyfin.Api/Results/OkResultOfT.cs b/Jellyfin.Api/Results/OkResultOfT.cs new file mode 100644 index 000000000..f60cbbcee --- /dev/null +++ b/Jellyfin.Api/Results/OkResultOfT.cs @@ -0,0 +1,21 @@ +#pragma warning disable SA1649 // File name should match type name. + +using Microsoft.AspNetCore.Mvc; + +namespace Jellyfin.Api.Results; + +/// +/// Ok result with type specified. +/// +/// The type to return. +public class OkResult : OkObjectResult +{ + /// + /// Initializes a new instance of the class. + /// + /// The value to return. + public OkResult(T value) + : base(value) + { + } +} -- cgit v1.2.3