Skip to content
This repository was archived by the owner on Dec 21, 2022. It is now read-only.

Commit df22d64

Browse files
committed
Merge branch 'main' into feat/qol
2 parents c086dbb + 6a5e48b commit df22d64

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

.github/workflows/build-test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: build-test
33
on:
44
push:
55
branches:
6-
- dev
6+
- "*"
77
pull_request:
88
branches:
9-
- dev
9+
- "*"
1010

1111
defaults:
1212
run:

src/MaaCopilotServer.GameData/Constants/I18NConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static string GetZoneTypeI18NString(this ZoneTypes zoneTypes, ArkServerLa
110110
ZoneTypes.Weekly => "物资筹备 & 芯片搜索",
111111
ZoneTypes.Activity => "活动关卡",
112112
ZoneTypes.Campaign => "剿灭作战",
113-
ZoneTypes.Memory => "悖論模擬",
113+
ZoneTypes.Memory => "悖论模拟",
114114
_ => throw new ArgumentOutOfRangeException(nameof(zoneTypes), zoneTypes, null)
115115
};
116116

src/MaaCopilotServer.Infrastructure/MaaCopilotServer.Infrastructure.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
2626
<PackageReference Include="FluentEmail.Liquid" Version="3.0.2" />
2727
<PackageReference Include="FluentEmail.MailKit" Version="3.0.2" />
28+
<PackageReference Include="JsonSchema.Net" Version="3.2.0" />
2829
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.6" />
2930
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
3031
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
31-
<PackageReference Include="NJsonSchema" Version="10.7.2" />
3232
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.5" />
3333
</ItemGroup>
3434

src/MaaCopilotServer.Infrastructure/Services/OperationProcessService.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the AGPL-3.0 license.
44

55
using System.Text.Json;
6+
using Json.Schema;
67
using System.Text.Json.Serialization;
78
using MaaCopilotServer.Application.Common.Interfaces;
89
using MaaCopilotServer.Application.Common.Models;
@@ -12,7 +13,6 @@
1213
using MaaCopilotServer.Resources;
1314
using Microsoft.EntityFrameworkCore;
1415
using Microsoft.Extensions.Options;
15-
using NJsonSchema;
1616
using Action = MaaCopilotServer.Application.Common.Operation.Model.Action;
1717

1818
namespace MaaCopilotServer.Infrastructure.Services;
@@ -22,6 +22,7 @@ public class OperationProcessService : IOperationProcessService
2222
private readonly IMaaCopilotDbContext _dbContext;
2323
private readonly ValidationErrorMessage _validationErrorMessage;
2424
private readonly JsonSchema _schema;
25+
private readonly ValidationOptions _validationOptions;
2526

2627
private static readonly JsonSerializerOptions s_failedSerializerOptions = new()
2728
{
@@ -37,7 +38,9 @@ public OperationProcessService(
3738
_validationErrorMessage = validationErrorMessage;
3839

3940
var schemaFile = Path.Combine(applicationOption.Value.AssemblyPath, SystemConstants.MaaCopilotSchemaPath);
40-
_schema = JsonSchema.FromFileAsync(schemaFile).GetAwaiter().GetResult();
41+
_schema = JsonSchema.FromFile(schemaFile);
42+
43+
_validationOptions = new ValidationOptions { ValidateAs = Draft.Draft7, OutputFormat = OutputFormat.Detailed };
4144
}
4245

4346
public async Task<OperationValidationResult> Validate(string? operation)
@@ -53,15 +56,14 @@ public async Task<OperationValidationResult> Validate(string? operation)
5356
};
5457
}
5558

56-
var schemaValidationResult = _schema.Validate(operation);
57-
if (schemaValidationResult.Any())
59+
var schemaValidationResult = _schema.Validate(JsonDocument.Parse(operation).RootElement, _validationOptions);
60+
if (schemaValidationResult.IsValid is false)
5861
{
59-
var message = string.Join(";", schemaValidationResult);
6062
return new OperationValidationResult
6163
{
6264
IsValid = false,
6365
Operation = null,
64-
ErrorMessages = message,
66+
ErrorMessages = schemaValidationResult.Message ?? string.Empty,
6567
ArkLevel = null
6668
};
6769
}

src/MaaCopilotServer.Resources/maa-copilot-schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "http://json-schema.org/draft-06/schema",
2+
"$schema": "http://json-schema.org/draft-07/schema",
33
"title": "Maa Copilot Operation",
44
"properties": {
55
"stage_name": {

0 commit comments

Comments
 (0)