DlnaController.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System.Collections.Generic;
  2. using System.ComponentModel.DataAnnotations;
  3. using Jellyfin.Api.Constants;
  4. using MediaBrowser.Controller.Dlna;
  5. using MediaBrowser.Model.Dlna;
  6. using Microsoft.AspNetCore.Authorization;
  7. using Microsoft.AspNetCore.Http;
  8. using Microsoft.AspNetCore.Mvc;
  9. namespace Jellyfin.Api.Controllers
  10. {
  11. /// <summary>
  12. /// Dlna Controller.
  13. /// </summary>
  14. [Authorize(Policy = Policies.RequiresElevation)]
  15. public class DlnaController : BaseJellyfinApiController
  16. {
  17. private readonly IDlnaManager _dlnaManager;
  18. /// <summary>
  19. /// Initializes a new instance of the <see cref="DlnaController"/> class.
  20. /// </summary>
  21. /// <param name="dlnaManager">Instance of the <see cref="IDlnaManager"/> interface.</param>
  22. public DlnaController(IDlnaManager dlnaManager)
  23. {
  24. _dlnaManager = dlnaManager;
  25. }
  26. /// <summary>
  27. /// Get profile infos.
  28. /// </summary>
  29. /// <response code="200">Device profile infos returned.</response>
  30. /// <returns>An <see cref="OkResult"/> containing the device profile infos.</returns>
  31. [HttpGet("ProfileInfos")]
  32. [ProducesResponseType(StatusCodes.Status200OK)]
  33. public ActionResult<IEnumerable<DeviceProfileInfo>> GetProfileInfos()
  34. {
  35. return Ok(_dlnaManager.GetProfileInfos());
  36. }
  37. /// <summary>
  38. /// Gets the default profile.
  39. /// </summary>
  40. /// <response code="200">Default device profile returned.</response>
  41. /// <returns>An <see cref="OkResult"/> containing the default profile.</returns>
  42. [HttpGet("Profiles/Default")]
  43. [ProducesResponseType(StatusCodes.Status200OK)]
  44. public ActionResult<DeviceProfile> GetDefaultProfile()
  45. {
  46. return _dlnaManager.GetDefaultProfile();
  47. }
  48. /// <summary>
  49. /// Gets a single profile.
  50. /// </summary>
  51. /// <param name="profileId">Profile Id.</param>
  52. /// <response code="200">Device profile returned.</response>
  53. /// <response code="404">Device profile not found.</response>
  54. /// <returns>An <see cref="OkResult"/> containing the profile on success, or a <see cref="NotFoundResult"/> if device profile not found.</returns>
  55. [HttpGet("Profiles/{profileId}")]
  56. [ProducesResponseType(StatusCodes.Status200OK)]
  57. [ProducesResponseType(StatusCodes.Status404NotFound)]
  58. public ActionResult<DeviceProfile> GetProfile([FromRoute, Required] string profileId)
  59. {
  60. var profile = _dlnaManager.GetProfile(profileId);
  61. if (profile == null)
  62. {
  63. return NotFound();
  64. }
  65. return profile;
  66. }
  67. /// <summary>
  68. /// Deletes a profile.
  69. /// </summary>
  70. /// <param name="profileId">Profile id.</param>
  71. /// <response code="204">Device profile deleted.</response>
  72. /// <response code="404">Device profile not found.</response>
  73. /// <returns>A <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if profile not found.</returns>
  74. [HttpDelete("Profiles/{profileId}")]
  75. [ProducesResponseType(StatusCodes.Status204NoContent)]
  76. [ProducesResponseType(StatusCodes.Status404NotFound)]
  77. public ActionResult DeleteProfile([FromRoute, Required] string profileId)
  78. {
  79. var existingDeviceProfile = _dlnaManager.GetProfile(profileId);
  80. if (existingDeviceProfile == null)
  81. {
  82. return NotFound();
  83. }
  84. _dlnaManager.DeleteProfile(profileId);
  85. return NoContent();
  86. }
  87. /// <summary>
  88. /// Creates a profile.
  89. /// </summary>
  90. /// <param name="deviceProfile">Device profile.</param>
  91. /// <response code="204">Device profile created.</response>
  92. /// <returns>A <see cref="NoContentResult"/>.</returns>
  93. [HttpPost("Profiles")]
  94. [ProducesResponseType(StatusCodes.Status204NoContent)]
  95. public ActionResult CreateProfile([FromBody] DeviceProfile deviceProfile)
  96. {
  97. _dlnaManager.CreateProfile(deviceProfile);
  98. return NoContent();
  99. }
  100. /// <summary>
  101. /// Updates a profile.
  102. /// </summary>
  103. /// <param name="profileId">Profile id.</param>
  104. /// <param name="deviceProfile">Device profile.</param>
  105. /// <response code="204">Device profile updated.</response>
  106. /// <response code="404">Device profile not found.</response>
  107. /// <returns>A <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if profile not found.</returns>
  108. [HttpPost("Profiles/{profileId}")]
  109. [ProducesResponseType(StatusCodes.Status204NoContent)]
  110. [ProducesResponseType(StatusCodes.Status404NotFound)]
  111. public ActionResult UpdateProfile([FromRoute, Required] string profileId, [FromBody] DeviceProfile deviceProfile)
  112. {
  113. var existingDeviceProfile = _dlnaManager.GetProfile(profileId);
  114. if (existingDeviceProfile == null)
  115. {
  116. return NotFound();
  117. }
  118. _dlnaManager.UpdateProfile(deviceProfile);
  119. return NoContent();
  120. }
  121. }
  122. }