diff options
| author | David <daullmer@gmail.com> | 2021-02-13 22:55:33 +0100 |
|---|---|---|
| committer | David <daullmer@gmail.com> | 2021-02-13 22:55:33 +0100 |
| commit | fc7377fb9bf2b227a8a2300e6909d7c74862c8ab (patch) | |
| tree | 667966225e0aa2a4dce983f744f07581e5bfd37f /Jellyfin.Server/Filters/FileRequestFilter.cs | |
| parent | 7f12b273197204c49862623b6de6b1a573af2cd8 (diff) | |
| parent | 6616add8c8526456e343d7b576d22df0ed261124 (diff) | |
Merge remote-tracking branch 'jellyfin/master' into nfo-tests
# Conflicts:
# tests/Jellyfin.XbmcMetadata.Tests/Parsers/EpisodeNfoProviderTests.cs
# tests/Jellyfin.XbmcMetadata.Tests/Parsers/SeriesNfoParserTests.cs
Diffstat (limited to 'Jellyfin.Server/Filters/FileRequestFilter.cs')
| -rw-r--r-- | Jellyfin.Server/Filters/FileRequestFilter.cs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Jellyfin.Server/Filters/FileRequestFilter.cs b/Jellyfin.Server/Filters/FileRequestFilter.cs new file mode 100644 index 000000000..69e10994f --- /dev/null +++ b/Jellyfin.Server/Filters/FileRequestFilter.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using Jellyfin.Api.Attributes; +using Microsoft.OpenApi.Models; +using Swashbuckle.AspNetCore.SwaggerGen; + +namespace Jellyfin.Server.Filters +{ + /// <inheritdoc /> + public class FileRequestFilter : IOperationFilter + { + /// <inheritdoc /> + public void Apply(OpenApiOperation operation, OperationFilterContext context) + { + foreach (var attribute in context.ApiDescription.ActionDescriptor.EndpointMetadata) + { + if (attribute is AcceptsFileAttribute acceptsFileAttribute) + { + operation.RequestBody = GetRequestBody(acceptsFileAttribute.GetContentTypes()); + break; + } + } + } + + private static OpenApiRequestBody GetRequestBody(IEnumerable<string> contentTypes) + { + var body = new OpenApiRequestBody(); + var mediaType = new OpenApiMediaType + { + Schema = new OpenApiSchema + { + Type = "string", + Format = "binary" + } + }; + foreach (var contentType in contentTypes) + { + body.Content.Add(contentType, mediaType); + } + + return body; + } + } +} |
