CLI: Add file browser toggle

This commit is contained in:
genteure 2022-06-08 00:58:08 +08:00
parent 4d0e52c87d
commit ca0d206500
4 changed files with 33 additions and 6 deletions

View File

@ -41,6 +41,7 @@ namespace BililiveRecorder.Cli
new Option<string?>(new []{ "--http-bind", "--bind", "-b" }, () => null, "Bind address for http service"), new Option<string?>(new []{ "--http-bind", "--bind", "-b" }, () => null, "Bind address for http service"),
new Option<string?>(new []{ "--http-basic-user" }, () => null, "Web interface username"), new Option<string?>(new []{ "--http-basic-user" }, () => null, "Web interface username"),
new Option<string?>(new []{ "--http-basic-pass" }, () => null, "Web interface password"), new Option<string?>(new []{ "--http-basic-pass" }, () => null, "Web interface password"),
new Option<bool>(new []{ "--enable-file-browser" }, () => true, "Enable file browser located at '/file'"),
new Option<LogEventLevel>(new []{ "--loglevel", "--log", "-l" }, () => LogEventLevel.Information, "Minimal log level output to console"), new Option<LogEventLevel>(new []{ "--loglevel", "--log", "-l" }, () => LogEventLevel.Information, "Minimal log level output to console"),
new Option<LogEventLevel>(new []{ "--logfilelevel", "--flog" }, () => LogEventLevel.Debug, "Minimal log level output to file"), new Option<LogEventLevel>(new []{ "--logfilelevel", "--flog" }, () => LogEventLevel.Debug, "Minimal log level output to file"),
new Option<string?>(new []{ "--cert-pem-path", "--pem" }, "Path of the certificate pem file"), new Option<string?>(new []{ "--cert-pem-path", "--pem" }, "Path of the certificate pem file"),
@ -58,6 +59,7 @@ namespace BililiveRecorder.Cli
new Option<string?>(new []{ "--http-bind", "--bind", "-b" }, () => null, "Bind address for http service"), new Option<string?>(new []{ "--http-bind", "--bind", "-b" }, () => null, "Bind address for http service"),
new Option<string?>(new []{ "--http-basic-user" }, () => null, "Web interface username"), new Option<string?>(new []{ "--http-basic-user" }, () => null, "Web interface username"),
new Option<string?>(new []{ "--http-basic-pass" }, () => null, "Web interface password"), new Option<string?>(new []{ "--http-basic-pass" }, () => null, "Web interface password"),
new Option<bool>(new []{ "--enable-file-browser" }, () => true, "Enable file browser located at '/file'"),
new Option<LogEventLevel>(new []{ "--loglevel", "--log", "-l" }, () => LogEventLevel.Information, "Minimal log level output to console"), new Option<LogEventLevel>(new []{ "--loglevel", "--log", "-l" }, () => LogEventLevel.Information, "Minimal log level output to console"),
new Option<LogEventLevel>(new []{ "--logfilelevel", "--flog" }, () => LogEventLevel.Debug, "Minimal log level output to file"), new Option<LogEventLevel>(new []{ "--logfilelevel", "--flog" }, () => LogEventLevel.Debug, "Minimal log level output to file"),
new Option<string?>(new []{ "--cert-pem-path", "--pem" }, "Path of the certificate pem file"), new Option<string?>(new []{ "--cert-pem-path", "--pem" }, "Path of the certificate pem file"),
@ -173,6 +175,8 @@ namespace BililiveRecorder.Cli
{ {
services.AddSingleton(recorderAccessProxy); services.AddSingleton(recorderAccessProxy);
services.AddSingleton(new BililiveRecorderFileExplorerSettings(sharedArguments.EnableFileBrowser));
if (sharedArguments.HttpBasicUser is not null || sharedArguments.HttpBasicPass is not null) if (sharedArguments.HttpBasicUser is not null || sharedArguments.HttpBasicPass is not null)
{ {
services.AddSingleton(new BasicAuthCredential(sharedArguments.HttpBasicUser ?? string.Empty, sharedArguments.HttpBasicPass ?? string.Empty)); 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 string? HttpBasicPass { get; set; } = null;
public bool EnableFileBrowser { get; set; }
public string? CertPemPath { get; set; } = null; public string? CertPemPath { get; set; } = null;
public string? CertKeyPath { get; set; } = null; public string? CertKeyPath { get; set; } = null;

View File

@ -0,0 +1,12 @@
namespace BililiveRecorder.Web
{
public class BililiveRecorderFileExplorerSettings
{
public BililiveRecorderFileExplorerSettings(bool enable)
{
this.Enable = enable;
}
public bool Enable { get; set; }
}
}

View File

@ -203,13 +203,16 @@ namespace BililiveRecorder.Web
try try
{ {
var sharedRecordingFiles = new SharedOptions if (app.ApplicationServices.GetService<BililiveRecorderFileExplorerSettings>()?.Enable ?? false)
{ {
FileProvider = new PhysicalFileProvider(app.ApplicationServices.GetRequiredService<IRecorder>().Config.Global.WorkDirectory), var sharedRecordingFiles = new SharedOptions
RequestPath = "/file", {
RedirectToAppendTrailingSlash = true, FileProvider = new PhysicalFileProvider(app.ApplicationServices.GetRequiredService<IRecorder>().Config.Global.WorkDirectory),
}; RequestPath = "/file",
app.UseStaticFiles(new StaticFileOptions(sharedRecordingFiles)).UseDirectoryBrowser(new DirectoryBrowserOptions(sharedRecordingFiles)); RedirectToAppendTrailingSlash = true,
};
app.UseStaticFiles(new StaticFileOptions(sharedRecordingFiles)).UseDirectoryBrowser(new DirectoryBrowserOptions(sharedRecordingFiles));
}
} }
catch (Exception) { } catch (Exception) { }

View File

@ -98,6 +98,12 @@
<p class="path">/ui</p> <p class="path">/ui</p>
</div> </div>
</a> </a>
<a href="/file">
<div class="card">
<p class="name">录播文件浏览器</p>
<p class="path">/file</p>
</div>
</a>
</div> </div>
<div class="group"> <div class="group">
<h2>REST API</h2> <h2>REST API</h2>