From f5385e4735849cbb1552e69faa0116e5498b3688 Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 21 Apr 2020 18:12:46 -0600 Subject: Move Emby.Dlna DlnaService.cs to Jellyfin.Api --- Jellyfin.Api/Controllers/DlnaController.cs | 124 +++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 Jellyfin.Api/Controllers/DlnaController.cs (limited to 'Jellyfin.Api/Controllers/DlnaController.cs') diff --git a/Jellyfin.Api/Controllers/DlnaController.cs b/Jellyfin.Api/Controllers/DlnaController.cs new file mode 100644 index 000000000..68cd144f4 --- /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(); + } + } +} -- cgit v1.2.3 From 6051df0c47876cd30ea0f39f8ef6ed1f54740a67 Mon Sep 17 00:00:00 2001 From: crobibero Date: Fri, 31 Jul 2020 10:14:09 -0600 Subject: Fix response codes, documentation, and auth --- Jellyfin.Api/Controllers/DlnaController.cs | 52 +++++++++++++++++------------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'Jellyfin.Api/Controllers/DlnaController.cs') diff --git a/Jellyfin.Api/Controllers/DlnaController.cs b/Jellyfin.Api/Controllers/DlnaController.cs index 68cd144f4..dcd31a48b 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(); } } } -- cgit v1.2.3 From 32c0ac96a14bcc42e57f9583d71dd65c804bb577 Mon Sep 17 00:00:00 2001 From: crobibero Date: Fri, 31 Jul 2020 10:17:01 -0600 Subject: fix route params --- Jellyfin.Api/Controllers/DlnaController.cs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'Jellyfin.Api/Controllers/DlnaController.cs') diff --git a/Jellyfin.Api/Controllers/DlnaController.cs b/Jellyfin.Api/Controllers/DlnaController.cs index dcd31a48b..397299a73 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(); -- cgit v1.2.3