From 58722d1443f5e014c006bcb98490c10a98106791 Mon Sep 17 00:00:00 2001 From: genteure Date: Tue, 7 Jun 2022 13:44:50 +0800 Subject: [PATCH] Web: Better home page --- BililiveRecorder.Web/IndexController.cs | 38 ++++ BililiveRecorder.Web/Startup.cs | 5 +- BililiveRecorder.Web/embeded/index.html | 280 ++++++++++-------------- 3 files changed, 160 insertions(+), 163 deletions(-) create mode 100644 BililiveRecorder.Web/IndexController.cs diff --git a/BililiveRecorder.Web/IndexController.cs b/BililiveRecorder.Web/IndexController.cs new file mode 100644 index 0000000..5d95cbe --- /dev/null +++ b/BililiveRecorder.Web/IndexController.cs @@ -0,0 +1,38 @@ +using System; +using System.IO; +using System.Text; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.FileProviders; + +namespace BililiveRecorder.Web +{ + [Controller, Route("/", Name = "Home Page")] + [ApiExplorerSettings(IgnoreApi = true)] + public class IndexController : Controller + { + private static string? result; + private readonly ManifestEmbeddedFileProvider fileProvider; + + public IndexController(ManifestEmbeddedFileProvider fileProvider) + { + this.fileProvider = fileProvider ?? throw new ArgumentNullException(nameof(fileProvider)); + } + + [HttpGet] + public ActionResult Get() + { + if (result is null) + { + using var file = this.fileProvider.GetFileInfo("/index.html").CreateReadStream(); + using var reader = new StreamReader(file, Encoding.UTF8); + var html = reader.ReadToEnd(); + result = html + .Replace("__VERSION__", GitVersionInformation.FullSemVer) + .Replace("__FULL_VERSION__", GitVersionInformation.InformationalVersion) + ; + } + + return this.Content(result, "text/html", Encoding.UTF8); + } + } +} diff --git a/BililiveRecorder.Web/Startup.cs b/BililiveRecorder.Web/Startup.cs index fbf4ac1..cb0cfa6 100644 --- a/BililiveRecorder.Web/Startup.cs +++ b/BililiveRecorder.Web/Startup.cs @@ -68,6 +68,8 @@ namespace BililiveRecorder.Web .AddCors(o => o.AddDefaultPolicy(p => p.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader())) ; + services.AddSingleton(new ManifestEmbeddedFileProvider(typeof(Startup).Assembly)); + // Graphql API GraphQL.MicrosoftDI.GraphQLBuilderExtensions.AddGraphQL(services) .AddServer(true) @@ -179,10 +181,11 @@ namespace BililiveRecorder.Web ctp.Mappings[".mjs"] = "text/javascript; charset=utf-8"; ctp.Mappings[".json"] = "application/json; charset=utf-8"; + var manifestEmbeddedFileProvider = app.ApplicationServices.GetRequiredService(); var sharedStaticFiles = new SharedOptions() { // 在运行的 exe 旁边新建一个 wwwroot 文件夹,会优先使用里面的内容,然后 fallback 到打包的资源文件 - FileProvider = new CompositeFileProvider(env.WebRootFileProvider, new ManifestEmbeddedFileProvider(typeof(Startup).Assembly)), + FileProvider = new CompositeFileProvider(env.WebRootFileProvider, manifestEmbeddedFileProvider), RedirectToAppendTrailingSlash = true, }; diff --git a/BililiveRecorder.Web/embeded/index.html b/BililiveRecorder.Web/embeded/index.html index c5ace2c..2f4020b 100644 --- a/BililiveRecorder.Web/embeded/index.html +++ b/BililiveRecorder.Web/embeded/index.html @@ -1,181 +1,137 @@ - + - B站录播姬 + B站录播姬 __VERSION__ -

B站录播姬

-

- 录播姬管理界面: - WebUI +

B站录播姬

+

+ __VERSION__

-

- REST API 界面: - Swagger -

-

- GraphiQL API 界面: - GraphiQL - Playground - Altair - Voyager -

-

录播姬 API 里的 objectId 在重启后会重新生成,是不保存到配置文件里的

+

https://rec.danmuji.org

-
-

GraphQL API 用法示例

-

- graphql 的语法请查看官方文档 - https://graphql.org/learn/ - 或中文翻译镜像 - https://graphql.cn/learn/ -

x -
-

列出所有直播间和基本信息

- - - + -
-

列出所有直播间的所有信息(截至编写此页面时,具体最新属性见API界面的文档)

-
-
-

添加一个房间

-
-
-

添加一个房间,用变量传参版

-
-
-

启用自动录制

-
-
开始录制、结束录制、手动切分,都是 mutation,在 graphql 文档页面里可以看到