From f5385e4735849cbb1552e69faa0116e5498b3688 Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 21 Apr 2020 18:12:46 -0600 Subject: [PATCH 1/3] Move Emby.Dlna DlnaService.cs to Jellyfin.Api --- Emby.Dlna/Api/DlnaService.cs | 88 --------------- Jellyfin.Api/Controllers/DlnaController.cs | 124 +++++++++++++++++++++ 2 files changed, 124 insertions(+), 88 deletions(-) delete mode 100644 Emby.Dlna/Api/DlnaService.cs create mode 100644 Jellyfin.Api/Controllers/DlnaController.cs diff --git a/Emby.Dlna/Api/DlnaService.cs b/Emby.Dlna/Api/DlnaService.cs deleted file mode 100644 index 5f984bb335..0000000000 --- a/Emby.Dlna/Api/DlnaService.cs +++ /dev/null @@ -1,88 +0,0 @@ -#pragma warning disable CS1591 - -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using MediaBrowser.Controller.Dlna; -using MediaBrowser.Controller.Net; -using MediaBrowser.Model.Dlna; -using MediaBrowser.Model.Services; - -namespace Emby.Dlna.Api -{ - [Route("/Dlna/ProfileInfos", "GET", Summary = "Gets a list of profiles")] - public class GetProfileInfos : IReturn - { - } - - [Route("/Dlna/Profiles/{Id}", "DELETE", Summary = "Deletes a profile")] - public class DeleteProfile : IReturnVoid - { - [ApiMember(Name = "Id", Description = "Profile Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")] - public string Id { get; set; } - } - - [Route("/Dlna/Profiles/Default", "GET", Summary = "Gets the default profile")] - public class GetDefaultProfile : IReturn - { - } - - [Route("/Dlna/Profiles/{Id}", "GET", Summary = "Gets a single profile")] - public class GetProfile : IReturn - { - [ApiMember(Name = "Id", Description = "Profile Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] - public string Id { get; set; } - } - - [Route("/Dlna/Profiles/{Id}", "POST", Summary = "Updates a profile")] - public class UpdateProfile : DeviceProfile, IReturnVoid - { - } - - [Route("/Dlna/Profiles", "POST", Summary = "Creates a profile")] - public class CreateProfile : DeviceProfile, IReturnVoid - { - } - - [Authenticated(Roles = "Admin")] - public class DlnaService : IService - { - private readonly IDlnaManager _dlnaManager; - - public DlnaService(IDlnaManager dlnaManager) - { - _dlnaManager = dlnaManager; - } - - [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "request", Justification = "Required for ServiceStack")] - public object Get(GetProfileInfos request) - { - return _dlnaManager.GetProfileInfos().ToArray(); - } - - public object Get(GetProfile request) - { - return _dlnaManager.GetProfile(request.Id); - } - - [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "request", Justification = "Required for ServiceStack")] - public object Get(GetDefaultProfile request) - { - return _dlnaManager.GetDefaultProfile(); - } - - public void Delete(DeleteProfile request) - { - _dlnaManager.DeleteProfile(request.Id); - } - - public void Post(UpdateProfile request) - { - _dlnaManager.UpdateProfile(request); - } - - public void Post(CreateProfile request) - { - _dlnaManager.CreateProfile(request); - } - } -} diff --git a/Jellyfin.Api/Controllers/DlnaController.cs b/Jellyfin.Api/Controllers/DlnaController.cs new file mode 100644 index 0000000000..68cd144f4e --- /dev/null +++ b/Jellyfin.Api/Controllers/DlnaController.cs @@ -0,0 +1,124 @@ +#nullable enable + +using System.Collections.Generic; +using MediaBrowser.Controller.Dlna; +using MediaBrowser.Controller.Net; +using MediaBrowser.Model.Dlna; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace Jellyfin.Api.Controllers +{ + /// + /// Dlna Controller. + /// + [Authenticated(Roles = "Admin")] + public class DlnaController : BaseJellyfinApiController + { + private readonly IDlnaManager _dlnaManager; + + /// + /// Initializes a new instance of the class. + /// + /// Instance of the interface. + public DlnaController(IDlnaManager dlnaManager) + { + _dlnaManager = dlnaManager; + } + + /// + /// Get profile infos. + /// + /// Profile infos. + [HttpGet("ProfileInfos")] + [ProducesResponseType(StatusCodes.Status200OK)] + public IEnumerable GetProfileInfos() + { + return _dlnaManager.GetProfileInfos(); + } + + /// + /// Gets the default profile. + /// + /// Default profile. + [HttpGet("Profiles/Default")] + [ProducesResponseType(StatusCodes.Status200OK)] + public ActionResult GetDefaultProfile() + { + return Ok(_dlnaManager.GetDefaultProfile()); + } + + /// + /// Gets a single profile. + /// + /// Profile Id. + /// Profile. + [HttpGet("Profiles/{Id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public ActionResult GetProfile([FromRoute] string id) + { + var profile = _dlnaManager.GetProfile(id); + if (profile == null) + { + return NotFound(); + } + + return Ok(profile); + } + + /// + /// Deletes a profile. + /// + /// Profile id. + /// Status. + [HttpDelete("Profiles/{Id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public ActionResult DeleteProfile([FromRoute] string id) + { + var existingDeviceProfile = _dlnaManager.GetProfile(id); + if (existingDeviceProfile == null) + { + return NotFound(); + } + + _dlnaManager.DeleteProfile(id); + return Ok(); + } + + /// + /// Creates a profile. + /// + /// Device profile. + /// Status. + [HttpPost("Profiles")] + [ProducesResponseType(StatusCodes.Status200OK)] + public ActionResult CreateProfile([FromBody] DeviceProfile deviceProfile) + { + _dlnaManager.CreateProfile(deviceProfile); + return Ok(); + } + + /// + /// Updates a profile. + /// + /// Profile id. + /// Device profile. + /// Status. + [HttpPost("Profiles/{Id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public ActionResult UpdateProfile([FromRoute] string id, [FromBody] DeviceProfile deviceProfile) + { + var existingDeviceProfile = _dlnaManager.GetProfile(id); + if (existingDeviceProfile == null) + { + return NotFound(); + } + + _dlnaManager.UpdateProfile(deviceProfile); + return Ok(); + } + } +} From 6051df0c47876cd30ea0f39f8ef6ed1f54740a67 Mon Sep 17 00:00:00 2001 From: crobibero Date: Fri, 31 Jul 2020 10:14:09 -0600 Subject: [PATCH 2/3] Fix response codes, documentation, and auth --- Jellyfin.Api/Controllers/DlnaController.cs | 52 +++++++++++++--------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/Jellyfin.Api/Controllers/DlnaController.cs b/Jellyfin.Api/Controllers/DlnaController.cs index 68cd144f4e..dcd31a48ba 100644 --- a/Jellyfin.Api/Controllers/DlnaController.cs +++ b/Jellyfin.Api/Controllers/DlnaController.cs @@ -1,9 +1,8 @@ -#nullable enable - using System.Collections.Generic; +using Jellyfin.Api.Constants; using MediaBrowser.Controller.Dlna; -using MediaBrowser.Controller.Net; using MediaBrowser.Model.Dlna; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -12,7 +11,7 @@ namespace Jellyfin.Api.Controllers /// /// Dlna Controller. /// - [Authenticated(Roles = "Admin")] + [Authorize(Policy = Policies.RequiresElevation)] public class DlnaController : BaseJellyfinApiController { private readonly IDlnaManager _dlnaManager; @@ -29,34 +28,38 @@ namespace Jellyfin.Api.Controllers /// /// Get profile infos. /// - /// Profile infos. + /// Device profile infos returned. + /// An containing the device profile infos. [HttpGet("ProfileInfos")] [ProducesResponseType(StatusCodes.Status200OK)] - public IEnumerable GetProfileInfos() + public ActionResult> GetProfileInfos() { - return _dlnaManager.GetProfileInfos(); + return Ok(_dlnaManager.GetProfileInfos()); } /// /// Gets the default profile. /// - /// Default profile. + /// Default device profile returned. + /// An containing the default profile. [HttpGet("Profiles/Default")] [ProducesResponseType(StatusCodes.Status200OK)] - public ActionResult GetDefaultProfile() + public ActionResult GetDefaultProfile() { - return Ok(_dlnaManager.GetDefaultProfile()); + return _dlnaManager.GetDefaultProfile(); } /// /// Gets a single profile. /// /// Profile Id. - /// Profile. + /// Device profile returned. + /// Device profile not found. + /// An containing the profile on success, or a if device profile not found. [HttpGet("Profiles/{Id}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GetProfile([FromRoute] string id) + public ActionResult GetProfile([FromRoute] string id) { var profile = _dlnaManager.GetProfile(id); if (profile == null) @@ -64,16 +67,18 @@ namespace Jellyfin.Api.Controllers return NotFound(); } - return Ok(profile); + return profile; } /// /// Deletes a profile. /// /// Profile id. - /// Status. + /// Device profile deleted. + /// Device profile not found. + /// A on success, or a if profile not found. [HttpDelete("Profiles/{Id}")] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult DeleteProfile([FromRoute] string id) { @@ -84,20 +89,21 @@ namespace Jellyfin.Api.Controllers } _dlnaManager.DeleteProfile(id); - return Ok(); + return NoContent(); } /// /// Creates a profile. /// /// Device profile. - /// Status. + /// Device profile created. + /// A . [HttpPost("Profiles")] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] public ActionResult CreateProfile([FromBody] DeviceProfile deviceProfile) { _dlnaManager.CreateProfile(deviceProfile); - return Ok(); + return NoContent(); } /// @@ -105,9 +111,11 @@ namespace Jellyfin.Api.Controllers /// /// Profile id. /// Device profile. - /// Status. + /// Device profile updated. + /// Device profile not found. + /// A on success, or a if profile not found. [HttpPost("Profiles/{Id}")] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult UpdateProfile([FromRoute] string id, [FromBody] DeviceProfile deviceProfile) { @@ -118,7 +126,7 @@ namespace Jellyfin.Api.Controllers } _dlnaManager.UpdateProfile(deviceProfile); - return Ok(); + return NoContent(); } } } From 32c0ac96a14bcc42e57f9583d71dd65c804bb577 Mon Sep 17 00:00:00 2001 From: crobibero Date: Fri, 31 Jul 2020 10:17:01 -0600 Subject: [PATCH 3/3] fix route params --- Jellyfin.Api/Controllers/DlnaController.cs | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Jellyfin.Api/Controllers/DlnaController.cs b/Jellyfin.Api/Controllers/DlnaController.cs index dcd31a48ba..397299a73f 100644 --- a/Jellyfin.Api/Controllers/DlnaController.cs +++ b/Jellyfin.Api/Controllers/DlnaController.cs @@ -52,16 +52,16 @@ namespace Jellyfin.Api.Controllers /// /// Gets a single profile. /// - /// Profile Id. + /// Profile Id. /// Device profile returned. /// Device profile not found. /// An containing the profile on success, or a if device profile not found. - [HttpGet("Profiles/{Id}")] + [HttpGet("Profiles/{profileId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GetProfile([FromRoute] string id) + public ActionResult GetProfile([FromRoute] string profileId) { - var profile = _dlnaManager.GetProfile(id); + var profile = _dlnaManager.GetProfile(profileId); if (profile == null) { return NotFound(); @@ -73,22 +73,22 @@ namespace Jellyfin.Api.Controllers /// /// Deletes a profile. /// - /// Profile id. + /// Profile id. /// Device profile deleted. /// Device profile not found. /// A on success, or a if profile not found. - [HttpDelete("Profiles/{Id}")] + [HttpDelete("Profiles/{profileId}")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult DeleteProfile([FromRoute] string id) + public ActionResult DeleteProfile([FromRoute] string profileId) { - var existingDeviceProfile = _dlnaManager.GetProfile(id); + var existingDeviceProfile = _dlnaManager.GetProfile(profileId); if (existingDeviceProfile == null) { return NotFound(); } - _dlnaManager.DeleteProfile(id); + _dlnaManager.DeleteProfile(profileId); return NoContent(); } @@ -109,17 +109,17 @@ namespace Jellyfin.Api.Controllers /// /// Updates a profile. /// - /// Profile id. + /// Profile id. /// Device profile. /// Device profile updated. /// Device profile not found. /// A on success, or a if profile not found. - [HttpPost("Profiles/{Id}")] + [HttpPost("Profiles/{profileId}")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult UpdateProfile([FromRoute] string id, [FromBody] DeviceProfile deviceProfile) + public ActionResult UpdateProfile([FromRoute] string profileId, [FromBody] DeviceProfile deviceProfile) { - var existingDeviceProfile = _dlnaManager.GetProfile(id); + var existingDeviceProfile = _dlnaManager.GetProfile(profileId); if (existingDeviceProfile == null) { return NotFound();