2020-04-22 00:12:46 +00:00
|
|
|
using System.Collections.Generic;
|
2020-09-05 23:11:44 +00:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2020-07-31 16:14:09 +00:00
|
|
|
using Jellyfin.Api.Constants;
|
2020-04-22 00:12:46 +00:00
|
|
|
using MediaBrowser.Controller.Dlna;
|
|
|
|
using MediaBrowser.Model.Dlna;
|
2020-07-31 16:14:09 +00:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2020-04-22 00:12:46 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.Controllers
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Dlna Controller.
|
|
|
|
/// </summary>
|
2020-07-31 16:14:09 +00:00
|
|
|
[Authorize(Policy = Policies.RequiresElevation)]
|
2020-04-22 00:12:46 +00:00
|
|
|
public class DlnaController : BaseJellyfinApiController
|
|
|
|
{
|
|
|
|
private readonly IDlnaManager _dlnaManager;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="DlnaController"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dlnaManager">Instance of the <see cref="IDlnaManager"/> interface.</param>
|
|
|
|
public DlnaController(IDlnaManager dlnaManager)
|
|
|
|
{
|
|
|
|
_dlnaManager = dlnaManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get profile infos.
|
|
|
|
/// </summary>
|
2020-07-31 16:14:09 +00:00
|
|
|
/// <response code="200">Device profile infos returned.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the device profile infos.</returns>
|
2020-04-22 00:12:46 +00:00
|
|
|
[HttpGet("ProfileInfos")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-07-31 16:14:09 +00:00
|
|
|
public ActionResult<IEnumerable<DeviceProfileInfo>> GetProfileInfos()
|
2020-04-22 00:12:46 +00:00
|
|
|
{
|
2020-07-31 16:14:09 +00:00
|
|
|
return Ok(_dlnaManager.GetProfileInfos());
|
2020-04-22 00:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the default profile.
|
|
|
|
/// </summary>
|
2020-07-31 16:14:09 +00:00
|
|
|
/// <response code="200">Default device profile returned.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the default profile.</returns>
|
2020-04-22 00:12:46 +00:00
|
|
|
[HttpGet("Profiles/Default")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-07-31 16:14:09 +00:00
|
|
|
public ActionResult<DeviceProfile> GetDefaultProfile()
|
2020-04-22 00:12:46 +00:00
|
|
|
{
|
2020-07-31 16:14:09 +00:00
|
|
|
return _dlnaManager.GetDefaultProfile();
|
2020-04-22 00:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets a single profile.
|
|
|
|
/// </summary>
|
2020-07-31 16:17:01 +00:00
|
|
|
/// <param name="profileId">Profile Id.</param>
|
2020-07-31 16:14:09 +00:00
|
|
|
/// <response code="200">Device profile returned.</response>
|
|
|
|
/// <response code="404">Device profile not found.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the profile on success, or a <see cref="NotFoundResult"/> if device profile not found.</returns>
|
2020-07-31 16:17:01 +00:00
|
|
|
[HttpGet("Profiles/{profileId}")]
|
2020-04-22 00:12:46 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public ActionResult<DeviceProfile> GetProfile([FromRoute, Required] string profileId)
|
2020-04-22 00:12:46 +00:00
|
|
|
{
|
2020-07-31 16:17:01 +00:00
|
|
|
var profile = _dlnaManager.GetProfile(profileId);
|
2020-04-22 00:12:46 +00:00
|
|
|
if (profile == null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
2020-07-31 16:14:09 +00:00
|
|
|
return profile;
|
2020-04-22 00:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Deletes a profile.
|
|
|
|
/// </summary>
|
2020-07-31 16:17:01 +00:00
|
|
|
/// <param name="profileId">Profile id.</param>
|
2020-07-31 16:14:09 +00:00
|
|
|
/// <response code="204">Device profile deleted.</response>
|
|
|
|
/// <response code="404">Device profile not found.</response>
|
|
|
|
/// <returns>A <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if profile not found.</returns>
|
2020-07-31 16:17:01 +00:00
|
|
|
[HttpDelete("Profiles/{profileId}")]
|
2020-07-31 16:14:09 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-04-22 00:12:46 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public ActionResult DeleteProfile([FromRoute, Required] string profileId)
|
2020-04-22 00:12:46 +00:00
|
|
|
{
|
2020-07-31 16:17:01 +00:00
|
|
|
var existingDeviceProfile = _dlnaManager.GetProfile(profileId);
|
2020-04-22 00:12:46 +00:00
|
|
|
if (existingDeviceProfile == null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
2020-07-31 16:17:01 +00:00
|
|
|
_dlnaManager.DeleteProfile(profileId);
|
2020-07-31 16:14:09 +00:00
|
|
|
return NoContent();
|
2020-04-22 00:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a profile.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="deviceProfile">Device profile.</param>
|
2020-07-31 16:14:09 +00:00
|
|
|
/// <response code="204">Device profile created.</response>
|
|
|
|
/// <returns>A <see cref="NoContentResult"/>.</returns>
|
2020-04-22 00:12:46 +00:00
|
|
|
[HttpPost("Profiles")]
|
2020-07-31 16:14:09 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-04-22 00:12:46 +00:00
|
|
|
public ActionResult CreateProfile([FromBody] DeviceProfile deviceProfile)
|
|
|
|
{
|
|
|
|
_dlnaManager.CreateProfile(deviceProfile);
|
2020-07-31 16:14:09 +00:00
|
|
|
return NoContent();
|
2020-04-22 00:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates a profile.
|
|
|
|
/// </summary>
|
2020-07-31 16:17:01 +00:00
|
|
|
/// <param name="profileId">Profile id.</param>
|
2020-04-22 00:12:46 +00:00
|
|
|
/// <param name="deviceProfile">Device profile.</param>
|
2020-07-31 16:14:09 +00:00
|
|
|
/// <response code="204">Device profile updated.</response>
|
|
|
|
/// <response code="404">Device profile not found.</response>
|
|
|
|
/// <returns>A <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if profile not found.</returns>
|
2020-07-31 16:17:01 +00:00
|
|
|
[HttpPost("Profiles/{profileId}")]
|
2020-07-31 16:14:09 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-04-22 00:12:46 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public ActionResult UpdateProfile([FromRoute, Required] string profileId, [FromBody] DeviceProfile deviceProfile)
|
2020-04-22 00:12:46 +00:00
|
|
|
{
|
2020-07-31 16:17:01 +00:00
|
|
|
var existingDeviceProfile = _dlnaManager.GetProfile(profileId);
|
2020-04-22 00:12:46 +00:00
|
|
|
if (existingDeviceProfile == null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
2021-10-31 14:49:24 +00:00
|
|
|
_dlnaManager.UpdateProfile(profileId, deviceProfile);
|
2020-07-31 16:14:09 +00:00
|
|
|
return NoContent();
|
2020-04-22 00:12:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|