2020-08-06 14:17:45 +00:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2020-09-01 23:26:49 +00:00
|
|
|
using System.Net.Mime;
|
2020-06-01 17:06:15 +00:00
|
|
|
using System.Text.Json;
|
2020-04-22 19:07:21 +00:00
|
|
|
using System.Threading.Tasks;
|
2020-09-01 23:26:49 +00:00
|
|
|
using Jellyfin.Api.Attributes;
|
2020-04-23 16:03:54 +00:00
|
|
|
using Jellyfin.Api.Constants;
|
2020-04-22 19:07:21 +00:00
|
|
|
using Jellyfin.Api.Models.ConfigurationDtos;
|
2020-07-12 18:11:59 +00:00
|
|
|
using MediaBrowser.Common.Json;
|
2020-04-22 19:07:21 +00:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
|
|
|
using MediaBrowser.Model.Configuration;
|
2020-04-23 16:03:54 +00:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2020-04-22 19:07:21 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.Controllers
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Configuration Controller.
|
|
|
|
/// </summary>
|
|
|
|
[Route("System")]
|
2020-06-16 20:15:58 +00:00
|
|
|
[Authorize(Policy = Policies.DefaultAuthorization)]
|
2020-04-22 19:07:21 +00:00
|
|
|
public class ConfigurationController : BaseJellyfinApiController
|
|
|
|
{
|
|
|
|
private readonly IServerConfigurationManager _configurationManager;
|
|
|
|
private readonly IMediaEncoder _mediaEncoder;
|
|
|
|
|
2020-07-14 18:20:24 +00:00
|
|
|
private readonly JsonSerializerOptions _serializerOptions = JsonDefaults.GetOptions();
|
|
|
|
|
2020-04-22 19:07:21 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="ConfigurationController"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="configurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
|
|
|
|
/// <param name="mediaEncoder">Instance of the <see cref="IMediaEncoder"/> interface.</param>
|
|
|
|
public ConfigurationController(
|
|
|
|
IServerConfigurationManager configurationManager,
|
2020-06-01 17:06:15 +00:00
|
|
|
IMediaEncoder mediaEncoder)
|
2020-04-22 19:07:21 +00:00
|
|
|
{
|
|
|
|
_configurationManager = configurationManager;
|
|
|
|
_mediaEncoder = mediaEncoder;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets application configuration.
|
|
|
|
/// </summary>
|
2020-05-19 15:29:59 +00:00
|
|
|
/// <response code="200">Application configuration returned.</response>
|
2020-04-22 19:07:21 +00:00
|
|
|
/// <returns>Application configuration.</returns>
|
|
|
|
[HttpGet("Configuration")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
public ActionResult<ServerConfiguration> GetConfiguration()
|
|
|
|
{
|
2020-04-23 16:03:54 +00:00
|
|
|
return _configurationManager.Configuration;
|
2020-04-22 19:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates application configuration.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="configuration">Configuration.</param>
|
2020-06-12 10:38:13 +00:00
|
|
|
/// <response code="204">Configuration updated.</response>
|
2020-05-19 15:29:59 +00:00
|
|
|
/// <returns>Update status.</returns>
|
2020-04-22 19:07:21 +00:00
|
|
|
[HttpPost("Configuration")]
|
2020-04-23 16:03:54 +00:00
|
|
|
[Authorize(Policy = Policies.RequiresElevation)]
|
2020-06-12 10:38:13 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-08-06 14:17:45 +00:00
|
|
|
public ActionResult UpdateConfiguration([FromBody, Required] ServerConfiguration configuration)
|
2020-04-22 19:07:21 +00:00
|
|
|
{
|
|
|
|
_configurationManager.ReplaceConfiguration(configuration);
|
2020-06-12 10:38:13 +00:00
|
|
|
return NoContent();
|
2020-04-22 19:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets a named configuration.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="key">Configuration key.</param>
|
2020-05-19 15:29:59 +00:00
|
|
|
/// <response code="200">Configuration returned.</response>
|
2020-04-22 19:07:21 +00:00
|
|
|
/// <returns>Configuration.</returns>
|
2020-06-21 00:02:07 +00:00
|
|
|
[HttpGet("Configuration/{key}")]
|
2020-04-22 19:07:21 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-09-01 23:26:49 +00:00
|
|
|
[ProducesFile(MediaTypeNames.Application.Json)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public ActionResult<object> GetNamedConfiguration([FromRoute, Required] string? key)
|
2020-04-22 19:07:21 +00:00
|
|
|
{
|
2020-04-23 16:03:54 +00:00
|
|
|
return _configurationManager.GetConfiguration(key);
|
2020-04-22 19:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates named configuration.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="key">Configuration key.</param>
|
2020-06-12 10:38:13 +00:00
|
|
|
/// <response code="204">Named configuration updated.</response>
|
2020-05-19 15:29:59 +00:00
|
|
|
/// <returns>Update status.</returns>
|
2020-06-21 00:02:07 +00:00
|
|
|
[HttpPost("Configuration/{key}")]
|
2020-04-23 16:03:54 +00:00
|
|
|
[Authorize(Policy = Policies.RequiresElevation)]
|
2020-06-12 10:38:13 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public async Task<ActionResult> UpdateNamedConfiguration([FromRoute, Required] string? key)
|
2020-04-22 19:07:21 +00:00
|
|
|
{
|
|
|
|
var configurationType = _configurationManager.GetConfigurationType(key);
|
2020-07-14 18:20:24 +00:00
|
|
|
var configuration = await JsonSerializer.DeserializeAsync(Request.Body, configurationType, _serializerOptions).ConfigureAwait(false);
|
2020-04-22 19:07:21 +00:00
|
|
|
_configurationManager.SaveConfiguration(key, configuration);
|
2020-06-12 10:38:13 +00:00
|
|
|
return NoContent();
|
2020-04-22 19:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets a default MetadataOptions object.
|
|
|
|
/// </summary>
|
2020-05-19 15:29:59 +00:00
|
|
|
/// <response code="200">Metadata options returned.</response>
|
|
|
|
/// <returns>Default MetadataOptions.</returns>
|
2020-04-22 19:07:21 +00:00
|
|
|
[HttpGet("Configuration/MetadataOptions/Default")]
|
2020-04-23 16:03:54 +00:00
|
|
|
[Authorize(Policy = Policies.RequiresElevation)]
|
2020-04-22 19:07:21 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
public ActionResult<MetadataOptions> GetDefaultMetadataOptions()
|
|
|
|
{
|
2020-04-23 16:03:54 +00:00
|
|
|
return new MetadataOptions();
|
2020-04-22 19:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates the path to the media encoder.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="mediaEncoderPath">Media encoder path form body.</param>
|
2020-06-12 10:38:13 +00:00
|
|
|
/// <response code="204">Media encoder path updated.</response>
|
2020-04-22 19:07:21 +00:00
|
|
|
/// <returns>Status.</returns>
|
|
|
|
[HttpPost("MediaEncoder/Path")]
|
2020-04-23 16:03:54 +00:00
|
|
|
[Authorize(Policy = Policies.FirstTimeSetupOrElevated)]
|
2020-06-12 10:38:13 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-08-20 13:53:53 +00:00
|
|
|
public ActionResult UpdateMediaEncoderPath([FromBody, Required] MediaEncoderPathDto mediaEncoderPath)
|
2020-04-22 19:07:21 +00:00
|
|
|
{
|
|
|
|
_mediaEncoder.UpdateEncoderPath(mediaEncoderPath.Path, mediaEncoderPath.PathType);
|
2020-06-12 10:38:13 +00:00
|
|
|
return NoContent();
|
2020-04-22 19:07:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|