befly 3.18.14 → 3.18.16
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/lib/dbHelper/dataOps.js +2 -2
- package/lib/dbHelper/validate.js +3 -3
- package/package.json +2 -2
- package/sync/dev.js +57 -2
package/lib/dbHelper/dataOps.js
CHANGED
|
@@ -96,8 +96,8 @@ export const dataOpsMethods = {
|
|
|
96
96
|
},
|
|
97
97
|
|
|
98
98
|
async getAll(options) {
|
|
99
|
-
const MAX_LIMIT =
|
|
100
|
-
const WARNING_LIMIT =
|
|
99
|
+
const MAX_LIMIT = 100000;
|
|
100
|
+
const WARNING_LIMIT = 10000;
|
|
101
101
|
const prepareOptions = this.buildQueryOptions(options, { page: 1, limit: 10 });
|
|
102
102
|
const prepared = await this.prepareQueryOptions(prepareOptions, "getAll.options");
|
|
103
103
|
|
package/lib/dbHelper/validate.js
CHANGED
|
@@ -241,14 +241,14 @@ export function validateSafeFieldName(field) {
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
export function validatePageLimitRange(prepared, rawTable) {
|
|
244
|
-
if (prepared.page < 1 || prepared.page >
|
|
244
|
+
if (prepared.page < 1 || prepared.page > 100000) {
|
|
245
245
|
throw new Error(`页码必须在 1 到 10000 之间 (table: ${rawTable}, page: ${prepared.page}, limit: ${prepared.limit})`, {
|
|
246
246
|
cause: null,
|
|
247
247
|
code: "validation"
|
|
248
248
|
});
|
|
249
249
|
}
|
|
250
|
-
if (prepared.limit < 1 || prepared.limit >
|
|
251
|
-
throw new Error(`每页数量必须在 1 到
|
|
250
|
+
if (prepared.limit < 1 || prepared.limit > 100000) {
|
|
251
|
+
throw new Error(`每页数量必须在 1 到 100000 之间 (table: ${rawTable}, page: ${prepared.page}, limit: ${prepared.limit})`, {
|
|
252
252
|
cause: null,
|
|
253
253
|
code: "validation"
|
|
254
254
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.18.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.18.16",
|
|
4
|
+
"gitHead": "98aa4ea2914a476dfa3c8b23099a238134ca96e6",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
|
|
7
7
|
"keywords": [
|
package/sync/dev.js
CHANGED
|
@@ -11,7 +11,7 @@ export async function syncDev(ctx) {
|
|
|
11
11
|
|
|
12
12
|
const allApis = await ctx.mysql.getAll({
|
|
13
13
|
table: "beflyApi",
|
|
14
|
-
fields: ["path"],
|
|
14
|
+
fields: ["path", "auth"],
|
|
15
15
|
where: { state$gte: 0 },
|
|
16
16
|
orderBy: ["id#ASC"]
|
|
17
17
|
});
|
|
@@ -134,6 +134,60 @@ export async function syncDev(ctx) {
|
|
|
134
134
|
}
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
+
const defaultApis = [];
|
|
138
|
+
for (const api of allApis.data.lists) {
|
|
139
|
+
const apiPath = api.path;
|
|
140
|
+
if (typeof apiPath !== "string" || apiPath.length === 0) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const auth = api.auth;
|
|
145
|
+
if (auth === "否" || auth === false) {
|
|
146
|
+
defaultApis.push(apiPath);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 与 syncApi 的存储语义保持一致:
|
|
151
|
+
// - true -> "是"
|
|
152
|
+
// - false -> "否"
|
|
153
|
+
// - string[] -> "a,b,c"
|
|
154
|
+
if (typeof auth === "string" && auth !== "是") {
|
|
155
|
+
const roleCodes = auth.split(",");
|
|
156
|
+
for (const roleCode of roleCodes) {
|
|
157
|
+
if (roleCode.trim() === roleConfig.code) {
|
|
158
|
+
defaultApis.push(apiPath);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const mergedApis = [];
|
|
166
|
+
const mergedApiSet = new Set();
|
|
167
|
+
|
|
168
|
+
if (Array.isArray(existingRole.data?.apis)) {
|
|
169
|
+
for (const apiPath of existingRole.data.apis) {
|
|
170
|
+
if (typeof apiPath !== "string") {
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const value = apiPath.trim();
|
|
174
|
+
if (value.length === 0 || mergedApiSet.has(value)) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
mergedApiSet.add(value);
|
|
178
|
+
mergedApis.push(value);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
for (const apiPath of defaultApis) {
|
|
183
|
+
const value = apiPath.trim();
|
|
184
|
+
if (value.length === 0 || mergedApiSet.has(value)) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
mergedApiSet.add(value);
|
|
188
|
+
mergedApis.push(value);
|
|
189
|
+
}
|
|
190
|
+
|
|
137
191
|
if (existingRole.data?.id) {
|
|
138
192
|
// 角色存在则强制更新(不做差异判断)
|
|
139
193
|
await ctx.mysql.updData({
|
|
@@ -142,6 +196,7 @@ export async function syncDev(ctx) {
|
|
|
142
196
|
data: {
|
|
143
197
|
name: roleConfig.name,
|
|
144
198
|
description: roleConfig.description,
|
|
199
|
+
apis: mergedApis,
|
|
145
200
|
sort: roleConfig.sort,
|
|
146
201
|
state: 1
|
|
147
202
|
}
|
|
@@ -154,7 +209,7 @@ export async function syncDev(ctx) {
|
|
|
154
209
|
name: roleConfig.name,
|
|
155
210
|
description: roleConfig.description,
|
|
156
211
|
menus: [],
|
|
157
|
-
apis:
|
|
212
|
+
apis: mergedApis,
|
|
158
213
|
sort: roleConfig.sort
|
|
159
214
|
}
|
|
160
215
|
});
|