Web: Add "version" graphql query

This commit is contained in:
genteure 2022-04-02 21:08:04 +08:00
parent db7f2872f8
commit 958683a1d1
6 changed files with 218 additions and 1 deletions

View File

@ -30,6 +30,15 @@ namespace BililiveRecorder.Web.Schemas
var roomid = context.GetArgument<int>("roomId");
var enabled = context.GetArgument<bool>("autoRecord");
if (roomid <= 0)
{
context.Errors.Add(new ExecutionError("Roomid out of range")
{
Code = "BREC_ROOMID_OUT_OF_RANGE"
});
return null;
}
var room = this.recorder.Rooms.FirstOrDefault(x => x.RoomConfig.RoomId == roomid || x.ShortId == roomid);
if (room is not null)

View File

@ -21,6 +21,8 @@ namespace BililiveRecorder.Web.Schemas
private void SetupFields()
{
this.Field<RecorderVersionType>("version", resolve: context => RecorderVersion.Instance);
this.Field<GlobalConfigType>("config", resolve: context => this.recorder.Config.Global);
this.Field<DefaultConfigType>("defaultConfig", resolve: context => DefaultConfig.Instance);

View File

@ -0,0 +1,41 @@
namespace BililiveRecorder.Web.Schemas.Types
{
public class RecorderVersion
{
internal static readonly RecorderVersion Instance = new();
public string Major { get; } = GitVersionInformation.Major;
public string Minor { get; } = GitVersionInformation.Minor;
public string Patch { get; } = GitVersionInformation.Patch;
public string PreReleaseTag { get; } = GitVersionInformation.PreReleaseTag;
public string PreReleaseTagWithDash { get; } = GitVersionInformation.PreReleaseTagWithDash;
public string PreReleaseLabel { get; } = GitVersionInformation.PreReleaseLabel;
public string PreReleaseLabelWithDash { get; } = GitVersionInformation.PreReleaseLabelWithDash;
public string PreReleaseNumber { get; } = GitVersionInformation.PreReleaseNumber;
public string WeightedPreReleaseNumber { get; } = GitVersionInformation.WeightedPreReleaseNumber;
public string BuildMetaData { get; } = GitVersionInformation.BuildMetaData;
public string BuildMetaDataPadded { get; } = GitVersionInformation.BuildMetaDataPadded;
public string FullBuildMetaData { get; } = GitVersionInformation.FullBuildMetaData;
public string MajorMinorPatch { get; } = GitVersionInformation.MajorMinorPatch;
public string SemVer { get; } = GitVersionInformation.SemVer;
public string LegacySemVer { get; } = GitVersionInformation.LegacySemVer;
public string LegacySemVerPadded { get; } = GitVersionInformation.LegacySemVerPadded;
public string AssemblySemVer { get; } = GitVersionInformation.AssemblySemVer;
public string AssemblySemFileVer { get; } = GitVersionInformation.AssemblySemFileVer;
public string FullSemVer { get; } = GitVersionInformation.FullSemVer;
public string InformationalVersion { get; } = GitVersionInformation.InformationalVersion;
public string BranchName { get; } = GitVersionInformation.BranchName;
public string EscapedBranchName { get; } = GitVersionInformation.EscapedBranchName;
public string Sha { get; } = GitVersionInformation.Sha;
public string ShortSha { get; } = GitVersionInformation.ShortSha;
public string NuGetVersionV2 { get; } = GitVersionInformation.NuGetVersionV2;
public string NuGetVersion { get; } = GitVersionInformation.NuGetVersion;
public string NuGetPreReleaseTagV2 { get; } = GitVersionInformation.NuGetPreReleaseTagV2;
public string NuGetPreReleaseTag { get; } = GitVersionInformation.NuGetPreReleaseTag;
public string VersionSourceSha { get; } = GitVersionInformation.VersionSourceSha;
public string CommitsSinceVersionSource { get; } = GitVersionInformation.CommitsSinceVersionSource;
public string CommitsSinceVersionSourcePadded { get; } = GitVersionInformation.CommitsSinceVersionSourcePadded;
public string UncommittedChanges { get; } = GitVersionInformation.UncommittedChanges;
public string CommitDate { get; } = GitVersionInformation.CommitDate;
}
}

View File

@ -0,0 +1,44 @@
using GraphQL.Types;
namespace BililiveRecorder.Web.Schemas.Types
{
public class RecorderVersionType : ObjectGraphType<RecorderVersion>
{
public RecorderVersionType()
{
this.Field(x => x.Major);
this.Field(x => x.Minor);
this.Field(x => x.Patch);
this.Field(x => x.PreReleaseTag);
this.Field(x => x.PreReleaseTagWithDash);
this.Field(x => x.PreReleaseLabel);
this.Field(x => x.PreReleaseLabelWithDash);
this.Field(x => x.PreReleaseNumber);
this.Field(x => x.WeightedPreReleaseNumber);
this.Field(x => x.BuildMetaData);
this.Field(x => x.BuildMetaDataPadded);
this.Field(x => x.FullBuildMetaData);
this.Field(x => x.MajorMinorPatch);
this.Field(x => x.SemVer);
this.Field(x => x.LegacySemVer);
this.Field(x => x.LegacySemVerPadded);
this.Field(x => x.AssemblySemVer);
this.Field(x => x.AssemblySemFileVer);
this.Field(x => x.FullSemVer);
this.Field(x => x.InformationalVersion);
this.Field(x => x.BranchName);
this.Field(x => x.EscapedBranchName);
this.Field(x => x.Sha);
this.Field(x => x.ShortSha);
this.Field(x => x.NuGetVersionV2);
this.Field(x => x.NuGetVersion);
this.Field(x => x.NuGetPreReleaseTagV2);
this.Field(x => x.NuGetPreReleaseTag);
this.Field(x => x.VersionSourceSha);
this.Field(x => x.CommitsSinceVersionSource);
this.Field(x => x.CommitsSinceVersionSourcePadded);
this.Field(x => x.UncommittedChanges);
this.Field(x => x.CommitDate);
}
}
}

View File

@ -0,0 +1,120 @@
namespace BililiveRecorder.Web
{
internal static class ConstStrings
{
internal const string HOME_PAGE_HTML = @"<meta charset=utf-8><meta content=""width=device-width,initial-scale=1""name=viewport><title>录播姬</title><style>a{margin:5px}textarea{width:300px;height:200px}</style><h1>录播姬,以后再写管理界面</h1><p><span style=color:red;font-weight:700>API 界面</span> <a href=/ui/graphiql>GraphiQL</a> <a href=/ui/playground>Playground</a> <a href=/ui/altair>Altair</a> <a href=/ui/voyager>Voyager</a><p>说明:录播姬 API 里的 objectId 在重启后会重新生成,是不保存到配置文件里的<div><h2>API 用法示例</h2><p>graphql 的<b>语法</b>请查看官方文档 <a href=https://graphql.org/learn/ >https://graphql.org/learn/</a> ,或中文翻译镜像 <a href=https://graphql.cn/learn/ >https://graphql.cn/learn/</a><div><h3>列出所有直播间和基本信息</h3><textarea>
query {
rooms {
objectId
roomConfig {
roomId
autoRecord
}
shortId
name
streaming
title
areaNameParent
areaNameChild
}
}</textarea></div><div><h3>API界面的文档</h3><textarea>
query {
rooms {
objectId
shortId
recording
roomConfig {
roomId
autoRecord
optionalRecordingQuality {
value
hasValue
}
optionalRecordMode {
value
hasValue
}
optionalRecordDanmakuSuperChat {
value
hasValue
}
optionalRecordDanmakuRaw {
value
hasValue
}
optionalRecordDanmakuGuard {
value
hasValue
}
optionalRecordDanmakuGift {
value
hasValue
}
optionalRecordDanmaku {
value
hasValue
}
optionalCuttingNumber {
value
hasValue
}
optionalCuttingMode {
value
hasValue
}
}
stats {
durationRatio
fileMaxTimestamp
networkMbps
sessionDuration
totalInputBytes
sessionMaxTimestamp
totalOutputBytes
}
streaming
title
name
danmakuConnected
autoRecordForThisSession
areaNameParent
areaNameChild
}
}
</textarea></div><div><h3></h3><textarea>
mutation {
addRoom(roomId: 3, autoRecord: false) {
objectId
shortId
roomConfig {
roomId
autoRecord
}
}
}
</textarea></div><div><h3></h3><textarea>
mutation AddRoom($roomid: Int, $autoRecord: Boolean) {
addRoom(roomId: $roomid, autoRecord: $autoRecord) {
objectId
shortId
roomConfig {
roomId
autoRecord
}
}
}
</textarea> <textarea>{'roomid': 4, 'autoRecord': false}</textarea></div><div><h3></h3><textarea>
mutation {
setRoomConfig(roomId: 3, config: { autoRecord: true }) {
objectId
shortId
recording
roomConfig {
roomId
autoRecord
}
}
}
</textarea></div><div> mutation graphql </div></div>";
}
}

View File

@ -70,7 +70,8 @@ namespace BililiveRecorder.Web
{
if (context.Request.Path == "/")
{
await context.Response.WriteAsync(@"<h1>to be done</h1><style>a{margin:5px}</style><a href=""/ui/playground"">Playground</a><a href=""/ui/graphiql"">GraphiQL</a><a href=""/ui/altair"">Altair</a><a href=""/ui/voyager"">Voyager</a>").ConfigureAwait(false);
context.Response.ContentType = "text/html";
await context.Response.WriteAsync(ConstStrings.HOME_PAGE_HTML, encoding: System.Text.Encoding.UTF8).ConfigureAwait(false);
}
else
{