Files
simapi-net/Controllers/SimApiCommonController.cs
T

55 lines
1.5 KiB
C#
Raw Normal View History

2025-11-01 21:38:55 +08:00
using System.Collections.Generic;
2026-08-10 22:07:38 +08:00
using System.Linq;
2025-11-01 15:40:55 +08:00
using Microsoft.AspNetCore.Mvc;
2026-08-10 22:07:38 +08:00
using Microsoft.Extensions.Configuration;
using SimApi.Attributes;
using SimApi.Communications;
2026-08-10 22:07:38 +08:00
using SimApi.Configurations;
2020-08-05 15:29:56 +08:00
using SimApi.Helpers;
using static SimApi.Helpers.SimApiError;
2020-07-05 06:09:02 +08:00
2024-03-23 07:29:43 +08:00
namespace SimApi.Controllers;
2025-11-01 15:40:55 +08:00
2026-08-10 22:07:38 +08:00
public class SimApiCommonController(SimApiOptions simApiOptions) : SimApiBaseController
2020-07-05 06:09:02 +08:00
{
2024-03-23 07:29:43 +08:00
/// <summary>
/// 错误回馈页面
/// </summary>
/// <param name="code">错误代码</param>
/// <returns></returns>
[HttpGet("exception/{code:int}")]
2026-09-04 02:26:43 +08:00
[SimApiDoc(ignore: true)]
2026-04-26 12:27:56 +08:00
public void ExceptionHandler(int code)
2020-07-05 06:09:02 +08:00
{
Error(code);
2024-03-23 07:29:43 +08:00
}
2020-07-05 06:09:02 +08:00
2026-08-10 22:07:38 +08:00
/// <summary>
/// 给前端的自定义信息
/// </summary>
/// <returns></returns>
2025-11-01 15:40:55 +08:00
[HttpPost, HttpGet]
2026-09-04 02:26:43 +08:00
[HttpPost, SimApiDoc("公共", "获取自定义配置",groupNames: "*")]
2026-08-10 22:07:38 +08:00
public Dictionary<string, object> WebConfig()
2025-11-01 15:40:55 +08:00
{
2026-08-10 22:07:38 +08:00
var resp = simApiOptions.WebConfig!.ToDictionary();
if (simApiOptions.WebConfigIncludeVersion)
2025-11-01 15:40:55 +08:00
{
2026-08-10 22:07:38 +08:00
resp.Add("Versions", new Dictionary<string, string>
{
{ "SimApi", SimApiUtil.SimApiVersion },
{ "App", SimApiUtil.AppVersion }
});
}
return resp;
2025-11-01 15:40:55 +08:00
}
2026-08-10 22:07:38 +08:00
2026-05-20 09:38:40 +08:00
/// <summary>
/// 获取已登录用户信息
/// </summary>
/// <returns></returns>
2026-09-04 02:26:43 +08:00
[HttpPost, SimApiAuth, SimApiDoc("认证", "获取已登录用户信息",groupNames: "*")]
2026-05-20 09:38:40 +08:00
public SimApiLoginItem UserInfo() => LoginInfo;
2021-05-30 03:35:27 +08:00
}