The Free Software Media System - Server Backend & API
Require properly typed ActionResult<T> (#8382)
Cody Robiberod2e18547b16f
diff --git a/Jellyfin.Api/BaseJellyfinApiController.cs b/Jellyfin.Api/BaseJellyfinApiController.csindex 59d6b75137..0c63d24b70 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.ApiJsonDefaults.PascalCaseMediaType)]public class BaseJellyfinApiController : ControllerBase{+ /// <summary>+ /// Create a new <see cref="OkResult{T}"/>.+ /// </summary>+ /// <param name="value">The value to return.</param>+ /// <typeparam name="T">The type to return.</typeparam>+ /// <returns>The <see cref="ActionResult{T}"/>.</returns>+ protected ActionResult<IEnumerable<T>> Ok<T>(List<T> value)+ => new OkResult<IEnumerable<T>>(value);++ /// <summary>+ /// Create a new <see cref="OkResult{T}"/>.+ /// </summary>+ /// <param name="value">The value to return.</param>+ /// <typeparam name="T">The type to return.</typeparam>+ /// <returns>The <see cref="ActionResult{T}"/>.</returns>+ protected ActionResult<IEnumerable<T>> Ok<T>(IReadOnlyList<T> value)+ => new OkResult<IEnumerable<T>>(value);++ /// <summary>+ /// Create a new <see cref="OkResult{T}"/>.+ /// </summary>+ /// <param name="value">The value to return.</param>+ /// <typeparam name="T">The type to return.</typeparam>+ /// <returns>The <see cref="ActionResult{T}"/>.</returns>+ protected ActionResult<IEnumerable<T>> Ok<T>(IEnumerable<T>? value)+ => new OkResult<IEnumerable<T>?>(value);++ /// <summary>+ /// Create a new <see cref="OkResult{T}"/>.+ /// </summary>+ /// <param name="value">The value to return.</param>+ /// <typeparam name="T">The type to return.</typeparam>+ /// <returns>The <see cref="ActionResult{T}"/>.</returns>+ protected ActionResult<T> Ok<T>(T value)+ => new OkResult<T>(value);}}diff --git a/Jellyfin.Api/Controllers/ConfigurationController.cs b/Jellyfin.Api/Controllers/ConfigurationController.csindex 464fadc060..bbe1633120 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.csindex 401c0197ac..8859d60207 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<string> 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<string> 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<string> 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<string> GetConnectionManager([FromRoute, Required] string serverId){return Ok(_connectionManager.GetServiceXml());}diff --git a/Jellyfin.Api/Controllers/MediaInfoController.cs b/Jellyfin.Api/Controllers/MediaInfoController.csindex 75df18204d..d2852ed011 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.csindex 420dd99233..4669447049 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<RecommendationDto> GetWithDirector(diff --git a/Jellyfin.Api/Controllers/UserLibraryController.cs b/Jellyfin.Api/Controllers/UserLibraryController.csindex e45f9b58cd..1656a1e98c 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.csindex 5cc8c906fb..04732ccf25 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.Controllersprivate readonly IUserManager _userManager;private readonly IUserViewManager _userViewManager;private readonly IDtoService _dtoService;- private readonly IAuthorizationContext _authContext;private readonly ILibraryManager _libraryManager;/// <summary>@@ -41,19 +37,16 @@ namespace Jellyfin.Api.Controllers/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>/// <param name="userViewManager">Instance of the <see cref="IUserViewManager"/> interface.</param>/// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>- /// <param name="authContext">Instance of the <see cref="IAuthorizationContext"/> interface.</param>/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>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.ControllersName = 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.csnew file mode 100644index 0000000000..f60cbbceea--- /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;++/// <summary>+/// Ok result with type specified.+/// </summary>+/// <typeparam name="T">The type to return.</typeparam>+public class OkResult<T> : OkObjectResult+{+ /// <summary>+ /// Initializes a new instance of the <see cref="OkResult{T}"/> class.+ /// </summary>+ /// <param name="value">The value to return.</param>+ public OkResult(T value)+ : base(value)+ {+ }+}