< Summary - Jellyfin

Information
Class: Jellyfin.Api.Controllers.ConfigurationController
Assembly: Jellyfin.Api
File(s): /srv/git/jellyfin/Jellyfin.Api/Controllers/ConfigurationController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 24
Coverable lines: 24
Total lines: 164
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
GetConfiguration()100%210%
UpdateConfiguration(...)100%210%
GetNamedConfiguration(...)100%210%
UpdateNamedConfiguration(...)0%620%
GetDefaultMetadataOptions()100%210%
UpdateBrandingConfiguration(...)100%210%

File(s)

/srv/git/jellyfin/Jellyfin.Api/Controllers/ConfigurationController.cs

#LineLine coverage
 1using System;
 2using System.ComponentModel.DataAnnotations;
 3using System.Net.Mime;
 4using System.Text.Json;
 5using Jellyfin.Api.Attributes;
 6using Jellyfin.Api.Constants;
 7using Jellyfin.Api.Models.ConfigurationDtos;
 8using Jellyfin.Extensions.Json;
 9using MediaBrowser.Common.Api;
 10using MediaBrowser.Controller.Configuration;
 11using MediaBrowser.Controller.MediaEncoding;
 12using MediaBrowser.Model.Branding;
 13using MediaBrowser.Model.Configuration;
 14using Microsoft.AspNetCore.Authorization;
 15using Microsoft.AspNetCore.Http;
 16using Microsoft.AspNetCore.Mvc;
 17
 18namespace Jellyfin.Api.Controllers;
 19
 20/// <summary>
 21/// Configuration Controller.
 22/// </summary>
 23[Route("System")]
 24[Authorize]
 25public class ConfigurationController : BaseJellyfinApiController
 26{
 27    private readonly IServerConfigurationManager _configurationManager;
 28    private readonly IMediaEncoder _mediaEncoder;
 29
 030    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>
 037    public ConfigurationController(
 038        IServerConfigurationManager configurationManager,
 039        IMediaEncoder mediaEncoder)
 40    {
 041        _configurationManager = configurationManager;
 042        _mediaEncoder = mediaEncoder;
 043    }
 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    {
 054        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    {
 068        _configurationManager.ReplaceConfiguration(configuration);
 069        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    {
 083        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    {
 098        var configurationType = _configurationManager.GetConfigurationType(key);
 099        var deserializedConfiguration = configuration.Deserialize(configurationType, _serializerOptions);
 100
 0101        if (deserializedConfiguration is null)
 102        {
 0103            throw new ArgumentException("Body doesn't contain a valid configuration");
 104        }
 105
 0106        _configurationManager.SaveConfiguration(key, deserializedConfiguration);
 0107        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    {
 0120        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
 0135        var currentBranding = (BrandingOptions)_configurationManager.GetConfiguration("branding");
 136
 137        // Update only the properties from BrandingOptionsDto
 0138        currentBranding.LoginDisclaimer = configuration.LoginDisclaimer;
 0139        currentBranding.CustomCss = configuration.CustomCss;
 0140        currentBranding.SplashscreenEnabled = configuration.SplashscreenEnabled;
 141
 0142        _configurationManager.SaveConfiguration("branding", currentBranding);
 143
 0144        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}