befly 3.10.6 → 3.10.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/hooks/hook.md +2 -1
- package/hooks/permission.ts +9 -6
- package/package.json +3 -3
package/docs/hooks/hook.md
CHANGED
|
@@ -452,7 +452,8 @@ const hook: Hook = {
|
|
|
452
452
|
}
|
|
453
453
|
|
|
454
454
|
if (!hasPermission) {
|
|
455
|
-
ctx.
|
|
455
|
+
const apiLabel = ctx.api?.name ? ctx.api.name : apiPath;
|
|
456
|
+
ctx.response = ErrorResponse(ctx, `无权访问 ${apiLabel} 接口`);
|
|
456
457
|
return;
|
|
457
458
|
}
|
|
458
459
|
}
|
package/hooks/permission.ts
CHANGED
|
@@ -35,12 +35,12 @@ export default {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// 4. 角色权限检查
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const apiPath = ctx.route;
|
|
42
|
-
const roleCode = ctx.user.roleCode;
|
|
38
|
+
// apiPath 在 apiHandler 中已统一生成并写入 ctx.route
|
|
39
|
+
const apiPath = ctx.route;
|
|
40
|
+
const roleCode = ctx.user.roleCode;
|
|
43
41
|
|
|
42
|
+
let hasPermission = false;
|
|
43
|
+
if (roleCode && befly.redis) {
|
|
44
44
|
try {
|
|
45
45
|
// 极简方案:每个角色一个 Set,直接判断成员是否存在
|
|
46
46
|
const roleApisKey = CacheKeys.roleApis(roleCode);
|
|
@@ -61,7 +61,10 @@ export default {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
if (!hasPermission) {
|
|
64
|
-
|
|
64
|
+
const apiNameLabel = typeof ctx.api.name === "string" && ctx.api.name.length > 0 ? ctx.api.name : null;
|
|
65
|
+
const apiPathLabel = typeof apiPath === "string" && apiPath.length > 0 ? apiPath : null;
|
|
66
|
+
const apiLabel = apiNameLabel ? apiNameLabel : apiPathLabel ? apiPathLabel : "未知接口";
|
|
67
|
+
ctx.response = ErrorResponse(ctx, `无权访问 ${apiLabel} 接口`, 1, null, { apiLabel: apiLabel }, "permission");
|
|
65
68
|
return;
|
|
66
69
|
}
|
|
67
70
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.10.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.10.8",
|
|
4
|
+
"gitHead": "f97afb740dabb7d42dd1f9d6bae5ec4744359d1c",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
|
|
7
7
|
"keywords": [
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"typecheck": "bunx tsgo --noEmit"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"befly-shared": "1.3.
|
|
65
|
+
"befly-shared": "^1.3.5",
|
|
66
66
|
"chalk": "^5.6.2",
|
|
67
67
|
"es-toolkit": "^1.43.0",
|
|
68
68
|
"fast-jwt": "^6.1.0",
|