66 lines
2.1 KiB
Plaintext
66 lines
2.1 KiB
Plaintext
/*
|
|
* Copyright (c) 2025 SimcuTeam. All rights reserved.
|
|
* 遵循 MIT 许可证。
|
|
* Controllers/SimApiCommonController:通用内置路由。
|
|
*/
|
|
|
|
package simcu::simapi.controllers
|
|
|
|
import std.collection.*
|
|
import soulsoft_web_mvc.annotations.*
|
|
import simcu::simapi.communications.*
|
|
import simcu::simapi.configurations.*
|
|
import simcu::simapi.helpers.*
|
|
import simcu::simapi.annotations.{SimApiAuth as SimApiAuthAttribute}
|
|
import simcu::simapi.openapi.annotations.*
|
|
|
|
/**
|
|
* 通用控制器:错误反馈、WebConfig、用户信息。
|
|
* 控制器直接返回 SimApiBaseResponse / SimApiResponse<T>。
|
|
*/
|
|
public class SimApiCommonController <: SimApiBaseController {
|
|
private let _options: SimApiOptions
|
|
|
|
public init(options: SimApiOptions) {
|
|
this._options = options
|
|
}
|
|
|
|
/**
|
|
* GET /exception/{code}:错误反馈页面(始终注册)。
|
|
* 抛 SimApiException,由异常中间件统一输出。
|
|
*/
|
|
@HttpGet["exception/{code}"]
|
|
@SimApiDoc[ignore: true]
|
|
public func exceptionHandler(@FromRoute[] code: Int64) { // cjlint-ignore !G.FUN.02 注解绑定参数误报
|
|
SimApiError.error(code: code)
|
|
}
|
|
|
|
/**
|
|
* POST/GET /config:给前端的自定义信息(含版本)。
|
|
* 动态注册:路由路径由 SimApiRouteOptions.webConfigRoute 决定(见 simapi_extensions.cj)。
|
|
*/
|
|
public func webConfig(): HashMap<String, Any> {
|
|
var versionMap = HashMap<String, Any>()
|
|
versionMap["SimApi"] = SimApiUtil.simApiVersion
|
|
versionMap["App"] = SimApiUtil.appVersion
|
|
var map = HashMap<String, Any>()
|
|
for ((key, value) in _options.webConfig) {
|
|
map[key] = value
|
|
}
|
|
if (_options.webConfigIncludeVersion) {
|
|
map["Versions"] = versionMap
|
|
}
|
|
map
|
|
}
|
|
|
|
|
|
/**
|
|
* POST /user/info:获取已登录用户信息(需登录)。
|
|
* 动态注册:路由路径由 SimApiRouteOptions.userInfoRoute 决定(见 simapi_extensions.cj)。
|
|
*/
|
|
@SimApiAuthAttribute
|
|
public func userInfo(): SimApiLoginItem {
|
|
loginInfo
|
|
}
|
|
}
|