2025-12-28 22:55:41 +08:00

63 lines
1.9 KiB
C#

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Milimoe.FunGame.WebAPI.Constant;
using Milimoe.FunGame.Core.Api.Transmittal;
using Milimoe.FunGame.Core.Api.Utility;
using Milimoe.FunGame.Core.Library.Common.Addon;
namespace Milimoe.FunGame.WebAPI
{
public class MilimoeWebAPI : WebAPIPlugin
{
public override string Name => Constants.WebAPI;
public override string Description => Constants.Description;
public override string Version => Constants.Version;
public override string Author => Constants.Author;
public override void ProcessInput(string input)
{
try
{
if (input.Trim() != "")
{
Controller.WriteLine("Console Reply");
}
}
catch (Exception e)
{
Controller.Error(e);
}
}
public override void AfterLoad(WebAPIPluginLoader loader, params object[] objs)
{
Statics.RunningPlugin ??= this;
Statics.WebAPIPluginLoader ??= loader;
Controller.NewSQLHelper();
Controller.NewMailSender();
if (objs.Length > 0 && objs[0] is WebApplicationBuilder builder)
{
builder.Services.AddTransient(provider =>
{
SQLHelper? sql = Factory.OpenFactory.GetSQLHelper();
if (sql != null) return sql;
throw new Milimoe.FunGame.SQLServiceException();
});
}
WebAPIAuthenticator.WebAPICustomBearerTokenAuthenticator += CustomBearerTokenAuthenticator;
}
private string CustomBearerTokenAuthenticator(string token)
{
if (Configs.TokenList.Contains(token))
{
return "APIUser";
}
return "";
}
}
}