From 2ecd6c3649393671ad7c7c6c21a4ed1e837eceda Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Fri, 2 Aug 2024 16:24:44 -0500 Subject: [PATCH 1/2] fix audio range request --- .../BotSharp.Abstraction/BotSharp.Abstraction.csproj | 2 +- .../Files/Constants/FileConstants.cs | 9 +++++++++ .../Controllers/ConversationController.cs | 5 ++++- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 src/Infrastructure/BotSharp.Abstraction/Files/Constants/FileConstants.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj b/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj index 446b88697..570f5c922 100644 --- a/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj +++ b/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj @@ -1,4 +1,4 @@ - + $(TargetFramework) diff --git a/src/Infrastructure/BotSharp.Abstraction/Files/Constants/FileConstants.cs b/src/Infrastructure/BotSharp.Abstraction/Files/Constants/FileConstants.cs new file mode 100644 index 000000000..683d037c0 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Files/Constants/FileConstants.cs @@ -0,0 +1,9 @@ +namespace BotSharp.Abstraction.Files.Constants; + +public class FileConstants +{ + public static readonly IEnumerable AudioTypes = new List + { + ".mp3", ".wav", ".flac", ".aac", ".ogg", ".wma" + }; +} diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index 22649d72a..1999cfd1f 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Files.Constants; using BotSharp.Abstraction.Files.Enums; using BotSharp.Abstraction.Options; using BotSharp.Abstraction.Routing; @@ -413,7 +414,9 @@ private FileContentResult BuildFileResult(string file) using Stream stream = System.IO.File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read); var bytes = new byte[stream.Length]; stream.Read(bytes, 0, (int)stream.Length); - return File(bytes, "application/octet-stream", Path.GetFileName(file)); + var fileExtensions = Path.GetExtension(file).ToLower(); + var enableRangeProcessing = FileConstants.AudioTypes.Contains(fileExtensions); + return File(bytes, "application/octet-stream", Path.GetFileName(file), enableRangeProcessing: enableRangeProcessing); } private async Task OnChunkReceived(HttpResponse response, ChatResponseModel message) From b84aef83215e5ba5c3b6af72910d73d6467d3a6d Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Fri, 2 Aug 2024 16:26:11 -0500 Subject: [PATCH 2/2] rename --- .../BotSharp.Abstraction/Files/Constants/FileConstants.cs | 2 +- .../BotSharp.OpenAPI/Controllers/ConversationController.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Files/Constants/FileConstants.cs b/src/Infrastructure/BotSharp.Abstraction/Files/Constants/FileConstants.cs index 683d037c0..dab5bc817 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Files/Constants/FileConstants.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Files/Constants/FileConstants.cs @@ -2,7 +2,7 @@ namespace BotSharp.Abstraction.Files.Constants; public class FileConstants { - public static readonly IEnumerable AudioTypes = new List + public static readonly IEnumerable AudioExtensions = new List { ".mp3", ".wav", ".flac", ".aac", ".ogg", ".wma" }; diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index 1999cfd1f..261eb04bd 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -414,8 +414,8 @@ private FileContentResult BuildFileResult(string file) using Stream stream = System.IO.File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read); var bytes = new byte[stream.Length]; stream.Read(bytes, 0, (int)stream.Length); - var fileExtensions = Path.GetExtension(file).ToLower(); - var enableRangeProcessing = FileConstants.AudioTypes.Contains(fileExtensions); + var fileExtension = Path.GetExtension(file).ToLower(); + var enableRangeProcessing = FileConstants.AudioExtensions.Contains(fileExtension); return File(bytes, "application/octet-stream", Path.GetFileName(file), enableRangeProcessing: enableRangeProcessing); }