< Summary - Jellyfin

Information
Class: Jellyfin.Server.Filters.FileResponseFilter
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Filters/FileResponseFilter.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 53
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
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
.cctor()100%11100%
Apply(...)100%88100%

File(s)

/srv/git/jellyfin/Jellyfin.Server/Filters/FileResponseFilter.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using Jellyfin.Api.Attributes;
 4using Microsoft.OpenApi.Models;
 5using Swashbuckle.AspNetCore.SwaggerGen;
 6
 7namespace Jellyfin.Server.Filters
 8{
 9    /// <inheritdoc />
 10    public class FileResponseFilter : IOperationFilter
 11    {
 12        private const string SuccessCode = "200";
 113        private static readonly OpenApiMediaType _openApiMediaType = new OpenApiMediaType
 114        {
 115            Schema = new OpenApiSchema
 116            {
 117                Type = "string",
 118                Format = "binary"
 119            }
 120        };
 21
 22        /// <inheritdoc />
 23        public void Apply(OpenApiOperation operation, OperationFilterContext context)
 24        {
 897225            foreach (var attribute in context.ApiDescription.ActionDescriptor.EndpointMetadata)
 26            {
 413927                if (attribute is ProducesFileAttribute producesFileAttribute)
 28                {
 29                    // Get operation response values.
 6830                    var response = operation.Responses
 6831                        .FirstOrDefault(o => o.Key.Equals(SuccessCode, StringComparison.Ordinal));
 32
 33                    // Operation doesn't have a response.
 6834                    if (response.Value is null)
 35                    {
 36                        continue;
 37                    }
 38
 39                    // Clear existing responses.
 6840                    response.Value.Content.Clear();
 41
 42                    // Add all content-types as file.
 27843                    foreach (var contentType in producesFileAttribute.ContentTypes)
 44                    {
 7145                        response.Value.Content.Add(contentType, _openApiMediaType);
 46                    }
 47
 6848                    break;
 49                }
 50            }
 38151        }
 52    }
 53}