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-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;
|
2023-11-10 16:17:22 +00:00
|
|
|
using MediaBrowser.Common.Api;
|
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;
|
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
namespace Jellyfin.Api.Controllers;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Configuration Controller.
|
|
|
|
/// </summary>
|
|
|
|
[Route("System")]
|
2023-02-08 22:55:26 +00:00
|
|
|
[Authorize]
|
2023-01-31 11:18:10 +00:00
|
|
|
public class ConfigurationController : BaseJellyfinApiController
|
2020-04-22 19:07:21 +00:00
|
|
|
{
|
2023-01-31 11:18:10 +00:00
|
|
|
private readonly IServerConfigurationManager _configurationManager;
|
|
|
|
private readonly IMediaEncoder _mediaEncoder;
|
|
|
|
|
|
|
|
private readonly JsonSerializerOptions _serializerOptions = JsonDefaults.Options;
|
|
|
|
|
2020-04-22 19:07:21 +00:00
|
|
|
/// <summary>
|
2023-01-31 11:18:10 +00:00
|
|
|
/// Initializes a new instance of the <see cref="ConfigurationController"/> class.
|
2020-04-22 19:07:21 +00:00
|
|
|
/// </summary>
|
2023-01-31 11:18:10 +00:00
|
|
|
/// <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,
|
|
|
|
IMediaEncoder mediaEncoder)
|
2020-04-22 19:07:21 +00:00
|
|
|
{
|
2023-01-31 11:18:10 +00:00
|
|
|
_configurationManager = configurationManager;
|
|
|
|
_mediaEncoder = mediaEncoder;
|
|
|
|
}
|
2020-04-22 19:07:21 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets application configuration.
|
|
|
|
/// </summary>
|
|
|
|
/// <response code="200">Application configuration returned.</response>
|
|
|
|
/// <returns>Application configuration.</returns>
|
|
|
|
[HttpGet("Configuration")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
public ActionResult<ServerConfiguration> GetConfiguration()
|
|
|
|
{
|
|
|
|
return _configurationManager.Configuration;
|
|
|
|
}
|
2020-07-14 18:20:24 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Updates application configuration.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="configuration">Configuration.</param>
|
|
|
|
/// <response code="204">Configuration updated.</response>
|
|
|
|
/// <returns>Update status.</returns>
|
|
|
|
[HttpPost("Configuration")]
|
|
|
|
[Authorize(Policy = Policies.RequiresElevation)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
public ActionResult UpdateConfiguration([FromBody, Required] ServerConfiguration configuration)
|
|
|
|
{
|
|
|
|
_configurationManager.ReplaceConfiguration(configuration);
|
|
|
|
return NoContent();
|
|
|
|
}
|
2020-04-22 19:07:21 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets a named configuration.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="key">Configuration key.</param>
|
|
|
|
/// <response code="200">Configuration returned.</response>
|
|
|
|
/// <returns>Configuration.</returns>
|
|
|
|
[HttpGet("Configuration/{key}")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
[ProducesFile(MediaTypeNames.Application.Json)]
|
|
|
|
public ActionResult<object> GetNamedConfiguration([FromRoute, Required] string key)
|
|
|
|
{
|
|
|
|
return _configurationManager.GetConfiguration(key);
|
|
|
|
}
|
2020-04-22 19:07:21 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Updates named configuration.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="key">Configuration key.</param>
|
|
|
|
/// <param name="configuration">Configuration.</param>
|
|
|
|
/// <response code="204">Named configuration updated.</response>
|
|
|
|
/// <returns>Update status.</returns>
|
|
|
|
[HttpPost("Configuration/{key}")]
|
|
|
|
[Authorize(Policy = Policies.RequiresElevation)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
public ActionResult UpdateNamedConfiguration([FromRoute, Required] string key, [FromBody, Required] JsonDocument configuration)
|
|
|
|
{
|
|
|
|
var configurationType = _configurationManager.GetConfigurationType(key);
|
|
|
|
var deserializedConfiguration = configuration.Deserialize(configurationType, _serializerOptions);
|
2020-04-22 19:07:21 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
if (deserializedConfiguration is null)
|
2020-04-22 19:07:21 +00:00
|
|
|
{
|
2023-01-31 11:18:10 +00:00
|
|
|
throw new ArgumentException("Body doesn't contain a valid configuration");
|
2020-04-22 19:07:21 +00:00
|
|
|
}
|
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
_configurationManager.SaveConfiguration(key, deserializedConfiguration);
|
|
|
|
return NoContent();
|
|
|
|
}
|
2020-04-22 19:07:21 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets a default MetadataOptions object.
|
|
|
|
/// </summary>
|
|
|
|
/// <response code="200">Metadata options returned.</response>
|
|
|
|
/// <returns>Default MetadataOptions.</returns>
|
|
|
|
[HttpGet("Configuration/MetadataOptions/Default")]
|
|
|
|
[Authorize(Policy = Policies.RequiresElevation)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
public ActionResult<MetadataOptions> GetDefaultMetadataOptions()
|
|
|
|
{
|
|
|
|
return new MetadataOptions();
|
|
|
|
}
|
2020-04-22 19:07:21 +00:00
|
|
|
|
2023-01-31 11:18:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Updates the path to the media encoder.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="mediaEncoderPath">Media encoder path form body.</param>
|
|
|
|
/// <response code="204">Media encoder path updated.</response>
|
|
|
|
/// <returns>Status.</returns>
|
2024-03-28 19:57:55 +00:00
|
|
|
[Obsolete("This endpoint is obsolete.")]
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
2023-01-31 11:18:10 +00:00
|
|
|
[HttpPost("MediaEncoder/Path")]
|
|
|
|
[Authorize(Policy = Policies.FirstTimeSetupOrElevated)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
public ActionResult UpdateMediaEncoderPath([FromBody, Required] MediaEncoderPathDto mediaEncoderPath)
|
|
|
|
{
|
2024-03-28 19:57:55 +00:00
|
|
|
// API ENDPOINT DISABLED (NOOP) FOR SECURITY PURPOSES
|
|
|
|
// _mediaEncoder.UpdateEncoderPath(mediaEncoderPath.Path, mediaEncoderPath.PathType);
|
2023-01-31 11:18:10 +00:00
|
|
|
return NoContent();
|
2020-04-22 19:07:21 +00:00
|
|
|
}
|
|
|
|
}
|