mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 06:43:57 +00:00
enter intro cutscene
This commit is contained in:
24
SdkServer/Utils/JsonStringToObjectConverter.cs
Normal file
24
SdkServer/Utils/JsonStringToObjectConverter.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.SdkServer.Utils;
|
||||
|
||||
public class JsonStringToObjectConverter<T> : JsonConverter<T> where T : class
|
||||
{
|
||||
public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.String)
|
||||
return JsonSerializer.Deserialize<T>(ref reader, options);
|
||||
|
||||
var jsonString = reader.GetString();
|
||||
return !string.IsNullOrEmpty(jsonString)
|
||||
? JsonSerializer.Deserialize<T>(jsonString, options)
|
||||
: null;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
|
||||
{
|
||||
var json = JsonSerializer.Serialize(value, options);
|
||||
writer.WriteStringValue(json);
|
||||
}
|
||||
}
|
||||
34
SdkServer/Utils/LoggingMiddleware.cs
Normal file
34
SdkServer/Utils/LoggingMiddleware.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using MikuSB.Util;
|
||||
|
||||
namespace MikuSB.SdkServer.Utils;
|
||||
|
||||
public class RequestLoggingMiddleware(RequestDelegate next)
|
||||
{
|
||||
public async Task InvokeAsync(HttpContext context, Logger logger)
|
||||
{
|
||||
var request = context.Request;
|
||||
var method = request.Method;
|
||||
var path = request.Path + request.QueryString;
|
||||
|
||||
await next(context);
|
||||
|
||||
var statusCode = context.Response.StatusCode;
|
||||
|
||||
if (path.StartsWith("/report") || path.Contains("/log/") || path == "/alive")
|
||||
return;
|
||||
|
||||
if (statusCode == 200)
|
||||
{
|
||||
logger.Info($"{method} {path} => {statusCode}");
|
||||
}
|
||||
else if (statusCode == 404)
|
||||
{
|
||||
logger.Warn($"{method} {path} => {statusCode}");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error($"{method} {path} => {statusCode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user