From b6dbcd6ceee794de8833293fd6f5a78392a4a113 Mon Sep 17 00:00:00 2001 From: xRain Date: Sun, 26 Apr 2026 12:27:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BA=86=E5=86=85=E7=BD=AE?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=99=A8=E8=BF=94=E5=9B=9E=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CoceSdk/CoceController.cs | 8 ++++---- Controllers/SimApiAuthController.cs | 23 ++++++----------------- Controllers/SimApiCommonController.cs | 16 ++++++---------- Helpers/SimApiError.cs | 12 ------------ 4 files changed, 16 insertions(+), 43 deletions(-) diff --git a/CoceSdk/CoceController.cs b/CoceSdk/CoceController.cs index 250e616..32cb63c 100644 --- a/CoceSdk/CoceController.cs +++ b/CoceSdk/CoceController.cs @@ -20,7 +20,7 @@ public class CoceController(CoceApp coce, SimApiAuth auth, IServiceProvider sp) } [HttpPost] - public SimApiBaseResponse Login([FromBody] SimApiOneFieldRequest request) + public string Login([FromBody] SimApiOneFieldRequest request) { var data = coce.GetLevelToken(request.Data!); ErrorWhenNull(data, 400); @@ -39,14 +39,14 @@ public class CoceController(CoceApp coce, SimApiAuth auth, IServiceProvider sp) }; var processor = sp.GetService(); processor?.Process(loginItem, groups.ToArray()); - return new SimApiBaseResponse(auth.Login(loginItem)); + return auth.Login(loginItem); } [HttpPost, SimApiAuth] - public SimApiBaseResponse ListGroups() + public GroupInfo[] ListGroups() { var levelToken = coce.GetToken(LoginInfo.Id!); var groups = coce.GetUserGroups(levelToken!)!; - return new SimApiBaseResponse(groups.ToArray()); + return groups.ToArray(); } } \ No newline at end of file diff --git a/Controllers/SimApiAuthController.cs b/Controllers/SimApiAuthController.cs index 843f150..e6e7234 100644 --- a/Controllers/SimApiAuthController.cs +++ b/Controllers/SimApiAuthController.cs @@ -14,13 +14,10 @@ public class SimApiAuthController(SimApiAuth auth) : SimApiBaseController /// /// [HttpPost, SimApiDoc("认证", "检测登陆")] - public SimApiBaseResponse CheckLogin() + public string CheckLogin() { ErrorWhenNull(LoginInfo, 401, "未登录"); - return new SimApiBaseResponse - { - Data = LoginInfo.Id - }; + return LoginInfo.Id; } /// @@ -28,23 +25,15 @@ public class SimApiAuthController(SimApiAuth auth) : SimApiBaseController /// /// [HttpPost, SimApiDoc("认证", "退出登陆")] - public SimApiBaseResponse Logout() + public void Logout() { - string? token = null; - if (Request.Headers.TryGetValue("Token", out var value)) { - token = value; + auth.Logout(value!); } - - auth.Logout(token!); - return new SimApiBaseResponse(); } - [HttpPost, SimApiAuth] - public SimApiBaseResponse UserInfo() - { - return new SimApiBaseResponse(LoginInfo); - } + [HttpPost, SimApiAuth, SimApiDoc("认证", "获取已登录用户信息")] + public SimApiLoginItem UserInfo() => LoginInfo; } \ No newline at end of file diff --git a/Controllers/SimApiCommonController.cs b/Controllers/SimApiCommonController.cs index f88c300..aa0df92 100644 --- a/Controllers/SimApiCommonController.cs +++ b/Controllers/SimApiCommonController.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; -using SimApi.Communications; using SimApi.Helpers; namespace SimApi.Controllers; @@ -14,22 +13,19 @@ public class SimApiCommonController : SimApiBaseController /// [HttpGet("exception/{code:int}")] [ApiExplorerSettings(IgnoreApi = true)] - public SimApiBaseResponse ExceptionHandler(int code) + public void ExceptionHandler(int code) { - return new SimApiBaseResponse(code); + SimApiError.Error(code); } [HttpPost, HttpGet] - public SimApiBaseResponse> Versions() + public Dictionary Versions() { - return new SimApiBaseResponse>() + return new Dictionary { - Data = new Dictionary - { - { "SimApi", SimApiUtil.SimApiVersion }, - { "App", SimApiUtil.AppVersion } - } + { "SimApi", SimApiUtil.SimApiVersion }, + { "App", SimApiUtil.AppVersion } }; } } \ No newline at end of file diff --git a/Helpers/SimApiError.cs b/Helpers/SimApiError.cs index d815365..57b487f 100644 --- a/Helpers/SimApiError.cs +++ b/Helpers/SimApiError.cs @@ -68,16 +68,4 @@ public static class SimApiError { ErrorWhen(condition == null, code, message); } - - /// - /// 检测给定的泛型变量是否为Null(提供更精确的编译器 null 流分析) - /// - /// 检测条件 - /// 错误代码 - /// 错误描述 - public static void ErrorWhenNull([NotNull] T? condition, int code = 404, - string message = "请求的资源不存在") where T : class - { - ErrorWhen(condition == null, code, message); - } } \ No newline at end of file