From 80b8b6bb51ee378e8efa844ade069bec2ebd98ee Mon Sep 17 00:00:00 2001 From: genteure Date: Wed, 8 Feb 2023 11:59:49 +0800 Subject: [PATCH] fix(web): allow serving all file types fix #459 --- BililiveRecorder.Web/Startup.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/BililiveRecorder.Web/Startup.cs b/BililiveRecorder.Web/Startup.cs index 85ab159..c40d8e0 100644 --- a/BililiveRecorder.Web/Startup.cs +++ b/BililiveRecorder.Web/Startup.cs @@ -196,6 +196,14 @@ namespace BililiveRecorder.Web ctp.Mappings[".mjs"] = "text/javascript; charset=utf-8"; ctp.Mappings[".json"] = "application/json; charset=utf-8"; + ctp.Mappings[".mkv"] = "video/x-matroska"; + ctp.Mappings[".mk3d"] = "video/x-matroska"; + ctp.Mappings[".mka"] = "audio/x-matroska"; + ctp.Mappings[".mks"] = "video/x-matroska"; + ctp.Mappings[".srt"] = "text/plain"; + ctp.Mappings[".ass"] = "text/plain"; + ctp.Mappings[".ssa"] = "text/plain"; + var compositeFileProvider = app.ApplicationServices.GetRequiredService(); var sharedStaticFiles = new SharedOptions() { @@ -224,10 +232,16 @@ namespace BililiveRecorder.Web RequestPath = "/file", RedirectToAppendTrailingSlash = true, }; - app.UseStaticFiles(new StaticFileOptions(sharedRecordingFiles)).UseDirectoryBrowser(new DirectoryBrowserOptions(sharedRecordingFiles) - { - Formatter = new BililiveRecorderDirectoryFormatter() - }); + app + .UseStaticFiles(new StaticFileOptions(sharedRecordingFiles) + { + ContentTypeProvider = ctp, + ServeUnknownFileTypes = true, + }) + .UseDirectoryBrowser(new DirectoryBrowserOptions(sharedRecordingFiles) + { + Formatter = new BililiveRecorderDirectoryFormatter(), + }); } } catch (Exception) { }