chanjs 1.2.1 → 1.2.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/core/lib/controller.js +27 -0
- package/core/lib/task.js +1 -1
- package/index.js +4 -1
- package/package.json +1 -1
@@ -0,0 +1,27 @@
|
|
1
|
+
export default class Controller {
|
2
|
+
constructor() {
|
3
|
+
}
|
4
|
+
|
5
|
+
parseJsonFields(obj) {
|
6
|
+
const result = {};
|
7
|
+
for (const key in obj) {
|
8
|
+
if (!obj.hasOwnProperty(key)) continue;
|
9
|
+
const value = obj[key];
|
10
|
+
// 如果是字符串,并且看起来像 JSON(以 { 或 [ 开头)
|
11
|
+
if (typeof value === 'string' && (value.startsWith('{') || value.startsWith('['))) {
|
12
|
+
try {
|
13
|
+
result[key] = JSON.parse(value);
|
14
|
+
} catch (e) {
|
15
|
+
console.warn(`JSON parse failed for field: ${key}`, e);
|
16
|
+
result[key] = value; // 保留原始值
|
17
|
+
}
|
18
|
+
} else {
|
19
|
+
result[key] = value;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
return result;
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
}
|
package/core/lib/task.js
CHANGED
package/index.js
CHANGED
@@ -5,6 +5,7 @@ import cors from "cors";
|
|
5
5
|
import { pathToFileURL } from 'url'; // 新增顶部导入
|
6
6
|
import config from "./core/config.js";
|
7
7
|
import * as helper from "./core/helper.js";
|
8
|
+
import Controller from "./core/lib/controller.js";
|
8
9
|
import Service from "./core/lib/service.js";
|
9
10
|
import Cache from './core/lib/cache.js';
|
10
11
|
import Task from "./core/lib/task.js";
|
@@ -14,10 +15,12 @@ const {bindClass, createKnex, loadWebToEnd} = helper;
|
|
14
15
|
* @description 基于express封装的mvc框架,遵循约定优于配置原则
|
15
16
|
*/
|
16
17
|
class Chan {
|
17
|
-
static helper = helper;
|
18
|
+
static helper = {...helper};
|
18
19
|
static modules = {};
|
19
20
|
static plugins = {};
|
20
21
|
static config = config;
|
22
|
+
static Controller = Controller;
|
23
|
+
static Service = Service;
|
21
24
|
static Cache = Cache;
|
22
25
|
static Task = Task;
|
23
26
|
constructor() {
|