befly 2.0.2 → 2.0.3
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/main.js +2 -2
- package/package.json +2 -2
- package/utils/util.js +22 -0
package/main.js
CHANGED
|
@@ -8,7 +8,7 @@ import { Jwt } from './utils/jwt.js';
|
|
|
8
8
|
import { validator } from './utils/validate.js';
|
|
9
9
|
import { Crypto2 } from './utils/crypto.js';
|
|
10
10
|
import { Xml } from './libs/xml.js';
|
|
11
|
-
import { isEmptyObject, isType, pickFields, sortPlugins, RYes, RNo, filename2, dirname2 } from './utils/util.js';
|
|
11
|
+
import { isEmptyObject, isType, pickFields, sortPlugins, RYes, RNo, filename2, dirname2, filterLogFields } from './utils/util.js';
|
|
12
12
|
|
|
13
13
|
const setCorsOptions = (req) => {
|
|
14
14
|
return {
|
|
@@ -442,7 +442,7 @@ class Befly {
|
|
|
442
442
|
请求路径: apiPath,
|
|
443
443
|
请求方法: req.method,
|
|
444
444
|
用户信息: ctx.user,
|
|
445
|
-
请求体: ctx.body
|
|
445
|
+
请求体: filterLogFields(ctx.body, Env.LOG_EXCLUDE_FIELDS)
|
|
446
446
|
});
|
|
447
447
|
|
|
448
448
|
// 登录验证 auth 有3种值 分别为 true、false、['admin', 'user']
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "Buma - 为 Bun 专属打造的 API 接口框架核心引擎",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"README.md",
|
|
52
52
|
"vitest.config.js"
|
|
53
53
|
],
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "1cdaa1899462003fb95f4142cb6758c6ed986754"
|
|
55
55
|
}
|
package/utils/util.js
CHANGED
|
@@ -171,3 +171,25 @@ export const filename2 = (importMetaUrl) => {
|
|
|
171
171
|
export const dirname2 = (importMetaUrl) => {
|
|
172
172
|
return path.dirname(fileURLToPath(importMetaUrl));
|
|
173
173
|
};
|
|
174
|
+
|
|
175
|
+
// 过滤日志字段的函数
|
|
176
|
+
export const filterLogFields = (body, excludeFields = []) => {
|
|
177
|
+
if (!body || typeof body !== 'object') return body;
|
|
178
|
+
|
|
179
|
+
// 如果是字符串,按逗号分割并清理空格
|
|
180
|
+
let fieldsArray = excludeFields;
|
|
181
|
+
if (typeof excludeFields === 'string') {
|
|
182
|
+
fieldsArray = excludeFields
|
|
183
|
+
.split(',')
|
|
184
|
+
.map((field) => field.trim())
|
|
185
|
+
.filter((field) => field.length > 0);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const filtered = { ...body };
|
|
189
|
+
fieldsArray.forEach((field) => {
|
|
190
|
+
if (field in filtered) {
|
|
191
|
+
delete filtered[field];
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return filtered;
|
|
195
|
+
};
|