< Summary - Jellyfin

Information
Class: Jellyfin.Api.Controllers.ClientLogController
Assembly: Jellyfin.Api
File(s): /srv/git/jellyfin/Jellyfin.Api/Controllers/ClientLogController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 11
Coverable lines: 11
Total lines: 78
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
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%
GetRequestInformation()0%4260%

File(s)

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

#LineLine coverage
 1using System.Net.Mime;
 2using System.Threading.Tasks;
 3using Jellyfin.Api.Attributes;
 4using Jellyfin.Api.Extensions;
 5using Jellyfin.Api.Models.ClientLogDtos;
 6using MediaBrowser.Controller.ClientEvent;
 7using MediaBrowser.Controller.Configuration;
 8using Microsoft.AspNetCore.Authorization;
 9using Microsoft.AspNetCore.Http;
 10using Microsoft.AspNetCore.Mvc;
 11
 12namespace Jellyfin.Api.Controllers;
 13
 14/// <summary>
 15/// Client log controller.
 16/// </summary>
 17[Authorize]
 18public class ClientLogController : BaseJellyfinApiController
 19{
 20    private const int MaxDocumentSize = 1_000_000;
 21    private readonly IClientEventLogger _clientEventLogger;
 22    private readonly IServerConfigurationManager _serverConfigurationManager;
 23
 24    /// <summary>
 25    /// Initializes a new instance of the <see cref="ClientLogController"/> class.
 26    /// </summary>
 27    /// <param name="clientEventLogger">Instance of the <see cref="IClientEventLogger"/> interface.</param>
 28    /// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</p
 029    public ClientLogController(
 030        IClientEventLogger clientEventLogger,
 031        IServerConfigurationManager serverConfigurationManager)
 32    {
 033        _clientEventLogger = clientEventLogger;
 034        _serverConfigurationManager = serverConfigurationManager;
 035    }
 36
 37    /// <summary>
 38    /// Upload a document.
 39    /// </summary>
 40    /// <response code="200">Document saved.</response>
 41    /// <response code="403">Event logging disabled.</response>
 42    /// <response code="413">Upload size too large.</response>
 43    /// <returns>Create response.</returns>
 44    [HttpPost("Document")]
 45    [ProducesResponseType(typeof(ClientLogDocumentResponseDto), StatusCodes.Status200OK)]
 46    [ProducesResponseType(StatusCodes.Status403Forbidden)]
 47    [ProducesResponseType(StatusCodes.Status413PayloadTooLarge)]
 48    [AcceptsFile(MediaTypeNames.Text.Plain)]
 49    [RequestSizeLimit(MaxDocumentSize)]
 50    public async Task<ActionResult<ClientLogDocumentResponseDto>> LogFile()
 51    {
 52        if (!_serverConfigurationManager.Configuration.AllowClientLogUpload)
 53        {
 54            return Forbid();
 55        }
 56
 57        if (Request.ContentLength > MaxDocumentSize)
 58        {
 59            // Manually validate to return proper status code.
 60            return StatusCode(StatusCodes.Status413PayloadTooLarge, $"Payload must be less than {MaxDocumentSize:N0} byt
 61        }
 62
 63        var (clientName, clientVersion) = GetRequestInformation();
 64        var fileName = await _clientEventLogger.WriteDocumentAsync(clientName, clientVersion, Request.Body)
 65            .ConfigureAwait(false);
 66        return Ok(new ClientLogDocumentResponseDto(fileName));
 67    }
 68
 69    private (string ClientName, string ClientVersion) GetRequestInformation()
 70    {
 071        var clientName = HttpContext.User.GetClient() ?? "unknown-client";
 072        var clientVersion = HttpContext.User.GetIsApiKey()
 073            ? "apikey"
 074            : HttpContext.User.GetVersion() ?? "unknown-version";
 75
 076        return (clientName, clientVersion);
 77    }
 78}