aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Filters/FileRequestFilter.cs
diff options
context:
space:
mode:
authorBaronGreenback <jimcartlidge@yahoo.co.uk>2021-02-21 00:44:14 +0000
committerGitHub <noreply@github.com>2021-02-21 00:44:14 +0000
commit5756c6dbad8734171ee539e1a73d15c907168d93 (patch)
tree6d2f238a64f2ed233eadd1139af78a8c72d6cf21 /Jellyfin.Server/Filters/FileRequestFilter.cs
parentcb09096a59c0df9b02f4c057db93d8479678af8f (diff)
parent55dd0da5dae868a944e729e41973755eaff8d230 (diff)
Merge branch 'master' into bindfix
Diffstat (limited to 'Jellyfin.Server/Filters/FileRequestFilter.cs')
-rw-r--r--Jellyfin.Server/Filters/FileRequestFilter.cs43
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;
+ }
+ }
+}