2021-05-05 10:57:01 +00:00
|
|
|
using System;
|
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;
|
2021-06-19 16:02:33 +00:00
|
|
|
using Jellyfin.Extensions.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;
|
|
|
|
|
2021-03-09 04:57:38 +00:00
|
|
|
private readonly JsonSerializerOptions _serializerOptions = JsonDefaults.Options;
|
2020-07-14 18:20:24 +00:00
|
|
|
|
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-08 00:45:06 +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>
|
2022-04-09 14:45:13 +00:00
|
|
|
/// <param name="configuration">Configuration.</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)]
|
2022-04-09 14:45:13 +00:00
|
|
|
public ActionResult UpdateNamedConfiguration([FromRoute, Required] string key, [FromBody, Required] JsonDocument configuration)
|
2020-04-22 19:07:21 +00:00
|
|
|
{
|
|
|
|
var configurationType = _configurationManager.GetConfigurationType(key);
|
2022-04-09 14:45:13 +00:00
|
|
|
var deserializedConfiguration = configuration.Deserialize(configurationType, _serializerOptions);
|
|
|
|
|
|
|
|
if (deserializedConfiguration == null)
|
2021-05-05 10:57:01 +00:00
|
|
|
{
|
|
|
|
throw new ArgumentException("Body doesn't contain a valid configuration");
|
|
|
|
}
|
|
|
|
|
2022-04-09 14:45:13 +00:00
|
|
|
_configurationManager.SaveConfiguration(key, deserializedConfiguration);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|