Files
wjones af1152b001 Refactor: standardize namespace and using directive style
Refactored all C# test files to use explicit namespace declarations and moved all using directives inside the namespace block for consistency. Updated assembly info and cache files to reflect the new build. Adjusted MvcTestingAppManifest.json to use fully qualified assembly names. No functional changes; all updates are related to code style, organization, and project metadata.
2026-02-20 16:26:53 -05:00

58 lines
1.8 KiB
C#

// <copyright file="FileResponseFilter.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace Jellyfin.Server.Filters
{
using System;
using System.Linq;
using Jellyfin.Api.Attributes;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
/// <inheritdoc />
public class FileResponseFilter : IOperationFilter
{
private const string SuccessCode = "200";
private static readonly OpenApiMediaType _openApiMediaType = new OpenApiMediaType
{
Schema = new OpenApiSchema
{
Type = "string",
Format = "binary"
}
};
/// <inheritdoc />
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
foreach (var attribute in context.ApiDescription.ActionDescriptor.EndpointMetadata)
{
if (attribute is ProducesFileAttribute producesFileAttribute)
{
// Get operation response values.
var response = operation.Responses
.FirstOrDefault(o => o.Key.Equals(SuccessCode, StringComparison.Ordinal));
// Operation doesn't have a response.
if (response.Value is null)
{
continue;
}
// Clear existing responses.
response.Value.Content.Clear();
// Add all content-types as file.
foreach (var contentType in producesFileAttribute.ContentTypes)
{
response.Value.Content.Add(contentType, _openApiMediaType);
}
break;
}
}
}
}
}