befly 3.17.6 → 3.17.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.
@@ -16,88 +16,11 @@ export class CacheHelper {
16
16
  this.redis = deps.redis;
17
17
  }
18
18
 
19
- assertApiPathList(value) {
20
- if (isNullable(value)) return [];
21
-
22
- let list = value;
23
-
24
- if (isString(list)) {
25
- const trimmed = list.trim();
26
- if (trimmed === "" || trimmed === "null") {
27
- return [];
28
- }
29
-
30
- if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
31
- try {
32
- list = JSON.parse(trimmed);
33
- } catch {
34
- return [];
35
- }
36
- }
37
- }
38
-
39
- if (!Array.isArray(list)) {
40
- return [];
41
- }
42
-
43
- const out = [];
44
- for (const item of list) {
45
- if (!isString(item)) continue;
46
- const trimmed = item.trim();
47
- if (!isNonEmptyString(trimmed)) continue;
48
- out.push(trimmed);
49
- }
50
-
51
- return out;
52
- }
53
-
54
- assertMenuPathList(value) {
55
- if (isNullable(value)) return [];
56
-
57
- let list = value;
58
-
59
- if (isString(list)) {
60
- const trimmed = list.trim();
61
- if (trimmed === "" || trimmed === "null") {
62
- return [];
63
- }
64
-
65
- if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
66
- try {
67
- list = JSON.parse(trimmed);
68
- } catch {
69
- return [];
70
- }
71
- }
72
- }
73
-
74
- if (!Array.isArray(list)) {
75
- return [];
76
- }
77
-
78
- const out = [];
79
- for (const item of list) {
80
- if (!isString(item)) continue;
81
- const trimmed = item.trim();
82
- if (!isNonEmptyString(trimmed)) continue;
83
- out.push(trimmed);
84
- }
85
-
86
- return out;
87
- }
88
-
89
19
  /**
90
20
  * 缓存所有接口到 Redis
91
21
  */
92
22
  async cacheApis() {
93
23
  try {
94
- // 检查表是否存在
95
- const tableExists = await this.mysql.tableExists("beflyApi");
96
- if (!tableExists.data) {
97
- Logger.warn("⚠️ 接口表不存在,跳过接口缓存");
98
- return;
99
- }
100
-
101
24
  // 从数据库查询所有接口
102
25
  const apiList = await this.mysql.getAll({
103
26
  table: "beflyApi"
@@ -107,10 +30,19 @@ export class CacheHelper {
107
30
  const result = await this.redis.setObject(CacheKeys.apisAll(), apiList.data.lists);
108
31
 
109
32
  if (result === null) {
110
- Logger.warn("⚠️ 接口缓存失败");
33
+ Logger.warn("⚠️ 接口缓存失败", {
34
+ subsystem: "cache",
35
+ operation: "cacheApis"
36
+ });
111
37
  }
112
38
  } catch (error) {
113
39
  Logger.error("⚠️ 接口缓存异常", error);
40
+ throw new Error("接口缓存异常", {
41
+ cause: error,
42
+ code: "runtime",
43
+ subsystem: "cache",
44
+ operation: "cacheApis"
45
+ });
114
46
  }
115
47
  }
116
48
 
@@ -119,13 +51,6 @@ export class CacheHelper {
119
51
  */
120
52
  async cacheMenus() {
121
53
  try {
122
- // 检查表是否存在
123
- const tableExists = await this.mysql.tableExists("beflyMenu");
124
- if (!tableExists.data) {
125
- Logger.warn("⚠️ 菜单表不存在,跳过菜单缓存");
126
- return;
127
- }
128
-
129
54
  // 从数据库查询所有菜单
130
55
  const menus = await this.mysql.getAll({
131
56
  table: "beflyMenu"
@@ -135,10 +60,19 @@ export class CacheHelper {
135
60
  const result = await this.redis.setObject(CacheKeys.menusAll(), menus.data.lists);
136
61
 
137
62
  if (result === null) {
138
- Logger.warn("⚠️ 菜单缓存失败");
63
+ Logger.warn("⚠️ 菜单缓存失败", {
64
+ subsystem: "cache",
65
+ operation: "cacheMenus"
66
+ });
139
67
  }
140
68
  } catch (error) {
141
- Logger.warn("⚠️ 菜单缓存异常", { err: error });
69
+ Logger.error("⚠️ 菜单缓存异常", error);
70
+ throw new Error("菜单缓存异常", {
71
+ cause: error,
72
+ code: "runtime",
73
+ subsystem: "cache",
74
+ operation: "cacheMenus"
75
+ });
142
76
  }
143
77
  }
144
78
 
@@ -149,14 +83,6 @@ export class CacheHelper {
149
83
  */
150
84
  async cacheRoleApis() {
151
85
  try {
152
- // 检查表是否存在
153
- const roleTableExists = await this.mysql.tableExists("beflyRole");
154
-
155
- if (!roleTableExists.data) {
156
- Logger.warn("⚠️ 角色表不存在,跳过角色权限缓存");
157
- return;
158
- }
159
-
160
86
  // 查询所有角色(仅取必要字段)
161
87
  const roles = await this.mysql.getAll({
162
88
  table: "beflyRole",
@@ -167,8 +93,7 @@ export class CacheHelper {
167
93
 
168
94
  for (const role of roles.data.lists) {
169
95
  if (!role?.code) continue;
170
- const apiPaths = this.assertApiPathList(role.apis);
171
- roleApiPathsMap.set(role.code, apiPaths);
96
+ roleApiPathsMap.set(role.code, role.apis);
172
97
  }
173
98
 
174
99
  const roleCodes = Array.from(roleApiPathsMap.keys());
@@ -216,14 +141,6 @@ export class CacheHelper {
216
141
  */
217
142
  async cacheRoleMenus() {
218
143
  try {
219
- // 检查表是否存在
220
- const roleTableExists = await this.mysql.tableExists("beflyRole");
221
-
222
- if (!roleTableExists.data) {
223
- Logger.warn("⚠️ 角色表不存在,跳过角色菜单权限缓存");
224
- return;
225
- }
226
-
227
144
  // 查询所有角色(仅取必要字段)
228
145
  const roles = await this.mysql.getAll({
229
146
  table: "beflyRole",
@@ -234,8 +151,7 @@ export class CacheHelper {
234
151
 
235
152
  for (const role of roles.data.lists) {
236
153
  if (!role?.code) continue;
237
- const menuPaths = this.assertMenuPathList(role.menus);
238
- roleMenuPathsMap.set(role.code, menuPaths);
154
+ roleMenuPathsMap.set(role.code, role.menus);
239
155
  }
240
156
 
241
157
  const roleCodes = Array.from(roleMenuPathsMap.keys());
@@ -281,22 +197,31 @@ export class CacheHelper {
281
197
  */
282
198
  async refreshRoleApiPermissions(roleCode, apiPaths) {
283
199
  if (!isNonEmptyString(roleCode)) {
284
- return;
200
+ throw new Error("roleCode 参数不合法", {
201
+ cause: null,
202
+ code: "validation",
203
+ subsystem: "cache",
204
+ operation: "refreshRoleApiPermissions"
205
+ });
285
206
  }
286
207
  if (!Array.isArray(apiPaths)) {
287
- return;
208
+ throw new Error("apiPaths 参数不合法", {
209
+ cause: null,
210
+ code: "validation",
211
+ subsystem: "cache",
212
+ operation: "refreshRoleApiPermissions"
213
+ });
288
214
  }
289
215
 
290
- const normalizedPaths = this.assertApiPathList(apiPaths);
291
216
  const roleKey = CacheKeys.roleApis(roleCode);
292
217
 
293
218
  // 空数组短路:保证清理残留
294
- if (normalizedPaths.length === 0) {
219
+ if (apiPaths.length === 0) {
295
220
  await this.redis.del(roleKey);
296
221
  return;
297
222
  }
298
223
 
299
- const members = Array.from(new Set(normalizedPaths));
224
+ const members = Array.from(new Set(apiPaths));
300
225
 
301
226
  await this.redis.del(roleKey);
302
227
  if (members.length > 0) {
@@ -311,22 +236,31 @@ export class CacheHelper {
311
236
  */
312
237
  async refreshRoleMenuPermissions(roleCode, menuPaths) {
313
238
  if (!isNonEmptyString(roleCode)) {
314
- return;
239
+ throw new Error("roleCode 参数不合法", {
240
+ cause: null,
241
+ code: "validation",
242
+ subsystem: "cache",
243
+ operation: "refreshRoleMenuPermissions"
244
+ });
315
245
  }
316
246
  if (!Array.isArray(menuPaths)) {
317
- return;
247
+ throw new Error("menuPaths 参数不合法", {
248
+ cause: null,
249
+ code: "validation",
250
+ subsystem: "cache",
251
+ operation: "refreshRoleMenuPermissions"
252
+ });
318
253
  }
319
254
 
320
- const normalizedPaths = this.assertMenuPathList(menuPaths);
321
255
  const roleKey = CacheKeys.roleMenus(roleCode);
322
256
 
323
257
  // 空数组短路:保证清理残留
324
- if (normalizedPaths.length === 0) {
258
+ if (menuPaths.length === 0) {
325
259
  await this.redis.del(roleKey);
326
260
  return;
327
261
  }
328
262
 
329
- const members = Array.from(new Set(normalizedPaths));
263
+ const members = Array.from(new Set(menuPaths));
330
264
 
331
265
  await this.redis.del(roleKey);
332
266
  if (members.length > 0) {
@@ -361,7 +295,12 @@ export class CacheHelper {
361
295
  return apis || [];
362
296
  } catch (error) {
363
297
  Logger.error("获取接口缓存失败", error);
364
- return [];
298
+ throw new Error("获取接口缓存失败", {
299
+ cause: error,
300
+ code: "runtime",
301
+ subsystem: "cache",
302
+ operation: "getApis"
303
+ });
365
304
  }
366
305
  }
367
306
 
@@ -375,7 +314,12 @@ export class CacheHelper {
375
314
  return menus || [];
376
315
  } catch (error) {
377
316
  Logger.error("获取菜单缓存失败", error);
378
- return [];
317
+ throw new Error("获取菜单缓存失败", {
318
+ cause: error,
319
+ code: "runtime",
320
+ subsystem: "cache",
321
+ operation: "getMenus"
322
+ });
379
323
  }
380
324
  }
381
325
 
@@ -390,7 +334,13 @@ export class CacheHelper {
390
334
  return permissions || [];
391
335
  } catch (error) {
392
336
  Logger.error("获取角色权限缓存失败", error, { roleCode: roleCode });
393
- return [];
337
+ throw new Error("获取角色权限缓存失败", {
338
+ cause: error,
339
+ code: "runtime",
340
+ subsystem: "cache",
341
+ operation: "getRolePermissions",
342
+ roleCode: roleCode
343
+ });
394
344
  }
395
345
  }
396
346
 
@@ -405,7 +355,13 @@ export class CacheHelper {
405
355
  return permissions || [];
406
356
  } catch (error) {
407
357
  Logger.error("获取角色菜单权限缓存失败", error, { roleCode: roleCode });
408
- return [];
358
+ throw new Error("获取角色菜单权限缓存失败", {
359
+ cause: error,
360
+ code: "runtime",
361
+ subsystem: "cache",
362
+ operation: "getRoleMenuPermissions",
363
+ roleCode: roleCode
364
+ });
409
365
  }
410
366
  }
411
367
 
@@ -422,7 +378,13 @@ export class CacheHelper {
422
378
  return await this.redis.sismember(CacheKeys.roleApis(roleCode), value);
423
379
  } catch (error) {
424
380
  Logger.error("检查角色权限失败", error, { roleCode: roleCode });
425
- return false;
381
+ throw new Error("检查角色权限失败", {
382
+ cause: error,
383
+ code: "runtime",
384
+ subsystem: "cache",
385
+ operation: "checkRolePermission",
386
+ roleCode: roleCode
387
+ });
426
388
  }
427
389
  }
428
390
 
@@ -439,7 +401,13 @@ export class CacheHelper {
439
401
  return await this.redis.sismember(CacheKeys.roleMenus(roleCode), value);
440
402
  } catch (error) {
441
403
  Logger.error("检查角色菜单权限失败", error, { roleCode: roleCode });
442
- return false;
404
+ throw new Error("检查角色菜单权限失败", {
405
+ cause: error,
406
+ code: "runtime",
407
+ subsystem: "cache",
408
+ operation: "checkRoleMenuPermission",
409
+ roleCode: roleCode
410
+ });
443
411
  }
444
412
  }
445
413
 
@@ -458,7 +426,13 @@ export class CacheHelper {
458
426
  return false;
459
427
  } catch (error) {
460
428
  Logger.error("删除角色权限缓存失败", error, { roleCode: roleCode });
461
- return false;
429
+ throw new Error("删除角色权限缓存失败", {
430
+ cause: error,
431
+ code: "runtime",
432
+ subsystem: "cache",
433
+ operation: "deleteRolePermissions",
434
+ roleCode: roleCode
435
+ });
462
436
  }
463
437
  }
464
438
 
@@ -477,7 +451,13 @@ export class CacheHelper {
477
451
  return false;
478
452
  } catch (error) {
479
453
  Logger.error("删除角色菜单权限缓存失败", error, { roleCode: roleCode });
480
- return false;
454
+ throw new Error("删除角色菜单权限缓存失败", {
455
+ cause: error,
456
+ code: "runtime",
457
+ subsystem: "cache",
458
+ operation: "deleteRoleMenuPermissions",
459
+ roleCode: roleCode
460
+ });
481
461
  }
482
462
  }
483
463
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.17.6",
4
- "gitHead": "22a41360132e5482ba67a3884a008599942a72c1",
3
+ "version": "3.17.8",
4
+ "gitHead": "ff02e6df24881973a91e4943381ba8559ed9c55d",
5
5
  "private": false,
6
6
  "description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
7
7
  "keywords": [
package/sql/befly.sql ADDED
@@ -0,0 +1,173 @@
1
+ CREATE TABLE IF NOT EXISTS `befly_admin` (
2
+ `id` BIGINT NOT NULL,
3
+ `nickname` VARCHAR(50) NOT NULL DEFAULT '',
4
+ `username` VARCHAR(30) NOT NULL DEFAULT '',
5
+ `password` VARCHAR(500) NOT NULL DEFAULT '',
6
+ `email` VARCHAR(100) NOT NULL DEFAULT '',
7
+ `phone` VARCHAR(20) NOT NULL DEFAULT '',
8
+ `avatar` VARCHAR(500) NOT NULL DEFAULT '',
9
+ `role_code` VARCHAR(50) NOT NULL DEFAULT '',
10
+ `role_type` VARCHAR(5) NOT NULL DEFAULT 'user',
11
+ `last_login_time` BIGINT NOT NULL DEFAULT 0,
12
+ `last_login_ip` VARCHAR(50) NOT NULL DEFAULT '',
13
+ `state` TINYINT NOT NULL DEFAULT 1,
14
+ `created_at` BIGINT NOT NULL DEFAULT 0,
15
+ `updated_at` BIGINT NOT NULL DEFAULT 0,
16
+ `deleted_at` BIGINT NULL DEFAULT NULL,
17
+ PRIMARY KEY (`id`)
18
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
19
+
20
+ CREATE TABLE IF NOT EXISTS `befly_api` (
21
+ `id` BIGINT NOT NULL,
22
+ `name` VARCHAR(100) NOT NULL DEFAULT '',
23
+ `auth` VARCHAR(200) NOT NULL DEFAULT '',
24
+ `path` VARCHAR(200) NOT NULL DEFAULT '',
25
+ `parent_path` VARCHAR(200) NOT NULL DEFAULT '',
26
+ `state` TINYINT NOT NULL DEFAULT 1,
27
+ `created_at` BIGINT NOT NULL DEFAULT 0,
28
+ `updated_at` BIGINT NOT NULL DEFAULT 0,
29
+ `deleted_at` BIGINT NULL DEFAULT NULL,
30
+ PRIMARY KEY (`id`)
31
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
32
+
33
+ CREATE TABLE IF NOT EXISTS `befly_dict` (
34
+ `id` BIGINT NOT NULL,
35
+ `type_code` VARCHAR(50) NOT NULL DEFAULT '',
36
+ `key` VARCHAR(50) NOT NULL DEFAULT '',
37
+ `label` VARCHAR(100) NOT NULL DEFAULT '',
38
+ `sort` INT NOT NULL DEFAULT 0,
39
+ `remark` VARCHAR(200) NOT NULL DEFAULT '',
40
+ `state` TINYINT NOT NULL DEFAULT 1,
41
+ `created_at` BIGINT NOT NULL DEFAULT 0,
42
+ `updated_at` BIGINT NOT NULL DEFAULT 0,
43
+ `deleted_at` BIGINT NULL DEFAULT NULL,
44
+ PRIMARY KEY (`id`)
45
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
46
+
47
+ CREATE TABLE IF NOT EXISTS `befly_dict_type` (
48
+ `id` BIGINT NOT NULL,
49
+ `code` VARCHAR(50) NOT NULL DEFAULT '',
50
+ `name` VARCHAR(50) NOT NULL DEFAULT '',
51
+ `description` VARCHAR(200) NOT NULL DEFAULT '',
52
+ `sort` INT NOT NULL DEFAULT 0,
53
+ `state` TINYINT NOT NULL DEFAULT 1,
54
+ `created_at` BIGINT NOT NULL DEFAULT 0,
55
+ `updated_at` BIGINT NOT NULL DEFAULT 0,
56
+ `deleted_at` BIGINT NULL DEFAULT NULL,
57
+ PRIMARY KEY (`id`)
58
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
59
+
60
+ CREATE TABLE IF NOT EXISTS `befly_email_log` (
61
+ `id` BIGINT NOT NULL,
62
+ `admin_id` BIGINT NOT NULL DEFAULT 0,
63
+ `username` VARCHAR(100) NOT NULL DEFAULT '',
64
+ `nickname` VARCHAR(100) NOT NULL DEFAULT '',
65
+ `to_email` VARCHAR(200) NOT NULL DEFAULT '',
66
+ `subject` VARCHAR(200) NOT NULL DEFAULT '',
67
+ `content` TEXT NULL,
68
+ `cc_email` VARCHAR(500) NOT NULL DEFAULT '',
69
+ `bcc_email` VARCHAR(500) NOT NULL DEFAULT '',
70
+ `send_time` BIGINT NOT NULL DEFAULT 0,
71
+ `send_result` TINYINT NOT NULL DEFAULT 0,
72
+ `message_id` VARCHAR(200) NOT NULL DEFAULT '',
73
+ `fail_reason` VARCHAR(500) NOT NULL DEFAULT '',
74
+ `state` TINYINT NOT NULL DEFAULT 1,
75
+ `created_at` BIGINT NOT NULL DEFAULT 0,
76
+ `updated_at` BIGINT NOT NULL DEFAULT 0,
77
+ `deleted_at` BIGINT NULL DEFAULT NULL,
78
+ PRIMARY KEY (`id`)
79
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
80
+
81
+ CREATE TABLE IF NOT EXISTS `befly_login_log` (
82
+ `id` BIGINT NOT NULL,
83
+ `admin_id` BIGINT NOT NULL DEFAULT 0,
84
+ `username` VARCHAR(50) NOT NULL DEFAULT '',
85
+ `nickname` VARCHAR(50) NOT NULL DEFAULT '',
86
+ `ip` VARCHAR(50) NOT NULL DEFAULT '',
87
+ `user_agent` VARCHAR(500) NOT NULL DEFAULT '',
88
+ `browser_name` VARCHAR(50) NOT NULL DEFAULT '',
89
+ `browser_version` VARCHAR(50) NOT NULL DEFAULT '',
90
+ `os_name` VARCHAR(50) NOT NULL DEFAULT '',
91
+ `os_version` VARCHAR(50) NOT NULL DEFAULT '',
92
+ `device_type` VARCHAR(20) NOT NULL DEFAULT '',
93
+ `device_vendor` VARCHAR(50) NOT NULL DEFAULT '',
94
+ `device_model` VARCHAR(50) NOT NULL DEFAULT '',
95
+ `engine_name` VARCHAR(50) NOT NULL DEFAULT '',
96
+ `cpu_architecture` VARCHAR(20) NOT NULL DEFAULT '',
97
+ `login_time` BIGINT NOT NULL DEFAULT 0,
98
+ `login_result` TINYINT NOT NULL DEFAULT 0,
99
+ `fail_reason` VARCHAR(200) NOT NULL DEFAULT '',
100
+ `state` TINYINT NOT NULL DEFAULT 1,
101
+ `created_at` BIGINT NOT NULL DEFAULT 0,
102
+ `updated_at` BIGINT NOT NULL DEFAULT 0,
103
+ `deleted_at` BIGINT NULL DEFAULT NULL,
104
+ PRIMARY KEY (`id`)
105
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
106
+
107
+ CREATE TABLE IF NOT EXISTS `befly_menu` (
108
+ `id` BIGINT NOT NULL,
109
+ `name` VARCHAR(50) NOT NULL DEFAULT '',
110
+ `path` VARCHAR(150) NOT NULL DEFAULT '',
111
+ `sort` INT NOT NULL DEFAULT 0,
112
+ `parent_path` VARCHAR(200) NOT NULL DEFAULT '',
113
+ `state` TINYINT NOT NULL DEFAULT 1,
114
+ `created_at` BIGINT NOT NULL DEFAULT 0,
115
+ `updated_at` BIGINT NOT NULL DEFAULT 0,
116
+ `deleted_at` BIGINT NULL DEFAULT NULL,
117
+ PRIMARY KEY (`id`)
118
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
119
+
120
+ CREATE TABLE IF NOT EXISTS `befly_operate_log` (
121
+ `id` BIGINT NOT NULL,
122
+ `admin_id` BIGINT NOT NULL DEFAULT 0,
123
+ `username` VARCHAR(50) NOT NULL DEFAULT '',
124
+ `nickname` VARCHAR(50) NOT NULL DEFAULT '',
125
+ `ip` VARCHAR(50) NOT NULL DEFAULT '',
126
+ `module` VARCHAR(50) NOT NULL DEFAULT '',
127
+ `action` VARCHAR(50) NOT NULL DEFAULT '',
128
+ `method` VARCHAR(10) NOT NULL DEFAULT '',
129
+ `path` VARCHAR(200) NOT NULL DEFAULT '',
130
+ `params` TEXT NULL,
131
+ `result` TINYINT NOT NULL DEFAULT 0,
132
+ `response` TEXT NULL,
133
+ `duration` BIGINT NOT NULL DEFAULT 0,
134
+ `operate_time` BIGINT NOT NULL DEFAULT 0,
135
+ `remark` VARCHAR(500) NOT NULL DEFAULT '',
136
+ `state` TINYINT NOT NULL DEFAULT 1,
137
+ `created_at` BIGINT NOT NULL DEFAULT 0,
138
+ `updated_at` BIGINT NOT NULL DEFAULT 0,
139
+ `deleted_at` BIGINT NULL DEFAULT NULL,
140
+ PRIMARY KEY (`id`)
141
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
142
+
143
+ CREATE TABLE IF NOT EXISTS `befly_role` (
144
+ `id` BIGINT NOT NULL,
145
+ `name` VARCHAR(50) NOT NULL DEFAULT '',
146
+ `code` VARCHAR(50) NOT NULL DEFAULT '',
147
+ `description` VARCHAR(200) NOT NULL DEFAULT '',
148
+ `menus` JSON NULL,
149
+ `apis` JSON NULL,
150
+ `sort` INT NOT NULL DEFAULT 0,
151
+ `state` TINYINT NOT NULL DEFAULT 1,
152
+ `created_at` BIGINT NOT NULL DEFAULT 0,
153
+ `updated_at` BIGINT NOT NULL DEFAULT 0,
154
+ `deleted_at` BIGINT NULL DEFAULT NULL,
155
+ PRIMARY KEY (`id`)
156
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
157
+
158
+ CREATE TABLE IF NOT EXISTS `befly_sys_config` (
159
+ `id` BIGINT NOT NULL,
160
+ `name` VARCHAR(50) NOT NULL DEFAULT '',
161
+ `code` VARCHAR(100) NOT NULL DEFAULT '',
162
+ `value` TEXT NULL,
163
+ `value_type` VARCHAR(20) NOT NULL DEFAULT '',
164
+ `group` VARCHAR(50) NOT NULL DEFAULT '',
165
+ `sort` INT NOT NULL DEFAULT 0,
166
+ `is_system` TINYINT NOT NULL DEFAULT 0,
167
+ `description` VARCHAR(500) NOT NULL DEFAULT '',
168
+ `state` TINYINT NOT NULL DEFAULT 1,
169
+ `created_at` BIGINT NOT NULL DEFAULT 0,
170
+ `updated_at` BIGINT NOT NULL DEFAULT 0,
171
+ `deleted_at` BIGINT NULL DEFAULT NULL,
172
+ PRIMARY KEY (`id`)
173
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
package/sync/cache.js CHANGED
@@ -1,13 +1,36 @@
1
1
  export async function syncCache(ctx) {
2
- // 1) 缓存接口列表
3
- await ctx.cache.cacheApis();
2
+ const tasks = [
3
+ { name: "cacheApis", run: () => ctx.cache.cacheApis() },
4
+ { name: "cacheMenus", run: () => ctx.cache.cacheMenus() },
5
+ { name: "cacheRoleApis", run: () => ctx.cache.cacheRoleApis() },
6
+ { name: "cacheRoleMenus", run: () => ctx.cache.cacheRoleMenus() }
7
+ ];
4
8
 
5
- // 2) 缓存菜单列表
6
- await ctx.cache.cacheMenus();
9
+ const failures = [];
7
10
 
8
- // 3) 重建角色权限缓存(严格模式下要求 role.apis 必须为 pathname 字符串数组)
9
- await ctx.cache.cacheRoleApis();
11
+ for (const task of tasks) {
12
+ try {
13
+ await task.run();
14
+ } catch (error) {
15
+ failures.push({
16
+ step: task.name,
17
+ message: String(error?.message || error),
18
+ error: error
19
+ });
20
+ }
21
+ }
10
22
 
11
- // 4) 重建角色菜单权限缓存(role.menus menu.path 字符串数组)
12
- await ctx.cache.cacheRoleMenus();
23
+ if (failures.length > 0) {
24
+ throw new Error("缓存同步失败", {
25
+ cause: failures[0].error,
26
+ code: "runtime",
27
+ subsystem: "sync",
28
+ operation: "syncCache",
29
+ failedSteps: failures.map((item) => item.step),
30
+ failures: failures.map((item) => ({
31
+ step: item.step,
32
+ message: item.message
33
+ }))
34
+ });
35
+ }
13
36
  }
package/sql/admin.sql DELETED
@@ -1,18 +0,0 @@
1
- CREATE TABLE IF NOT EXISTS `admin` (
2
- `id` BIGINT NOT NULL,
3
- `nickname` VARCHAR(50) NOT NULL DEFAULT '',
4
- `username` VARCHAR(30) NOT NULL DEFAULT '',
5
- `password` VARCHAR(500) NOT NULL DEFAULT '',
6
- `email` VARCHAR(100) NOT NULL DEFAULT '',
7
- `phone` VARCHAR(20) NOT NULL DEFAULT '',
8
- `avatar` VARCHAR(500) NOT NULL DEFAULT '',
9
- `role_code` VARCHAR(50) NOT NULL DEFAULT '',
10
- `role_type` VARCHAR(5) NOT NULL DEFAULT 'user',
11
- `last_login_time` BIGINT NOT NULL DEFAULT 0,
12
- `last_login_ip` VARCHAR(50) NOT NULL DEFAULT '',
13
- `state` TINYINT NOT NULL DEFAULT 1,
14
- `created_at` BIGINT NOT NULL DEFAULT 0,
15
- `updated_at` BIGINT NOT NULL DEFAULT 0,
16
- `deleted_at` BIGINT NULL DEFAULT NULL,
17
- PRIMARY KEY (`id`)
18
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
package/sql/api.sql DELETED
@@ -1,12 +0,0 @@
1
- CREATE TABLE IF NOT EXISTS `api` (
2
- `id` BIGINT NOT NULL,
3
- `name` VARCHAR(100) NOT NULL DEFAULT '',
4
- `auth` VARCHAR(200) NOT NULL DEFAULT '',
5
- `path` VARCHAR(200) NOT NULL DEFAULT '',
6
- `parent_path` VARCHAR(200) NOT NULL DEFAULT '',
7
- `state` TINYINT NOT NULL DEFAULT 1,
8
- `created_at` BIGINT NOT NULL DEFAULT 0,
9
- `updated_at` BIGINT NOT NULL DEFAULT 0,
10
- `deleted_at` BIGINT NULL DEFAULT NULL,
11
- PRIMARY KEY (`id`)
12
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
package/sql/dict.sql DELETED
@@ -1,13 +0,0 @@
1
- CREATE TABLE IF NOT EXISTS `dict` (
2
- `id` BIGINT NOT NULL,
3
- `type_code` VARCHAR(50) NOT NULL DEFAULT '',
4
- `key` VARCHAR(50) NOT NULL DEFAULT '',
5
- `label` VARCHAR(100) NOT NULL DEFAULT '',
6
- `sort` INT NOT NULL DEFAULT 0,
7
- `remark` VARCHAR(200) NOT NULL DEFAULT '',
8
- `state` TINYINT NOT NULL DEFAULT 1,
9
- `created_at` BIGINT NOT NULL DEFAULT 0,
10
- `updated_at` BIGINT NOT NULL DEFAULT 0,
11
- `deleted_at` BIGINT NULL DEFAULT NULL,
12
- PRIMARY KEY (`id`)
13
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
package/sql/dictType.sql DELETED
@@ -1,12 +0,0 @@
1
- CREATE TABLE IF NOT EXISTS `dict_type` (
2
- `id` BIGINT NOT NULL,
3
- `code` VARCHAR(50) NOT NULL DEFAULT '',
4
- `name` VARCHAR(50) NOT NULL DEFAULT '',
5
- `description` VARCHAR(200) NOT NULL DEFAULT '',
6
- `sort` INT NOT NULL DEFAULT 0,
7
- `state` TINYINT NOT NULL DEFAULT 1,
8
- `created_at` BIGINT NOT NULL DEFAULT 0,
9
- `updated_at` BIGINT NOT NULL DEFAULT 0,
10
- `deleted_at` BIGINT NULL DEFAULT NULL,
11
- PRIMARY KEY (`id`)
12
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
package/sql/emailLog.sql DELETED
@@ -1,20 +0,0 @@
1
- CREATE TABLE IF NOT EXISTS `email_log` (
2
- `id` BIGINT NOT NULL,
3
- `admin_id` BIGINT NOT NULL DEFAULT 0,
4
- `username` VARCHAR(100) NOT NULL DEFAULT '',
5
- `nickname` VARCHAR(100) NOT NULL DEFAULT '',
6
- `to_email` VARCHAR(200) NOT NULL DEFAULT '',
7
- `subject` VARCHAR(200) NOT NULL DEFAULT '',
8
- `content` TEXT NULL,
9
- `cc_email` VARCHAR(500) NOT NULL DEFAULT '',
10
- `bcc_email` VARCHAR(500) NOT NULL DEFAULT '',
11
- `send_time` BIGINT NOT NULL DEFAULT 0,
12
- `send_result` TINYINT NOT NULL DEFAULT 0,
13
- `message_id` VARCHAR(200) NOT NULL DEFAULT '',
14
- `fail_reason` VARCHAR(500) NOT NULL DEFAULT '',
15
- `state` TINYINT NOT NULL DEFAULT 1,
16
- `created_at` BIGINT NOT NULL DEFAULT 0,
17
- `updated_at` BIGINT NOT NULL DEFAULT 0,
18
- `deleted_at` BIGINT NULL DEFAULT NULL,
19
- PRIMARY KEY (`id`)
20
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
package/sql/loginLog.sql DELETED
@@ -1,25 +0,0 @@
1
- CREATE TABLE IF NOT EXISTS `login_log` (
2
- `id` BIGINT NOT NULL,
3
- `admin_id` BIGINT NOT NULL DEFAULT 0,
4
- `username` VARCHAR(50) NOT NULL DEFAULT '',
5
- `nickname` VARCHAR(50) NOT NULL DEFAULT '',
6
- `ip` VARCHAR(50) NOT NULL DEFAULT '',
7
- `user_agent` VARCHAR(500) NOT NULL DEFAULT '',
8
- `browser_name` VARCHAR(50) NOT NULL DEFAULT '',
9
- `browser_version` VARCHAR(50) NOT NULL DEFAULT '',
10
- `os_name` VARCHAR(50) NOT NULL DEFAULT '',
11
- `os_version` VARCHAR(50) NOT NULL DEFAULT '',
12
- `device_type` VARCHAR(20) NOT NULL DEFAULT '',
13
- `device_vendor` VARCHAR(50) NOT NULL DEFAULT '',
14
- `device_model` VARCHAR(50) NOT NULL DEFAULT '',
15
- `engine_name` VARCHAR(50) NOT NULL DEFAULT '',
16
- `cpu_architecture` VARCHAR(20) NOT NULL DEFAULT '',
17
- `login_time` BIGINT NOT NULL DEFAULT 0,
18
- `login_result` TINYINT NOT NULL DEFAULT 0,
19
- `fail_reason` VARCHAR(200) NOT NULL DEFAULT '',
20
- `state` TINYINT NOT NULL DEFAULT 1,
21
- `created_at` BIGINT NOT NULL DEFAULT 0,
22
- `updated_at` BIGINT NOT NULL DEFAULT 0,
23
- `deleted_at` BIGINT NULL DEFAULT NULL,
24
- PRIMARY KEY (`id`)
25
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
package/sql/menu.sql DELETED
@@ -1,12 +0,0 @@
1
- CREATE TABLE IF NOT EXISTS `menu` (
2
- `id` BIGINT NOT NULL,
3
- `name` VARCHAR(50) NOT NULL DEFAULT '',
4
- `path` VARCHAR(150) NOT NULL DEFAULT '',
5
- `sort` INT NOT NULL DEFAULT 0,
6
- `parent_path` VARCHAR(200) NOT NULL DEFAULT '',
7
- `state` TINYINT NOT NULL DEFAULT 1,
8
- `created_at` BIGINT NOT NULL DEFAULT 0,
9
- `updated_at` BIGINT NOT NULL DEFAULT 0,
10
- `deleted_at` BIGINT NULL DEFAULT NULL,
11
- PRIMARY KEY (`id`)
12
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
@@ -1,22 +0,0 @@
1
- CREATE TABLE IF NOT EXISTS `operate_log` (
2
- `id` BIGINT NOT NULL,
3
- `admin_id` BIGINT NOT NULL DEFAULT 0,
4
- `username` VARCHAR(50) NOT NULL DEFAULT '',
5
- `nickname` VARCHAR(50) NOT NULL DEFAULT '',
6
- `ip` VARCHAR(50) NOT NULL DEFAULT '',
7
- `module` VARCHAR(50) NOT NULL DEFAULT '',
8
- `action` VARCHAR(50) NOT NULL DEFAULT '',
9
- `method` VARCHAR(10) NOT NULL DEFAULT '',
10
- `path` VARCHAR(200) NOT NULL DEFAULT '',
11
- `params` TEXT NULL,
12
- `result` TINYINT NOT NULL DEFAULT 0,
13
- `response` TEXT NULL,
14
- `duration` BIGINT NOT NULL DEFAULT 0,
15
- `operate_time` BIGINT NOT NULL DEFAULT 0,
16
- `remark` VARCHAR(500) NOT NULL DEFAULT '',
17
- `state` TINYINT NOT NULL DEFAULT 1,
18
- `created_at` BIGINT NOT NULL DEFAULT 0,
19
- `updated_at` BIGINT NOT NULL DEFAULT 0,
20
- `deleted_at` BIGINT NULL DEFAULT NULL,
21
- PRIMARY KEY (`id`)
22
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
package/sql/role.sql DELETED
@@ -1,14 +0,0 @@
1
- CREATE TABLE IF NOT EXISTS `role` (
2
- `id` BIGINT NOT NULL,
3
- `name` VARCHAR(50) NOT NULL DEFAULT '',
4
- `code` VARCHAR(50) NOT NULL DEFAULT '',
5
- `description` VARCHAR(200) NOT NULL DEFAULT '',
6
- `menus` JSON NULL,
7
- `apis` JSON NULL,
8
- `sort` INT NOT NULL DEFAULT 0,
9
- `state` TINYINT NOT NULL DEFAULT 1,
10
- `created_at` BIGINT NOT NULL DEFAULT 0,
11
- `updated_at` BIGINT NOT NULL DEFAULT 0,
12
- `deleted_at` BIGINT NULL DEFAULT NULL,
13
- PRIMARY KEY (`id`)
14
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
package/sql/sysConfig.sql DELETED
@@ -1,16 +0,0 @@
1
- CREATE TABLE IF NOT EXISTS `sys_config` (
2
- `id` BIGINT NOT NULL,
3
- `name` VARCHAR(50) NOT NULL DEFAULT '',
4
- `code` VARCHAR(100) NOT NULL DEFAULT '',
5
- `value` TEXT NULL,
6
- `value_type` VARCHAR(20) NOT NULL DEFAULT '',
7
- `group` VARCHAR(50) NOT NULL DEFAULT '',
8
- `sort` INT NOT NULL DEFAULT 0,
9
- `is_system` TINYINT NOT NULL DEFAULT 0,
10
- `description` VARCHAR(500) NOT NULL DEFAULT '',
11
- `state` TINYINT NOT NULL DEFAULT 1,
12
- `created_at` BIGINT NOT NULL DEFAULT 0,
13
- `updated_at` BIGINT NOT NULL DEFAULT 0,
14
- `deleted_at` BIGINT NULL DEFAULT NULL,
15
- PRIMARY KEY (`id`)
16
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;