befly 2.0.2 → 2.0.4

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.
Files changed (3) hide show
  1. package/main.js +2 -2
  2. package/package.json +2 -2
  3. package/utils/util.js +20 -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.2",
3
+ "version": "2.0.4",
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": "1b484a191c11bb664c35214135ae2bb461f2d851"
54
+ "gitHead": "599e77ab68a5bd46b1be84a6f0914ee4e45402ba"
55
55
  }
package/utils/util.js CHANGED
@@ -171,3 +171,23 @@ 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
+ const fieldsArray = excludeFields
181
+ .split(',')
182
+ .map((field) => field.trim())
183
+ .filter((field) => field.length > 0);
184
+
185
+ // 创建新对象,只包含不在排除列表中的字段
186
+ const filtered = {};
187
+ for (const [key, value] of Object.entries(body)) {
188
+ if (!fieldsArray.includes(key)) {
189
+ filtered[key] = value;
190
+ }
191
+ }
192
+ return filtered;
193
+ };