2021-05-30 19:16:20 +08:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using BililiveRecorder.Core;
|
2022-04-03 20:43:38 +08:00
|
|
|
using BililiveRecorder.Core.Config.V3;
|
2022-04-03 14:47:54 +08:00
|
|
|
using BililiveRecorder.Web.Models;
|
|
|
|
using BililiveRecorder.Web.Models.Graphql;
|
2021-05-30 19:16:20 +08:00
|
|
|
using GraphQL;
|
|
|
|
using GraphQL.Types;
|
|
|
|
|
2022-04-03 14:47:54 +08:00
|
|
|
namespace BililiveRecorder.Web.Graphql
|
2021-05-30 19:16:20 +08:00
|
|
|
{
|
|
|
|
internal class RecorderQuery : ObjectGraphType
|
|
|
|
{
|
|
|
|
private readonly IRecorder recorder;
|
|
|
|
|
|
|
|
public RecorderQuery(IRecorder recorder)
|
|
|
|
{
|
|
|
|
this.recorder = recorder ?? throw new ArgumentNullException(nameof(recorder));
|
|
|
|
|
|
|
|
this.SetupFields();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetupFields()
|
|
|
|
{
|
2022-04-02 21:08:04 +08:00
|
|
|
this.Field<RecorderVersionType>("version", resolve: context => RecorderVersion.Instance);
|
|
|
|
|
2021-05-30 19:16:20 +08:00
|
|
|
this.Field<GlobalConfigType>("config", resolve: context => this.recorder.Config.Global);
|
|
|
|
|
|
|
|
this.Field<DefaultConfigType>("defaultConfig", resolve: context => DefaultConfig.Instance);
|
|
|
|
|
|
|
|
this.Field<ListGraphType<RoomType>>("rooms", resolve: context => this.recorder.Rooms);
|
|
|
|
|
|
|
|
this.Field<RoomType>("room",
|
|
|
|
arguments: new QueryArguments(
|
|
|
|
new QueryArgument<IdGraphType> { Name = "objectId" },
|
|
|
|
new QueryArgument<IntGraphType> { Name = "roomId" }
|
|
|
|
),
|
|
|
|
resolve: context =>
|
|
|
|
{
|
|
|
|
var objectId = context.GetArgument<Guid>("objectId");
|
|
|
|
var roomid = context.GetArgument<int>("roomId");
|
|
|
|
|
|
|
|
var room = objectId != default
|
|
|
|
? this.recorder.Rooms.FirstOrDefault(x => x.ObjectId == objectId)
|
|
|
|
: this.recorder.Rooms.FirstOrDefault(x => x.RoomConfig.RoomId == roomid || x.ShortId == roomid);
|
|
|
|
|
|
|
|
return room;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|