DlnaController.cs 4.8 KB

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