diff --git a/Controllers/SimApiCoceController.cs b/CoceSdk/CoceController.cs similarity index 77% rename from Controllers/SimApiCoceController.cs rename to CoceSdk/CoceController.cs index eb8ed6a..70842c8 100644 --- a/Controllers/SimApiCoceController.cs +++ b/CoceSdk/CoceController.cs @@ -1,14 +1,16 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.DependencyInjection; using SimApi.Attributes; -using SimApi.CoceSdk; using SimApi.Communications; +using SimApi.Controllers; using SimApi.Helpers; -namespace SimApi.Controllers; +namespace SimApi.CoceSdk; -public class SimApiCoceController(CoceApp coce,SimApiAuth auth) : SimApiBaseController +public class CoceController(CoceApp coce, SimApiAuth auth, IServiceProvider sp) : SimApiBaseController { [HttpPost] public SimApiBaseResponse GetConfig() @@ -33,8 +35,9 @@ public class SimApiCoceController(CoceApp coce,SimApiAuth auth) : SimApiBaseCont { Id = data.UserId, Meta = meta, - Extra = groups }; + var processor = sp.GetService(); + processor?.Process(loginItem, groups.ToArray()); return new SimApiBaseResponse(auth.Login(loginItem)); } diff --git a/CoceSdk/ICoceLoginProcessor.cs b/CoceSdk/ICoceLoginProcessor.cs new file mode 100644 index 0000000..6f61930 --- /dev/null +++ b/CoceSdk/ICoceLoginProcessor.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; +using SimApi.Communications; + +namespace SimApi.CoceSdk; + +public interface ICoceLoginProcessor +{ + SimApiLoginItem Process(SimApiLoginItem loginItem, GroupInfo[] groups); +} \ No newline at end of file diff --git a/Configurations/SimApiOptions.cs b/Configurations/SimApiOptions.cs index fe23e9e..9bd90d2 100644 --- a/Configurations/SimApiOptions.cs +++ b/Configurations/SimApiOptions.cs @@ -10,13 +10,7 @@ public class SimApiOptions /// /// 是否启用后台任务系统 *基于Hangfire /// - public bool EnableJob { get; set; } = false; - - /// - /// 启用全部Cors,对于开发前后分离的时候很有用。 - /// default: true - /// - public bool EnableCors { get; set; } = true; + public bool EnableJob { get; set; } /// /// 启用SimApiAuth,一个简单的基于Header Token的认证方式。 @@ -24,13 +18,16 @@ public class SimApiOptions /// public bool EnableSimApiAuth { get; set; } - /// /// 是否使用CoceSdk /// public bool EnableCoceSdk { get; set; } - public CoceAppSdkOption CoceSdkOptions { get; set; } = new(); + /// + /// 开启S3兼容的存储系统。 + /// default: false + /// + public bool EnableSimApiStorage { get; set; } /// /// 启用在线文档,启用后 访问 /swagger 可以查看对应的api文档。 @@ -38,6 +35,20 @@ public class SimApiOptions /// public bool EnableSimApiDoc { get; set; } + /// + /// 是否启用Synapse + /// + public bool EnableSynapse { get; set; } + + /// + /// 启用全部Cors,对于开发前后分离的时候很有用。 + /// default: true + /// + public bool EnableCors { get; set; } = true; + + + public CoceAppSdkOption CoceSdkOptions { get; set; } = new(); + /// /// 启用异常拦截,启用后,所有的异常将被通过json反馈。 /// default: true @@ -49,11 +60,6 @@ public class SimApiOptions /// public bool EnableSimApiResponseFilter { get; set; } = true; - /// - /// 开启S3兼容的存储系统。 - /// default: false - /// - public bool EnableSimApiStorage { get; set; } /// /// 开启ForwardHeaders,开启后可以透传负载均衡的Headers @@ -67,16 +73,13 @@ public class SimApiOptions /// public bool EnableLowerUrl { get; set; } = true; + /// /// 启用格式化的 Console Logger /// default: false /// - public bool EnableLogger { get; set; } + public bool EnableLogger { get; set; } = true; - /// - /// 是否启用Synapse - /// - public bool EnableSynapse { get; set; } /// /// 配置Job diff --git a/SimApiExtensions.cs b/SimApiExtensions.cs index 2c0b8fa..4015ced 100644 --- a/SimApiExtensions.cs +++ b/SimApiExtensions.cs @@ -246,6 +246,7 @@ public static class SimApiExtensions if (simApiOptions.EnableSimApiResponseFilter) { builder.AddControllers(opt => opt.Filters.Add()) + .AddXmlSerializerFormatters() .AddJsonOptions(opt => opt.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase); } @@ -319,6 +320,7 @@ public static class SimApiExtensions if (options.EnableSimApiResponseFilter) { logger.LogInformation("开始配置SimApiResponseFilter..."); + builder.MapControllers(); } if (options.EnableSimApiAuth) @@ -337,11 +339,11 @@ public static class SimApiExtensions options.CoceSdkOptions.ApiEndpoint, options.CoceSdkOptions.AuthEndpoint, options.CoceSdkOptions.AppId); builder.MapControllerRoute(name: "LoginUseCoce", pattern: "/auth/login", - defaults: new { controller = "SimApiCoce", action = "Login" }); + defaults: new { controller = "Coce", action = "Login" }); builder.MapControllerRoute(name: "LoginUseCoce", pattern: "/user/groups", - defaults: new { controller = "SimApiCoce", action = "ListGroups" }); + defaults: new { controller = "Coce", action = "ListGroups" }); builder.MapControllerRoute(name: "LoginUseCoce", pattern: "/auth/config", - defaults: new { controller = "SimApiCoce", action = "GetConfig" }); + defaults: new { controller = "Coce", action = "GetConfig" }); } }