From adf62fb42b3a4ef5103d7768ab3080fc89619223 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 3 Aug 2025 19:48:47 +0800 Subject: [PATCH] :sparkles: Pool support wildcard in accept types --- DysonNetwork.Drive/Storage/TusService.cs | 32 +++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/DysonNetwork.Drive/Storage/TusService.cs b/DysonNetwork.Drive/Storage/TusService.cs index a6a0cb4..f111bb8 100644 --- a/DysonNetwork.Drive/Storage/TusService.cs +++ b/DysonNetwork.Drive/Storage/TusService.cs @@ -228,13 +228,33 @@ public abstract class TusService ); rejected = true; } - else if (!policy.AcceptTypes.Contains(contentType)) + else { - eventContext.FailRequest( - HttpStatusCode.Forbidden, - $"Content type {contentType} is not allowed by the pool's policy" - ); - rejected = true; + var foundMatch = false; + foreach (var acceptType in policy.AcceptTypes) + { + if (acceptType.EndsWith("/*", StringComparison.OrdinalIgnoreCase)) + { + var type = acceptType[..^2]; + if (!contentType.StartsWith($"{type}/", StringComparison.OrdinalIgnoreCase)) continue; + foundMatch = true; + break; + } + else if (acceptType.Equals(contentType, StringComparison.OrdinalIgnoreCase)) + { + foundMatch = true; + break; + } + } + + if (!foundMatch) + { + eventContext.FailRequest( + HttpStatusCode.Forbidden, + $"Content type {contentType} is not allowed by the pool's policy" + ); + rejected = true; + } } }