| | | 1 | | using System; |
| | | 2 | | using System.ComponentModel.DataAnnotations; |
| | | 3 | | using System.Net.Mime; |
| | | 4 | | using System.Text.Json; |
| | | 5 | | using Jellyfin.Api.Attributes; |
| | | 6 | | using Jellyfin.Api.Constants; |
| | | 7 | | using Jellyfin.Api.Models.ConfigurationDtos; |
| | | 8 | | using Jellyfin.Extensions.Json; |
| | | 9 | | using MediaBrowser.Common.Api; |
| | | 10 | | using MediaBrowser.Controller.Configuration; |
| | | 11 | | using MediaBrowser.Controller.MediaEncoding; |
| | | 12 | | using MediaBrowser.Model.Branding; |
| | | 13 | | using MediaBrowser.Model.Configuration; |
| | | 14 | | using Microsoft.AspNetCore.Authorization; |
| | | 15 | | using Microsoft.AspNetCore.Http; |
| | | 16 | | using Microsoft.AspNetCore.Mvc; |
| | | 17 | | |
| | | 18 | | namespace Jellyfin.Api.Controllers; |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Configuration Controller. |
| | | 22 | | /// </summary> |
| | | 23 | | [Route("System")] |
| | | 24 | | [Authorize] |
| | | 25 | | public class ConfigurationController : BaseJellyfinApiController |
| | | 26 | | { |
| | | 27 | | private readonly IServerConfigurationManager _configurationManager; |
| | | 28 | | private readonly IMediaEncoder _mediaEncoder; |
| | | 29 | | |
| | 0 | 30 | | private readonly JsonSerializerOptions _serializerOptions = JsonDefaults.Options; |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Initializes a new instance of the <see cref="ConfigurationController"/> class. |
| | | 34 | | /// </summary> |
| | | 35 | | /// <param name="configurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param> |
| | | 36 | | /// <param name="mediaEncoder">Instance of the <see cref="IMediaEncoder"/> interface.</param> |
| | 0 | 37 | | public ConfigurationController( |
| | 0 | 38 | | IServerConfigurationManager configurationManager, |
| | 0 | 39 | | IMediaEncoder mediaEncoder) |
| | | 40 | | { |
| | 0 | 41 | | _configurationManager = configurationManager; |
| | 0 | 42 | | _mediaEncoder = mediaEncoder; |
| | 0 | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Gets application configuration. |
| | | 47 | | /// </summary> |
| | | 48 | | /// <response code="200">Application configuration returned.</response> |
| | | 49 | | /// <returns>Application configuration.</returns> |
| | | 50 | | [HttpGet("Configuration")] |
| | | 51 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 52 | | public ActionResult<ServerConfiguration> GetConfiguration() |
| | | 53 | | { |
| | 0 | 54 | | return _configurationManager.Configuration; |
| | | 55 | | } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Updates application configuration. |
| | | 59 | | /// </summary> |
| | | 60 | | /// <param name="configuration">Configuration.</param> |
| | | 61 | | /// <response code="204">Configuration updated.</response> |
| | | 62 | | /// <returns>Update status.</returns> |
| | | 63 | | [HttpPost("Configuration")] |
| | | 64 | | [Authorize(Policy = Policies.RequiresElevation)] |
| | | 65 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | | 66 | | public ActionResult UpdateConfiguration([FromBody, Required] ServerConfiguration configuration) |
| | | 67 | | { |
| | 0 | 68 | | _configurationManager.ReplaceConfiguration(configuration); |
| | 0 | 69 | | return NoContent(); |
| | | 70 | | } |
| | | 71 | | |
| | | 72 | | /// <summary> |
| | | 73 | | /// Gets a named configuration. |
| | | 74 | | /// </summary> |
| | | 75 | | /// <param name="key">Configuration key.</param> |
| | | 76 | | /// <response code="200">Configuration returned.</response> |
| | | 77 | | /// <returns>Configuration.</returns> |
| | | 78 | | [HttpGet("Configuration/{key}")] |
| | | 79 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 80 | | [ProducesFile(MediaTypeNames.Application.Json)] |
| | | 81 | | public ActionResult<object> GetNamedConfiguration([FromRoute, Required] string key) |
| | | 82 | | { |
| | 0 | 83 | | return _configurationManager.GetConfiguration(key); |
| | | 84 | | } |
| | | 85 | | |
| | | 86 | | /// <summary> |
| | | 87 | | /// Updates named configuration. |
| | | 88 | | /// </summary> |
| | | 89 | | /// <param name="key">Configuration key.</param> |
| | | 90 | | /// <param name="configuration">Configuration.</param> |
| | | 91 | | /// <response code="204">Named configuration updated.</response> |
| | | 92 | | /// <returns>Update status.</returns> |
| | | 93 | | [HttpPost("Configuration/{key}")] |
| | | 94 | | [Authorize(Policy = Policies.RequiresElevation)] |
| | | 95 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | | 96 | | public ActionResult UpdateNamedConfiguration([FromRoute, Required] string key, [FromBody, Required] JsonDocument con |
| | | 97 | | { |
| | 0 | 98 | | var configurationType = _configurationManager.GetConfigurationType(key); |
| | 0 | 99 | | var deserializedConfiguration = configuration.Deserialize(configurationType, _serializerOptions); |
| | | 100 | | |
| | 0 | 101 | | if (deserializedConfiguration is null) |
| | | 102 | | { |
| | 0 | 103 | | throw new ArgumentException("Body doesn't contain a valid configuration"); |
| | | 104 | | } |
| | | 105 | | |
| | 0 | 106 | | _configurationManager.SaveConfiguration(key, deserializedConfiguration); |
| | 0 | 107 | | return NoContent(); |
| | | 108 | | } |
| | | 109 | | |
| | | 110 | | /// <summary> |
| | | 111 | | /// Gets a default MetadataOptions object. |
| | | 112 | | /// </summary> |
| | | 113 | | /// <response code="200">Metadata options returned.</response> |
| | | 114 | | /// <returns>Default MetadataOptions.</returns> |
| | | 115 | | [HttpGet("Configuration/MetadataOptions/Default")] |
| | | 116 | | [Authorize(Policy = Policies.RequiresElevation)] |
| | | 117 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 118 | | public ActionResult<MetadataOptions> GetDefaultMetadataOptions() |
| | | 119 | | { |
| | 0 | 120 | | return new MetadataOptions(); |
| | | 121 | | } |
| | | 122 | | |
| | | 123 | | /// <summary> |
| | | 124 | | /// Updates branding configuration. |
| | | 125 | | /// </summary> |
| | | 126 | | /// <param name="configuration">Branding configuration.</param> |
| | | 127 | | /// <response code="204">Branding configuration updated.</response> |
| | | 128 | | /// <returns>Update status.</returns> |
| | | 129 | | [HttpPost("Configuration/Branding")] |
| | | 130 | | [Authorize(Policy = Policies.RequiresElevation)] |
| | | 131 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | | 132 | | public ActionResult UpdateBrandingConfiguration([FromBody, Required] BrandingOptionsDto configuration) |
| | | 133 | | { |
| | | 134 | | // Get the current branding configuration to preserve SplashscreenLocation |
| | 0 | 135 | | var currentBranding = (BrandingOptions)_configurationManager.GetConfiguration("branding"); |
| | | 136 | | |
| | | 137 | | // Update only the properties from BrandingOptionsDto |
| | 0 | 138 | | currentBranding.LoginDisclaimer = configuration.LoginDisclaimer; |
| | 0 | 139 | | currentBranding.CustomCss = configuration.CustomCss; |
| | 0 | 140 | | currentBranding.SplashscreenEnabled = configuration.SplashscreenEnabled; |
| | | 141 | | |
| | 0 | 142 | | _configurationManager.SaveConfiguration("branding", currentBranding); |
| | | 143 | | |
| | 0 | 144 | | return NoContent(); |
| | | 145 | | } |
| | | 146 | | |
| | | 147 | | /// <summary> |
| | | 148 | | /// Updates the path to the media encoder. |
| | | 149 | | /// </summary> |
| | | 150 | | /// <param name="mediaEncoderPath">Media encoder path form body.</param> |
| | | 151 | | /// <response code="204">Media encoder path updated.</response> |
| | | 152 | | /// <returns>Status.</returns> |
| | | 153 | | [Obsolete("This endpoint is obsolete.")] |
| | | 154 | | [ApiExplorerSettings(IgnoreApi = true)] |
| | | 155 | | [HttpPost("MediaEncoder/Path")] |
| | | 156 | | [Authorize(Policy = Policies.FirstTimeSetupOrElevated)] |
| | | 157 | | [ProducesResponseType(StatusCodes.Status204NoContent)] |
| | | 158 | | public ActionResult UpdateMediaEncoderPath([FromBody, Required] MediaEncoderPathDto mediaEncoderPath) |
| | | 159 | | { |
| | | 160 | | // API ENDPOINT DISABLED (NOOP) FOR SECURITY PURPOSES |
| | | 161 | | // _mediaEncoder.UpdateEncoderPath(mediaEncoderPath.Path, mediaEncoderPath.PathType); |
| | | 162 | | return NoContent(); |
| | | 163 | | } |
| | | 164 | | } |