chanjs 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/index.js CHANGED
@@ -29,13 +29,10 @@ class Chan {
29
29
  getPackage,
30
30
  loadController,
31
31
  db,
32
- z, //验证器
32
+ z,
33
33
  validator,
34
- }; //工具类
34
+ };
35
35
  static config = {}; //配置
36
- //数据库
37
-
38
- // static Router = express.Router; //路由
39
36
  static Service = Service; //服务
40
37
  static Controller = Controller; //控制器
41
38
  static extend = {}; //组件扩展
@@ -71,7 +68,7 @@ class Chan {
71
68
  appName,
72
69
  version,
73
70
  cookieKey,
74
- JSON_LIMIT,
71
+ BODY_LIMIT,
75
72
  statics,
76
73
  logger,
77
74
  cors,
@@ -80,7 +77,7 @@ class Chan {
80
77
  log(this.app, logger);
81
78
  setFavicon(this.app);
82
79
  setCookie(this.app, cookieKey);
83
- setBody(this.app, JSON_LIMIT);
80
+ setBody(this.app, BODY_LIMIT);
84
81
  setTemplate(this.app, { views, env });
85
82
  setStatic(this.app, statics);
86
83
  Cors(this.app, cors);
@@ -1,6 +1,5 @@
1
1
  import express from "express";
2
2
 
3
-
4
3
  let setBody = function (app, JSON_LIMIT) {
5
4
  app.use(express.json({ limit: JSON_LIMIT }));
6
5
  app.use(express.urlencoded({ extended: false }));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "chanjs",
4
- "version": "2.0.2",
4
+ "version": "2.0.3",
5
5
  "description": "chanjs基于express5 纯js研发的轻量级mvc框架。",
6
6
  "main": "index.js",
7
7
  "module": "index.js",
package/utils/response.js CHANGED
@@ -1,26 +1,20 @@
1
- export let success = (data) => {
2
- return {
3
- success: true,
4
- msg: "�����ɹ�",
5
- code: 200,
6
- data,
7
- };
8
- };
9
-
10
- export let fail = (data, code = 201) => {
11
- return {
12
- success: false,
13
- msg: "����ʧ��",
14
- code,
15
- data,
16
- };
17
- };
18
-
19
- export let err = (data = {}, code = 500) => {
20
- return {
21
- success: false,
22
- msg: "ϵͳ�쳣",
23
- code,
24
- data,
25
- };
26
- };
1
+ export function parseJsonFields(obj) {
2
+ const result = {};
3
+ for (const key in obj) {
4
+ if (!obj.hasOwnProperty(key)) continue;
5
+ const value = obj[key];
6
+ // 如果是字符串,并且看起来像 JSON(以 { 或 [ 开头)
7
+ if (typeof value === 'string' && (value.startsWith('{') || value.startsWith('['))) {
8
+ try {
9
+ result[key] = JSON.parse(value);
10
+ } catch (e) {
11
+ console.warn(`JSON parse failed for field: ${key}`, e);
12
+ result[key] = value; // 保留原始值
13
+ }
14
+ } else {
15
+ result[key] = value;
16
+ }
17
+ }
18
+
19
+ return result;
20
+ }