Skip to content

Commit ca2442e

Browse files
committed
feat: AquaMai 选择安装在线版本
1 parent 9e485bd commit ca2442e

File tree

11 files changed

+504
-29
lines changed

11 files changed

+504
-29
lines changed

AquaMai

MaiChartManager/Controllers/ModController.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics;
22
using System.IO.Compression;
3+
using System.Security.Cryptography;
34
using System.Text.Json;
45
using System.Text.Json.Serialization;
56
using AquaMai.Config.HeadlessLoader;
@@ -282,7 +283,7 @@ public void InstallAquaMai()
282283
var src = Path.Combine(StaticSettings.exeDir, "AquaMai.dll");
283284
var dest = Path.Combine(StaticSettings.GamePath, @"Mods\AquaMai.dll");
284285
Directory.CreateDirectory(Path.GetDirectoryName(dest));
285-
System.IO.File.Copy(src, dest, true);
286+
FileSystem.CopyFile(src, dest, true);
286287
}
287288

288289
[HttpPost]
@@ -294,4 +295,47 @@ public void OpenJudgeAccuracyInfoPdf()
294295
UseShellExecute = true
295296
});
296297
}
298+
299+
private const string CI_KEY =
300+
"MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQBmXJFYcg9YMi5i7tcPxc29Lxb/8OwGBUA5zi0cN4Apvp/J+zBaeY7EB9clDcRh8sjXRgSc7/JXYrUn8LDPHoCuuMB2W6HAxV+NtQamITaUNJD89LM0NpubbTUeKYjUThXpr/otDWq8kk5hvwkk62ByqG/2EXnH6WhlrI81I9H4l5adi4=";
301+
302+
private const string RELEASE_KEY =
303+
"MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQBysJuWwvK1gK0Da9fnQgaiJpXH495QGEdGW/l3fj9g5X9v7TZCBPetUM7zDbMyMxLL+G4R1KQYvxcfKyvJz0h/woBkQ0nznNTCrkdBiB0xsNQrCBf8DDAJVw9w8X01rQeSxcnOZi2KBzixeMZZEqWnGtU/f3kDThWmRPaZ8Ptz8KynUU=";
304+
305+
[NonAction]
306+
private static bool VerifyBinary(byte[] data, string sign, string key)
307+
{
308+
byte[] signature = Convert.FromBase64String(sign);
309+
byte[] publicKey = Convert.FromBase64String(key);
310+
311+
using var ecdsa = ECDsa.Create();
312+
ecdsa.ImportSubjectPublicKeyInfo(publicKey, out _);
313+
return ecdsa.VerifyData(data, signature, HashAlgorithmName.SHA256, DSASignatureFormat.Rfc3279DerSequence);
314+
}
315+
316+
public record InstallAquaMaiOnlineDto(string Url, string Type, string Sign);
317+
318+
[HttpPost]
319+
public async Task InstallAquaMaiOnline(InstallAquaMaiOnlineDto req)
320+
{
321+
var key = req.Type switch
322+
{
323+
"ci" => CI_KEY,
324+
"release" => RELEASE_KEY,
325+
_ => throw new ArgumentException("Invalid type", nameof(req.Type)),
326+
};
327+
// Download from url
328+
using var client = new HttpClient();
329+
var data = await client.GetByteArrayAsync(req.Url);
330+
331+
if (!VerifyBinary(data, req.Sign, key))
332+
{
333+
throw new InvalidOperationException("Invalid signature");
334+
}
335+
336+
// Save to Mods folder
337+
var dest = Path.Combine(StaticSettings.GamePath, @"Mods\AquaMai.dll");
338+
Directory.CreateDirectory(Path.GetDirectoryName(dest));
339+
await System.IO.File.WriteAllBytesAsync(dest, data);
340+
}
297341
}

MaiChartManager/Front/genClient.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ generateApi({
1212
defaultResponseType: "void",
1313
enumNamesAsValues: true,
1414
})
15+
16+
generateApi({
17+
name: "aquaMaiVersionConfigApiGen.ts",
18+
output: path.resolve("src/client"),
19+
url: "https://aquamai-version-config.init.ink/openapi.json",
20+
templates: path.resolve("./api-templates"),
21+
httpClientType: "fetch", // or "fetch"
22+
defaultResponseType: "void",
23+
enumNamesAsValues: true,
24+
})

MaiChartManager/Front/src/client/api.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Api } from "@/client/apiGen";
2+
import { Api as AquaMaiVersionConfigApi } from "@/client/aquaMaiVersionConfigApiGen";
23

34
declare global {
45
const backendUrl: string | undefined;
@@ -14,6 +15,15 @@ export default (new Api({
1415
},
1516
})).maiChartManagerServlet
1617

18+
export const aquaMaiVersionConfig = new AquaMaiVersionConfigApi({
19+
baseUrl: 'https://aquamai-version-config.init.ink',
20+
baseApiParams: {
21+
headers: {
22+
accept: 'application/json',
23+
},
24+
},
25+
}).api
26+
1727
export const getUrl = (suffix: string) => {
1828
// @ts-ignore
1929
return `${globalThis.backendUrl ?? ''}/MaiChartManagerServlet/${suffix}`;

MaiChartManager/Front/src/client/apiGen.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ export interface ImportChartResult {
207207
fatal?: boolean;
208208
}
209209

210+
export interface InstallAquaMaiOnlineDto {
211+
url?: string | null;
212+
type?: string | null;
213+
sign?: string | null;
214+
}
215+
210216
export enum LicenseStatus {
211217
Pending = "Pending",
212218
Active = "Active",
@@ -1358,6 +1364,22 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
13581364
...params,
13591365
}),
13601366

1367+
/**
1368+
* No description
1369+
*
1370+
* @tags Mod
1371+
* @name InstallAquaMaiOnline
1372+
* @request POST:/MaiChartManagerServlet/InstallAquaMaiOnlineApi
1373+
*/
1374+
InstallAquaMaiOnline: (data: InstallAquaMaiOnlineDto, params: RequestParams = {}) =>
1375+
this.request<void, any>({
1376+
path: `/MaiChartManagerServlet/InstallAquaMaiOnlineApi`,
1377+
method: "POST",
1378+
body: data,
1379+
type: ContentType.Json,
1380+
...params,
1381+
}),
1382+
13611383
/**
13621384
* No description
13631385
*

0 commit comments

Comments
 (0)