refactor: 子包 attributes 改名 annotations——simapi.attributes → simapi.annotations
- src/attributes/ → src/annotations/(OriginResponse.cj / SimApiAuth.cj) - SimApiRequestDelegateFactory import 同步更新
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2025 SimcuTeam. All rights reserved.
|
||||
* 移植自 C# 项目 SimApi(E:\simcu\simapi-net),遵循 MIT 许可证。
|
||||
*/
|
||||
|
||||
package simapi.annotations
|
||||
|
||||
/**
|
||||
* 原样响应注解(对齐 C# SimApi.Attributes.OriginResponseAttribute)。
|
||||
*
|
||||
* 标注在控制器方法或类上,请求派发时 SimApiRequestDelegateFactory 跳过
|
||||
* 统一响应封装(SimApiBaseResponse 包装),接口返回什么就输出什么。
|
||||
*
|
||||
* 用法:
|
||||
* @OriginResponse
|
||||
* public func raw(): String { "hello" } // 直接输出 "hello",不包 {code,message,data}
|
||||
*/
|
||||
@Annotation[target: [MemberFunction, Type]]
|
||||
public class OriginResponse {
|
||||
public const init() {}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2025 SimcuTeam. All rights reserved.
|
||||
* 移植自 C# 项目 SimApi(E:\simcu\simapi-net),遵循 MIT 许可证。
|
||||
*/
|
||||
|
||||
package simapi.annotations
|
||||
|
||||
/**
|
||||
* 声明式鉴权注解(对齐 C# SimApi.Attributes.SimApiAuthAttribute)。
|
||||
*
|
||||
* 标注在控制器方法或类上,请求派发时(SimApiRequestDelegateFactory)自动执行鉴权:
|
||||
* - 未登录(无 LoginInfo)→ 401
|
||||
* - type 非空且登录用户类型不匹配 → 403
|
||||
* - 遍历执行所有已注册的 ISimApiAuthChecker
|
||||
*
|
||||
* 用法:
|
||||
* @SimApiAuth // 任意已登录用户
|
||||
* @SimApiAuth["admin"] // 仅 admin 类型
|
||||
* @SimApiAuth["admin,user"] // admin 或 user 类型(对齐 C# type.Split(","))
|
||||
*
|
||||
* 说明:仓颉注解参数须为编译期常量,String 无法作为 const 值数组元素,
|
||||
* 故与 C# 的 string[] 不同,这里用逗号分隔字符串对齐 C# 多类型。
|
||||
*/
|
||||
@Annotation[target: [MemberFunction, Type]]
|
||||
public class SimApiAuth {
|
||||
/// 允许访问的用户类型(空 = 任意已登录用户)
|
||||
public let `type`: String
|
||||
|
||||
public const init() {
|
||||
this.`type` = ""
|
||||
}
|
||||
|
||||
public const init(`type`: String) {
|
||||
this.`type` = `type`
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user