This repository has been archived by the owner on Dec 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from MaaAssistantArknights/dev
Release 0.1.4-alpha
- Loading branch information
Showing
72 changed files
with
994 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -470,7 +470,6 @@ FodyWeavers.xsd | |
*.usertasks | ||
|
||
#Mono Project Files | ||
*.resources | ||
test-results/ | ||
|
||
### Windows template | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
if [ -z "$1" ]; then | ||
echo ">>>>> ERROR: Version could not be empty!" | ||
exit | ||
exit 1 | ||
fi | ||
|
||
docker buildx build --load --platform linux/amd64 -t maa-copilot-server:"$1"-amd64 . | ||
docker buildx build --load --platform linux/arm64 -t maa-copilot-server:"$1"-arm64 . | ||
docker buildx build --load --build-arg APP_VERSION="$1" --platform linux/amd64 -t maa-copilot-server:"$1"-amd64 . | ||
docker buildx build --load --build-arg APP_VERSION="$1" --platform linux/arm64 -t maa-copilot-server:"$1"-arm64 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/MaaCopilotServer.Api/Helper/LoggerConfigurationHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// This file is a part of MaaCopilotServer project. | ||
// MaaCopilotServer belongs to the MAA organization. | ||
// Licensed under the AGPL-3.0 license. | ||
|
||
using Destructurama; | ||
using Elastic.Apm.SerilogEnricher; | ||
using Elastic.CommonSchema.Serilog; | ||
using Serilog; | ||
using Serilog.Sinks.Elasticsearch; | ||
|
||
namespace MaaCopilotServer.Api.Helper; | ||
|
||
public static class LoggerConfigurationHelper | ||
{ | ||
public static LoggerConfiguration GetLoggerConfiguration(this IConfiguration configuration) | ||
{ | ||
var loggerConfiguration = new LoggerConfiguration() | ||
.ReadFrom.Configuration(configuration) | ||
.Destructure.UsingAttributes(); | ||
|
||
if (configuration.GetValue<bool>("Switches:ElasticSearch") is false) | ||
{ | ||
return loggerConfiguration; | ||
} | ||
|
||
var elasticUris = configuration.GetValue<string>("ElasticLogSink:Uris") | ||
.Split(";").Select(x => new Uri(x)).ToArray(); | ||
var elasticPeriod = configuration.GetValue<int>("ElasticLogSink:Period"); | ||
var elasticAuthMethod = configuration.GetValue<string>("ElasticLogSink:Authentication:Method"); | ||
var elasticId = configuration.GetValue<string>("ElasticLogSink:Authentication:Secret:Id"); | ||
var elasticKey = configuration.GetValue<string>("ElasticLogSink:Authentication:Secret:Key"); | ||
var elasticApplicationName = configuration.GetValue<string>("ElasticLogSink:ApplicationName"); | ||
loggerConfiguration.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(elasticUris) | ||
{ | ||
Period = TimeSpan.FromSeconds(elasticPeriod), | ||
AutoRegisterTemplate = true, | ||
IndexFormat = $"{elasticApplicationName}-{DateTimeOffset.UtcNow.AddHours(8):yyyy.MM}", | ||
CustomFormatter = new EcsTextFormatter(), | ||
TypeName = null, | ||
ModifyConnectionSettings = c => | ||
{ | ||
switch (elasticAuthMethod) | ||
{ | ||
case "Basic": | ||
c.BasicAuthentication(elasticId, elasticKey); | ||
break; | ||
case "ApiKey": | ||
c.ApiKeyAuthentication(elasticId, elasticKey); | ||
break; | ||
} | ||
return c; | ||
} | ||
}); | ||
loggerConfiguration.Enrich.WithElasticApmCorrelationInfo(); | ||
|
||
return loggerConfiguration; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/MaaCopilotServer.Api/Middleware/MiddlewareExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// This file is a part of MaaCopilotServer project. | ||
// MaaCopilotServer belongs to the MAA organization. | ||
// Licensed under the AGPL-3.0 license. | ||
|
||
namespace MaaCopilotServer.Api.Middleware; | ||
|
||
public static class MiddlewareExtension | ||
{ | ||
public static IApplicationBuilder UseRequestCulture(this IApplicationBuilder app) | ||
{ | ||
app.UseMiddleware<RequestCultureMiddleware>(); | ||
return app; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/MaaCopilotServer.Api/Middleware/RequestCultureMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// This file is a part of MaaCopilotServer project. | ||
// MaaCopilotServer belongs to the MAA organization. | ||
// Licensed under the AGPL-3.0 license. | ||
|
||
using System.Globalization; | ||
using MaaCopilotServer.Resources; | ||
|
||
namespace MaaCopilotServer.Api.Middleware; | ||
|
||
public class RequestCultureMiddleware | ||
{ | ||
private readonly RequestDelegate _next; | ||
|
||
public RequestCultureMiddleware(RequestDelegate next) | ||
{ | ||
_next = next; | ||
} | ||
|
||
public async Task InvokeAsync(HttpContext context, ValidationErrorMessage validationErrorMessage, ApiErrorMessage apiErrorMessage) | ||
{ | ||
var hasCulture = context.Request.Query.TryGetValue("culture", out var culture); | ||
var info = hasCulture ? new CultureInfo(culture) : new CultureInfo("zh-cn"); | ||
|
||
validationErrorMessage.CultureInfo = info; | ||
apiErrorMessage.CultureInfo = info; | ||
|
||
await _next(context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"Serilog": { | ||
"Using": [ | ||
"Serilog.Sinks.Console", | ||
"Serilog.Sinks.File" | ||
], | ||
"MinimumLevel": { | ||
"Default": "Information", | ||
"Override": { | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information", | ||
"Microsoft.EntityFrameworkCore.Database.Command": "Warning" | ||
} | ||
}, | ||
"WriteTo": [ | ||
{ | ||
"Name": "Console", | ||
"Args": { | ||
"outputTemplate": "[{Timestamp:HH:mm:ss} {ElasticApmTraceId} {ElasticApmTransactionId} {Level:u3}] {ThreadId} {Message:lj}{NewLine}{Exception}" | ||
} | ||
}, | ||
{ | ||
"Name": "File", | ||
"Args": { | ||
"outputTemplate": "[{Timestamp:HH:mm:ss} {ElasticApmTraceId} {ElasticApmTransactionId} {Level:u3}] {ThreadId} {Message:lj}{NewLine}{Exception}", | ||
"path": "{{ DATA DIRECTORY }}/logs/log-.log", | ||
"rollingInterval": "Day", | ||
"shared": true | ||
} | ||
} | ||
], | ||
"Enrich": [ | ||
"FromLogContext", | ||
"WithThreadId" | ||
] | ||
}, | ||
"Jwt": { | ||
"Secret": "YOUR STRONG 32+ BIT LENGTH (RECOMMEND 128 BIT OR MORE) SECRET TOKEN", | ||
"Issuer": "MaaCopilot", | ||
"Audience": "Doctor", | ||
"ExpireTime": 720 | ||
}, | ||
"Database": { | ||
"ConnectionString": "Server=127.0.0.1;Port=5432;Database=maa_copilot;User Id=maa_admin;Password=m@@_@dmin_p@ss;" | ||
}, | ||
"Switches": { | ||
"ElasticSearch": true, | ||
"Apm": true | ||
}, | ||
"ElasticLogSink": { | ||
"ApplicationName": "maa-copilot", | ||
"Uris": "http://localhost:9200", | ||
"Period": 10, | ||
"Authentication": { | ||
"Method": "Basic", | ||
"Secret": { | ||
"Id": "", | ||
"Key": "" | ||
} | ||
} | ||
}, | ||
"ElasticApm": { | ||
"SecretToken": "", | ||
"ServerUrl": "http://localhost:8200", | ||
"ServiceName": "MaaCopilotServer", | ||
"Environment": "production" | ||
}, | ||
"AllowedHosts": "*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.