From ca0d2065005345cd063fff84bc396c4b12dba18a Mon Sep 17 00:00:00 2001 From: genteure Date: Wed, 8 Jun 2022 00:58:08 +0800 Subject: [PATCH] CLI: Add file browser toggle --- BililiveRecorder.Cli/Program.cs | 6 ++++++ .../BililiveRecorderFileExplorerSettings.cs | 12 ++++++++++++ BililiveRecorder.Web/Startup.cs | 15 +++++++++------ BililiveRecorder.Web/embeded/index.html | 6 ++++++ 4 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 BililiveRecorder.Web/BililiveRecorderFileExplorerSettings.cs diff --git a/BililiveRecorder.Cli/Program.cs b/BililiveRecorder.Cli/Program.cs index 7d9d677..25da8e6 100644 --- a/BililiveRecorder.Cli/Program.cs +++ b/BililiveRecorder.Cli/Program.cs @@ -41,6 +41,7 @@ namespace BililiveRecorder.Cli new Option(new []{ "--http-bind", "--bind", "-b" }, () => null, "Bind address for http service"), new Option(new []{ "--http-basic-user" }, () => null, "Web interface username"), new Option(new []{ "--http-basic-pass" }, () => null, "Web interface password"), + new Option(new []{ "--enable-file-browser" }, () => true, "Enable file browser located at '/file'"), new Option(new []{ "--loglevel", "--log", "-l" }, () => LogEventLevel.Information, "Minimal log level output to console"), new Option(new []{ "--logfilelevel", "--flog" }, () => LogEventLevel.Debug, "Minimal log level output to file"), new Option(new []{ "--cert-pem-path", "--pem" }, "Path of the certificate pem file"), @@ -58,6 +59,7 @@ namespace BililiveRecorder.Cli new Option(new []{ "--http-bind", "--bind", "-b" }, () => null, "Bind address for http service"), new Option(new []{ "--http-basic-user" }, () => null, "Web interface username"), new Option(new []{ "--http-basic-pass" }, () => null, "Web interface password"), + new Option(new []{ "--enable-file-browser" }, () => true, "Enable file browser located at '/file'"), new Option(new []{ "--loglevel", "--log", "-l" }, () => LogEventLevel.Information, "Minimal log level output to console"), new Option(new []{ "--logfilelevel", "--flog" }, () => LogEventLevel.Debug, "Minimal log level output to file"), new Option(new []{ "--cert-pem-path", "--pem" }, "Path of the certificate pem file"), @@ -173,6 +175,8 @@ namespace BililiveRecorder.Cli { services.AddSingleton(recorderAccessProxy); + services.AddSingleton(new BililiveRecorderFileExplorerSettings(sharedArguments.EnableFileBrowser)); + if (sharedArguments.HttpBasicUser is not null || sharedArguments.HttpBasicPass is not null) { services.AddSingleton(new BasicAuthCredential(sharedArguments.HttpBasicUser ?? string.Empty, sharedArguments.HttpBasicPass ?? string.Empty)); @@ -430,6 +434,8 @@ namespace BililiveRecorder.Cli public string? HttpBasicPass { get; set; } = null; + public bool EnableFileBrowser { get; set; } + public string? CertPemPath { get; set; } = null; public string? CertKeyPath { get; set; } = null; diff --git a/BililiveRecorder.Web/BililiveRecorderFileExplorerSettings.cs b/BililiveRecorder.Web/BililiveRecorderFileExplorerSettings.cs new file mode 100644 index 0000000..ebf4d12 --- /dev/null +++ b/BililiveRecorder.Web/BililiveRecorderFileExplorerSettings.cs @@ -0,0 +1,12 @@ +namespace BililiveRecorder.Web +{ + public class BililiveRecorderFileExplorerSettings + { + public BililiveRecorderFileExplorerSettings(bool enable) + { + this.Enable = enable; + } + + public bool Enable { get; set; } + } +} diff --git a/BililiveRecorder.Web/Startup.cs b/BililiveRecorder.Web/Startup.cs index 81d3c23..446563c 100644 --- a/BililiveRecorder.Web/Startup.cs +++ b/BililiveRecorder.Web/Startup.cs @@ -203,13 +203,16 @@ namespace BililiveRecorder.Web try { - var sharedRecordingFiles = new SharedOptions + if (app.ApplicationServices.GetService()?.Enable ?? false) { - FileProvider = new PhysicalFileProvider(app.ApplicationServices.GetRequiredService().Config.Global.WorkDirectory), - RequestPath = "/file", - RedirectToAppendTrailingSlash = true, - }; - app.UseStaticFiles(new StaticFileOptions(sharedRecordingFiles)).UseDirectoryBrowser(new DirectoryBrowserOptions(sharedRecordingFiles)); + var sharedRecordingFiles = new SharedOptions + { + FileProvider = new PhysicalFileProvider(app.ApplicationServices.GetRequiredService().Config.Global.WorkDirectory), + RequestPath = "/file", + RedirectToAppendTrailingSlash = true, + }; + app.UseStaticFiles(new StaticFileOptions(sharedRecordingFiles)).UseDirectoryBrowser(new DirectoryBrowserOptions(sharedRecordingFiles)); + } } catch (Exception) { } diff --git a/BililiveRecorder.Web/embeded/index.html b/BililiveRecorder.Web/embeded/index.html index 7f730ca..b2a64ad 100644 --- a/BililiveRecorder.Web/embeded/index.html +++ b/BililiveRecorder.Web/embeded/index.html @@ -98,6 +98,12 @@

/ui

+ +
+

录播文件浏览器

+

/file

+
+

REST API