befly 3.18.10 → 3.18.12
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/apis/menu/all.js +3 -10
- package/apis/role/apiSave.js +1 -1
- package/apis/role/apis.js +1 -1
- package/apis/role/del.js +1 -1
- package/apis/role/ins.js +1 -1
- package/apis/role/menuSave.js +1 -1
- package/apis/role/menus.js +1 -1
- package/apis/role/upd.js +1 -1
- package/checks/config.js +12 -0
- package/lib/cacheHelper.js +18 -18
- package/package.json +2 -2
package/apis/menu/all.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { isNonEmptyString, isString } from "../../utils/is.js";
|
|
2
|
-
|
|
3
1
|
export default {
|
|
4
|
-
name: "
|
|
2
|
+
name: "获取后台菜单",
|
|
5
3
|
method: "POST",
|
|
6
4
|
body: "none",
|
|
7
5
|
auth: true,
|
|
@@ -9,12 +7,7 @@ export default {
|
|
|
9
7
|
required: [],
|
|
10
8
|
handler: async (befly, ctx) => {
|
|
11
9
|
try {
|
|
12
|
-
const
|
|
13
|
-
if (!isNonEmptyString(roleCode)) {
|
|
14
|
-
return befly.tool.No("角色缺失", { lists: [] });
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const menuPaths = await befly.cache.getRoleMenuPermissions(roleCode);
|
|
10
|
+
const menuPaths = await befly.cache.getRoleMenus(ctx.roleCode);
|
|
18
11
|
|
|
19
12
|
if (menuPaths.length === 0) {
|
|
20
13
|
return befly.tool.Yes("菜单为空", { lists: [] });
|
|
@@ -29,7 +22,7 @@ export default {
|
|
|
29
22
|
const menuPathSet = new Set(menuPaths);
|
|
30
23
|
const authorizedMenus = allMenus.filter((menu) => {
|
|
31
24
|
const path = menu["path"];
|
|
32
|
-
return
|
|
25
|
+
return menuPathSet.has(path);
|
|
33
26
|
});
|
|
34
27
|
|
|
35
28
|
return befly.tool.Yes("获取菜单成功", { lists: authorizedMenus });
|
package/apis/role/apiSave.js
CHANGED
package/apis/role/apis.js
CHANGED
package/apis/role/del.js
CHANGED
package/apis/role/ins.js
CHANGED
package/apis/role/menuSave.js
CHANGED
package/apis/role/menus.js
CHANGED
package/apis/role/upd.js
CHANGED
package/checks/config.js
CHANGED
|
@@ -63,6 +63,18 @@ const configSchema = z
|
|
|
63
63
|
})
|
|
64
64
|
.strict(),
|
|
65
65
|
|
|
66
|
+
email: z
|
|
67
|
+
.object({
|
|
68
|
+
host: noTrimString,
|
|
69
|
+
port: z.int().min(1).max(65535),
|
|
70
|
+
secure: z.union([z.literal(0), z.literal(1), z.literal(true), z.literal(false)]),
|
|
71
|
+
user: noTrimString,
|
|
72
|
+
pass: noTrimString,
|
|
73
|
+
label: noTrimString.optional()
|
|
74
|
+
})
|
|
75
|
+
.strict()
|
|
76
|
+
.optional(),
|
|
77
|
+
|
|
66
78
|
cors: z
|
|
67
79
|
.object({
|
|
68
80
|
origin: noTrimString,
|
package/lib/cacheHelper.js
CHANGED
|
@@ -195,13 +195,13 @@ export class CacheHelper {
|
|
|
195
195
|
* - apiIds 为空数组:仅清理缓存(防止残留)
|
|
196
196
|
* - apiIds 非空:使用 $in 最小查询,DEL 后 SADD
|
|
197
197
|
*/
|
|
198
|
-
async
|
|
198
|
+
async refreshRoleApis(roleCode, apiPaths) {
|
|
199
199
|
if (!isNonEmptyString(roleCode)) {
|
|
200
200
|
throw new Error("roleCode 参数不合法", {
|
|
201
201
|
cause: null,
|
|
202
202
|
code: "validation",
|
|
203
203
|
subsystem: "cache",
|
|
204
|
-
operation: "
|
|
204
|
+
operation: "refreshRoleApis"
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
207
|
if (!Array.isArray(apiPaths)) {
|
|
@@ -209,7 +209,7 @@ export class CacheHelper {
|
|
|
209
209
|
cause: null,
|
|
210
210
|
code: "validation",
|
|
211
211
|
subsystem: "cache",
|
|
212
|
-
operation: "
|
|
212
|
+
operation: "refreshRoleApis"
|
|
213
213
|
});
|
|
214
214
|
}
|
|
215
215
|
|
|
@@ -234,13 +234,13 @@ export class CacheHelper {
|
|
|
234
234
|
* - menuPaths 为空数组:仅清理缓存(防止残留)
|
|
235
235
|
* - menuPaths 非空:DEL 后 SADD
|
|
236
236
|
*/
|
|
237
|
-
async
|
|
237
|
+
async refreshRoleMenus(roleCode, menuPaths) {
|
|
238
238
|
if (!isNonEmptyString(roleCode)) {
|
|
239
239
|
throw new Error("roleCode 参数不合法", {
|
|
240
240
|
cause: null,
|
|
241
241
|
code: "validation",
|
|
242
242
|
subsystem: "cache",
|
|
243
|
-
operation: "
|
|
243
|
+
operation: "refreshRoleMenus"
|
|
244
244
|
});
|
|
245
245
|
}
|
|
246
246
|
if (!Array.isArray(menuPaths)) {
|
|
@@ -248,7 +248,7 @@ export class CacheHelper {
|
|
|
248
248
|
cause: null,
|
|
249
249
|
code: "validation",
|
|
250
250
|
subsystem: "cache",
|
|
251
|
-
operation: "
|
|
251
|
+
operation: "refreshRoleMenus"
|
|
252
252
|
});
|
|
253
253
|
}
|
|
254
254
|
|
|
@@ -328,7 +328,7 @@ export class CacheHelper {
|
|
|
328
328
|
* @param roleCode - 角色代码
|
|
329
329
|
* @returns 接口路径列表
|
|
330
330
|
*/
|
|
331
|
-
async
|
|
331
|
+
async getRoleApis(roleCode) {
|
|
332
332
|
try {
|
|
333
333
|
const permissions = await this.redis.smembers(CacheKeys.roleApis(roleCode));
|
|
334
334
|
return permissions || [];
|
|
@@ -338,7 +338,7 @@ export class CacheHelper {
|
|
|
338
338
|
cause: error,
|
|
339
339
|
code: "runtime",
|
|
340
340
|
subsystem: "cache",
|
|
341
|
-
operation: "
|
|
341
|
+
operation: "getRoleApis",
|
|
342
342
|
roleCode: roleCode
|
|
343
343
|
});
|
|
344
344
|
}
|
|
@@ -349,7 +349,7 @@ export class CacheHelper {
|
|
|
349
349
|
* @param roleCode - 角色代码
|
|
350
350
|
* @returns 菜单路径列表(menu.path)
|
|
351
351
|
*/
|
|
352
|
-
async
|
|
352
|
+
async getRoleMenus(roleCode) {
|
|
353
353
|
try {
|
|
354
354
|
const permissions = await this.redis.smembers(CacheKeys.roleMenus(roleCode));
|
|
355
355
|
return permissions || [];
|
|
@@ -359,7 +359,7 @@ export class CacheHelper {
|
|
|
359
359
|
cause: error,
|
|
360
360
|
code: "runtime",
|
|
361
361
|
subsystem: "cache",
|
|
362
|
-
operation: "
|
|
362
|
+
operation: "getRoleMenus",
|
|
363
363
|
roleCode: roleCode
|
|
364
364
|
});
|
|
365
365
|
}
|
|
@@ -371,7 +371,7 @@ export class CacheHelper {
|
|
|
371
371
|
* @param apiPath - 接口路径(url.pathname,例如 /api/user/login;与 method 无关)
|
|
372
372
|
* @returns 是否有权限
|
|
373
373
|
*/
|
|
374
|
-
async
|
|
374
|
+
async checkRoleApis(roleCode, apiPath) {
|
|
375
375
|
try {
|
|
376
376
|
if (isNullable(apiPath)) return false;
|
|
377
377
|
const value = isString(apiPath) ? apiPath : String(apiPath);
|
|
@@ -382,7 +382,7 @@ export class CacheHelper {
|
|
|
382
382
|
cause: error,
|
|
383
383
|
code: "runtime",
|
|
384
384
|
subsystem: "cache",
|
|
385
|
-
operation: "
|
|
385
|
+
operation: "checkRoleApis",
|
|
386
386
|
roleCode: roleCode
|
|
387
387
|
});
|
|
388
388
|
}
|
|
@@ -394,7 +394,7 @@ export class CacheHelper {
|
|
|
394
394
|
* @param menuPath - 菜单路径(menu.path)
|
|
395
395
|
* @returns 是否有权限
|
|
396
396
|
*/
|
|
397
|
-
async
|
|
397
|
+
async checkRoleMenus(roleCode, menuPath) {
|
|
398
398
|
try {
|
|
399
399
|
if (isNullable(menuPath)) return false;
|
|
400
400
|
const value = isString(menuPath) ? menuPath : String(menuPath);
|
|
@@ -405,7 +405,7 @@ export class CacheHelper {
|
|
|
405
405
|
cause: error,
|
|
406
406
|
code: "runtime",
|
|
407
407
|
subsystem: "cache",
|
|
408
|
-
operation: "
|
|
408
|
+
operation: "checkRoleMenus",
|
|
409
409
|
roleCode: roleCode
|
|
410
410
|
});
|
|
411
411
|
}
|
|
@@ -416,7 +416,7 @@ export class CacheHelper {
|
|
|
416
416
|
* @param roleCode - 角色代码
|
|
417
417
|
* @returns 是否删除成功
|
|
418
418
|
*/
|
|
419
|
-
async
|
|
419
|
+
async deleteRoleApis(roleCode) {
|
|
420
420
|
try {
|
|
421
421
|
const result = await this.redis.del(CacheKeys.roleApis(roleCode));
|
|
422
422
|
if (result > 0) {
|
|
@@ -430,7 +430,7 @@ export class CacheHelper {
|
|
|
430
430
|
cause: error,
|
|
431
431
|
code: "runtime",
|
|
432
432
|
subsystem: "cache",
|
|
433
|
-
operation: "
|
|
433
|
+
operation: "deleteRoleApis",
|
|
434
434
|
roleCode: roleCode
|
|
435
435
|
});
|
|
436
436
|
}
|
|
@@ -441,7 +441,7 @@ export class CacheHelper {
|
|
|
441
441
|
* @param roleCode - 角色代码
|
|
442
442
|
* @returns 是否删除成功
|
|
443
443
|
*/
|
|
444
|
-
async
|
|
444
|
+
async deleteRoleMenus(roleCode) {
|
|
445
445
|
try {
|
|
446
446
|
const result = await this.redis.del(CacheKeys.roleMenus(roleCode));
|
|
447
447
|
if (result > 0) {
|
|
@@ -455,7 +455,7 @@ export class CacheHelper {
|
|
|
455
455
|
cause: error,
|
|
456
456
|
code: "runtime",
|
|
457
457
|
subsystem: "cache",
|
|
458
|
-
operation: "
|
|
458
|
+
operation: "deleteRoleMenus",
|
|
459
459
|
roleCode: roleCode
|
|
460
460
|
});
|
|
461
461
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.18.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.18.12",
|
|
4
|
+
"gitHead": "31db0dcea06e03f3116a3bf6c33f5e54180b2436",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
|
|
7
7
|
"keywords": [
|