mm_os 2.9.0 → 2.9.2
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/com/api/drive.js +9 -89
- package/core/com/api/index.js +3 -31
- package/core/com/cmd/drive.js +10 -1
- package/core/com/cmd/index.js +15 -1
- package/core/com/component/drive.js +1 -1
- package/core/com/component/index.js +16 -12
- package/core/com/db/drive.js +1 -1
- package/core/com/db/index.js +15 -17
- package/core/com/event/drive.js +3 -1
- package/core/com/event/index.js +74 -61
- package/core/com/eventer/com.js +2 -2
- package/core/com/middleware/com.js +41 -16
- package/core/com/mqtt/drive.js +4 -3
- package/core/com/mqtt/index.js +8 -6
- package/core/com/nav/drive.js +1 -19
- package/core/com/nav/index.js +1 -1
- package/core/com/param/drive.js +1 -1
- package/core/com/param/index.js +1 -27
- package/core/com/plugin/drive.js +18 -19
- package/core/com/plugin/index.js +16 -21
- package/core/com/plugin/script.js +109 -58
- package/core/com/rpc/com.json +4 -0
- package/core/com/rpc/drive.js +160 -0
- package/core/com/rpc/index.js +87 -0
- package/core/com/socket/drive.js +0 -1
- package/core/com/socket/index.js +5 -15
- package/core/com/sql/drive.js +7 -7
- package/core/com/sql/index.js +4 -31
- package/core/com/static/drive.js +15 -52
- package/core/com/static/index.js +15 -7
- package/core/com/task/index.js +14 -36
- package/core/com/tpl/com.js +2 -2
- package/index.js +9 -8
- package/middleware/cors/index.js +1 -1
- package/middleware/cors/middleware.json +3 -1
- package/middleware/log/index.js +1 -1
- package/middleware/log/middleware.json +1 -1
- package/middleware/mqtt_base/index.js +1 -1
- package/middleware/mqtt_base/middleware.json +3 -1
- package/middleware/waf/index.js +1 -1
- package/middleware/waf/middleware.json +1 -1
- package/middleware/waf_ip/index.js +1 -1
- package/middleware/waf_ip/middleware.json +1 -1
- package/middleware/web_after/index.js +20 -0
- package/middleware/web_after/middleware.json +9 -0
- package/middleware/web_base/index.js +1 -1
- package/middleware/web_base/middleware.json +1 -1
- package/middleware/web_before/index.js +27 -0
- package/middleware/web_before/middleware.json +9 -0
- package/middleware/web_check/index.js +22 -0
- package/middleware/web_check/middleware.json +9 -0
- package/middleware/web_main/index.js +22 -0
- package/middleware/web_main/middleware.json +9 -0
- package/middleware/web_proxy/index.js +1 -1
- package/middleware/web_proxy/middleware.json +1 -1
- package/middleware/web_render/index.js +81 -0
- package/middleware/web_render/middleware.json +9 -0
- package/middleware/web_socket/index.js +1 -1
- package/middleware/web_socket/middleware.json +1 -1
- package/middleware/web_static/index.js +1 -1
- package/middleware/web_static/middleware.json +1 -1
- package/package.json +2 -2
- package/demo/index.js +0 -28
- package/middleware/web_event/index.js +0 -413
- package/middleware/web_event/middleware.json +0 -10
- package/middleware/web_router/index.js +0 -33
- package/middleware/web_router/middleware.json +0 -10
- /package/core/com/{api → rpc}/rpc.js +0 -0
|
@@ -7,14 +7,20 @@ class Middleware {
|
|
|
7
7
|
// 中间件列表
|
|
8
8
|
this.list = [];
|
|
9
9
|
|
|
10
|
-
this.config =
|
|
10
|
+
this.config = {
|
|
11
11
|
path: "./middleware".fullname($.runPath),
|
|
12
12
|
file: "middleware.json",
|
|
13
13
|
mode: "web"
|
|
14
|
-
}
|
|
14
|
+
};
|
|
15
|
+
this.init(config);
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
Middleware.prototype.init = function(config) {
|
|
20
|
+
if (config) {
|
|
21
|
+
Object.assign(this.config, config);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
18
24
|
|
|
19
25
|
/**
|
|
20
26
|
* 新建脚本
|
|
@@ -58,8 +64,7 @@ Middleware.prototype.new_config = function(file) {
|
|
|
58
64
|
* 加载配置
|
|
59
65
|
* @param {String} file 配置文件路径
|
|
60
66
|
*/
|
|
61
|
-
Middleware.prototype.
|
|
62
|
-
var f = this.config.file;
|
|
67
|
+
Middleware.prototype.load_item = function(file) {
|
|
63
68
|
var config = file.loadJson();
|
|
64
69
|
if (config) {
|
|
65
70
|
var cg = this.list.getObj({
|
|
@@ -69,7 +74,7 @@ Middleware.prototype.load = function(file) {
|
|
|
69
74
|
$.push(cg, config, true);
|
|
70
75
|
} else {
|
|
71
76
|
cg = {
|
|
72
|
-
func_file: file.replace(
|
|
77
|
+
func_file: file.replace(this.config.file, 'index.js')
|
|
73
78
|
}
|
|
74
79
|
$.push(cg, config, true);
|
|
75
80
|
this.list.push(cg);
|
|
@@ -87,14 +92,15 @@ Middleware.prototype.load = function(file) {
|
|
|
87
92
|
* 遍历加载配置
|
|
88
93
|
* @param {Object} path
|
|
89
94
|
*/
|
|
90
|
-
Middleware.prototype.
|
|
95
|
+
Middleware.prototype.update_config_all = function(path, accurate) {
|
|
91
96
|
if (path.hasDir()) {
|
|
92
|
-
var dirs = $.dir.getAll(path);
|
|
97
|
+
var dirs = $.dir.getAll(path);
|
|
93
98
|
// 遍历目录路径
|
|
94
99
|
var file = this.config.file;
|
|
95
|
-
dirs.
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
for (var i = 0; i < dirs.length; i++) {
|
|
101
|
+
var d = dirs[i];
|
|
102
|
+
this.load_item(d + file);
|
|
103
|
+
}
|
|
98
104
|
}
|
|
99
105
|
};
|
|
100
106
|
|
|
@@ -105,24 +111,43 @@ Middleware.prototype.sort = function() {
|
|
|
105
111
|
return this.list.sortBy('asc', 'sort');
|
|
106
112
|
};
|
|
107
113
|
|
|
114
|
+
/**
|
|
115
|
+
* 清除接口缓存
|
|
116
|
+
*/
|
|
117
|
+
Middleware.prototype.clear = function() {
|
|
118
|
+
this.list = [];
|
|
119
|
+
};
|
|
120
|
+
|
|
108
121
|
/**
|
|
109
122
|
* 遍历加载配置
|
|
110
123
|
*/
|
|
111
|
-
Middleware.prototype.
|
|
112
|
-
|
|
124
|
+
Middleware.prototype.update_config = function(path, accurate = true, clear = true) {
|
|
125
|
+
if (clear) {
|
|
126
|
+
this.clear();
|
|
127
|
+
}
|
|
128
|
+
this.update_config_all("../../../middleware/".fullname(__dirname));
|
|
113
129
|
if (path) {
|
|
114
|
-
this.
|
|
130
|
+
this.update_config_all(path);
|
|
115
131
|
}
|
|
116
|
-
this.
|
|
132
|
+
this.update_config_all(this.config.path);
|
|
117
133
|
var p = "./middleware".fullname($.runPath);
|
|
118
134
|
if (this.config.path !== p) {
|
|
119
|
-
this.
|
|
135
|
+
this.update_config_all(p);
|
|
120
136
|
}
|
|
121
137
|
this.sort();
|
|
122
138
|
};
|
|
123
139
|
|
|
140
|
+
/**
|
|
141
|
+
* 更新
|
|
142
|
+
* @param {String} dir 检索的路径
|
|
143
|
+
* @param {Boolean} loadJS 是否加载JS
|
|
144
|
+
*/
|
|
145
|
+
Middleware.prototype.update = function(dir, accurate = true, loadJS = true, clear = true) {
|
|
146
|
+
this.update_config(dir, accurate, clear);
|
|
147
|
+
}
|
|
148
|
+
|
|
124
149
|
if (!$.middleware) {
|
|
125
150
|
$.middleware = new Middleware();
|
|
126
151
|
}
|
|
127
152
|
|
|
128
|
-
module.exports = Middleware;
|
|
153
|
+
module.exports = Middleware;
|
package/core/com/mqtt/drive.js
CHANGED
|
@@ -16,7 +16,8 @@ class Drive extends Item {
|
|
|
16
16
|
constructor(dir) {
|
|
17
17
|
super(dir, __dirname);
|
|
18
18
|
this.default_file = "./mqtt.json";
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
this.mode = 3;
|
|
20
21
|
/* 通用项 */
|
|
21
22
|
/**
|
|
22
23
|
* 配置参数
|
|
@@ -400,7 +401,7 @@ Drive.prototype.run_event = function(clientid, key, json) {
|
|
|
400
401
|
* @param {String} msgid 消息ID
|
|
401
402
|
* @param {Object} json 信息
|
|
402
403
|
*/
|
|
403
|
-
Drive.prototype.
|
|
404
|
+
Drive.prototype.run = async function(clientid, key, json) {
|
|
404
405
|
var o;
|
|
405
406
|
if (this.drives[clientid]) {
|
|
406
407
|
o = this.drives[clientid][key];
|
|
@@ -495,7 +496,7 @@ Drive.prototype.handle = async function(push_topic, msg, topic, index) {
|
|
|
495
496
|
var id = json.id;
|
|
496
497
|
if (json.result && id) {
|
|
497
498
|
var key = this.get_key(json.method, json.clientid, id);
|
|
498
|
-
var o = await this.
|
|
499
|
+
var o = await this.run(json.clientid, key, json.result);
|
|
499
500
|
if (o) {
|
|
500
501
|
return
|
|
501
502
|
}
|
package/core/com/mqtt/index.js
CHANGED
|
@@ -21,22 +21,24 @@ class MQTT extends Index {
|
|
|
21
21
|
constructor(scope, title) {
|
|
22
22
|
super(scope, __dirname);
|
|
23
23
|
this.Drive = Drive;
|
|
24
|
+
// 更新并重载脚本
|
|
25
|
+
this.mode = 3;
|
|
24
26
|
this.type = "mqtt";
|
|
25
27
|
this.title = title;
|
|
26
28
|
this.dict = {};
|
|
27
|
-
|
|
28
29
|
this.config = {
|
|
29
30
|
hostname: "127.0.0.1",
|
|
30
31
|
port: "1883",
|
|
31
32
|
protocol: "mqtt",
|
|
32
|
-
clientId: "
|
|
33
|
+
clientId: "iot_test",
|
|
33
34
|
subscribe_qos: 0,
|
|
34
35
|
publish_qos: 1,
|
|
35
|
-
username: "
|
|
36
|
+
username: "iot_test",
|
|
36
37
|
password: "asd123",
|
|
37
38
|
table: "iot_device",
|
|
38
39
|
clean: false,
|
|
39
40
|
longtime: 15000,
|
|
41
|
+
requestTimeout: 3000,
|
|
40
42
|
// 在线有效期时长判断 单位:毫秒,150000毫秒为2.5分钟
|
|
41
43
|
online_expires: 150000,
|
|
42
44
|
// 在线有效期检测间隔
|
|
@@ -133,7 +135,7 @@ MQTT.prototype.update_after = function() {
|
|
|
133
135
|
_this.send(topic, msg, qos, retain);
|
|
134
136
|
}
|
|
135
137
|
};
|
|
136
|
-
o.
|
|
138
|
+
o.exec('init');
|
|
137
139
|
var topics = o.config.topic;
|
|
138
140
|
if (topics) {
|
|
139
141
|
for (var i = 0; i < topics.length; i++) {
|
|
@@ -273,7 +275,7 @@ MQTT.prototype.receive = async function(push_topic, msg) {
|
|
|
273
275
|
for (var i = 0; i < topics.length; i++) {
|
|
274
276
|
var topic = topics[i];
|
|
275
277
|
if (this.match(push_topic, topic)) {
|
|
276
|
-
ret = await o.run(
|
|
278
|
+
ret = await o.run(push_topic, msg, topic, i);
|
|
277
279
|
}
|
|
278
280
|
}
|
|
279
281
|
}
|
|
@@ -410,7 +412,7 @@ MQTT.prototype.reqASync = function(topic, method, params) {
|
|
|
410
412
|
resolve(null);
|
|
411
413
|
reject("request timeout!");
|
|
412
414
|
}
|
|
413
|
-
},
|
|
415
|
+
}, _this.config.requestTimeout);
|
|
414
416
|
});
|
|
415
417
|
};
|
|
416
418
|
|
package/core/com/nav/drive.js
CHANGED
|
@@ -29,7 +29,7 @@ class Drive extends Item {
|
|
|
29
29
|
// 模板路径
|
|
30
30
|
this.tpl_path = "./tpl/";
|
|
31
31
|
// 默认启用热更新
|
|
32
|
-
this.mode =
|
|
32
|
+
this.mode = 3;
|
|
33
33
|
/* 通用项 */
|
|
34
34
|
// 配置参数
|
|
35
35
|
this.config = {
|
|
@@ -349,24 +349,6 @@ Drive.prototype.new_config = function(file) {
|
|
|
349
349
|
file.saveText(JSON.stringify(cg, null, 4));
|
|
350
350
|
};
|
|
351
351
|
|
|
352
|
-
/**
|
|
353
|
-
* 载入配置
|
|
354
|
-
* @param {Object|String} cg 配置对象或配置路径
|
|
355
|
-
*/
|
|
356
|
-
Drive.prototype.load = function(cg) {
|
|
357
|
-
var obj;
|
|
358
|
-
if (!cg) {
|
|
359
|
-
cg = this.extensions;
|
|
360
|
-
}
|
|
361
|
-
if (typeof(cg) === "string") {
|
|
362
|
-
obj = this.loadFile(cg);
|
|
363
|
-
} else {
|
|
364
|
-
obj = cg;
|
|
365
|
-
}
|
|
366
|
-
this.loadObj(obj);
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
|
|
370
352
|
/**
|
|
371
353
|
* 获取API配置
|
|
372
354
|
* @param {String} app 应用域名
|
package/core/com/nav/index.js
CHANGED
package/core/com/param/drive.js
CHANGED
package/core/com/param/index.js
CHANGED
|
@@ -19,36 +19,10 @@ class Param extends Index {
|
|
|
19
19
|
this.type = "param";
|
|
20
20
|
this.title = title;
|
|
21
21
|
// 默认启用热更新
|
|
22
|
-
this.mode =
|
|
22
|
+
this.mode = 3;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
/**
|
|
27
|
-
* 加载配置
|
|
28
|
-
* @param {String} path 检索路径
|
|
29
|
-
*/
|
|
30
|
-
Param.prototype.load = function(path) {
|
|
31
|
-
if (!path) {
|
|
32
|
-
path = "./app/";
|
|
33
|
-
}
|
|
34
|
-
// 获取所有应用路径
|
|
35
|
-
var search_dir;
|
|
36
|
-
var _this = this;
|
|
37
|
-
if (this.scope && this.scope !== $.val.scope) {
|
|
38
|
-
search_dir = this.type + '_' + this.scope;
|
|
39
|
-
var list_scope = $.dir.getAll(path, search_dir);
|
|
40
|
-
list_scope.map(function(f) {
|
|
41
|
-
// 获取所有param配置文件
|
|
42
|
-
var list_file = $.file.getAll(f, "*" + _this.type + ".json");
|
|
43
|
-
_this.load_list(list_file);
|
|
44
|
-
});
|
|
45
|
-
} else {
|
|
46
|
-
// 获取所有param配置文件
|
|
47
|
-
var list_file = $.file.getAll(path, "*" + _this.type + ".json");
|
|
48
|
-
_this.load_list(list_file);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
26
|
/**
|
|
53
27
|
* 排序
|
|
54
28
|
*/
|
package/core/com/plugin/drive.js
CHANGED
|
@@ -18,7 +18,7 @@ class Drive extends Item {
|
|
|
18
18
|
super(dir, __dirname);
|
|
19
19
|
this.default_file = "./plugin.json";
|
|
20
20
|
// 默认启用热更新
|
|
21
|
-
this.mode =
|
|
21
|
+
this.mode = 3;
|
|
22
22
|
/**
|
|
23
23
|
* 当前语言
|
|
24
24
|
*/
|
|
@@ -80,7 +80,6 @@ Drive.prototype.set_config = function(config) {
|
|
|
80
80
|
var file = this.filename;
|
|
81
81
|
var cg = Object.assign({}, this.config, config || {});
|
|
82
82
|
this.config = conf(cg, file);
|
|
83
|
-
this.set_config_after();
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
/**
|
|
@@ -98,15 +97,6 @@ Drive.prototype.set_config_after = function() {
|
|
|
98
97
|
this.backup_options();
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
/**
|
|
102
|
-
* 重启设备
|
|
103
|
-
* @param {Object} option 配置
|
|
104
|
-
*/
|
|
105
|
-
Drive.prototype.restart = function(option) {
|
|
106
|
-
this.stop();
|
|
107
|
-
this.start();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
100
|
/**
|
|
111
101
|
* 更新配置
|
|
112
102
|
*/
|
|
@@ -327,31 +317,40 @@ Drive.prototype.set_lang = function(lang) {
|
|
|
327
317
|
};
|
|
328
318
|
|
|
329
319
|
/**
|
|
330
|
-
*
|
|
320
|
+
* 安装
|
|
331
321
|
* @param {Object} option 配置参数
|
|
332
|
-
* @return {String} 成功返回null
|
|
322
|
+
* @return {String} 成功返回null,否则返回错误提示
|
|
333
323
|
*/
|
|
334
|
-
Drive.prototype.
|
|
324
|
+
Drive.prototype.install = function(option) {
|
|
335
325
|
var msg = null;
|
|
336
326
|
return msg;
|
|
337
327
|
};
|
|
338
328
|
|
|
339
329
|
/**
|
|
340
|
-
*
|
|
330
|
+
* 重启设备
|
|
331
|
+
* @param {Object} option 配置
|
|
332
|
+
*/
|
|
333
|
+
Drive.prototype.restart = async function(option) {
|
|
334
|
+
await this.run('stop');
|
|
335
|
+
await this.run('start');
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* 初始化
|
|
341
340
|
* @param {Object} option 配置参数
|
|
342
341
|
* @return {String} 成功返回null, 否则返回错误提示
|
|
343
342
|
*/
|
|
344
|
-
Drive.prototype.
|
|
343
|
+
Drive.prototype.init = function(option) {
|
|
345
344
|
var msg = null;
|
|
346
345
|
return msg;
|
|
347
346
|
};
|
|
348
347
|
|
|
349
348
|
/**
|
|
350
|
-
*
|
|
349
|
+
* 更新
|
|
351
350
|
* @param {Object} option 配置参数
|
|
352
|
-
* @return {String} 成功返回null
|
|
351
|
+
* @return {String} 成功返回null, 否则返回错误提示
|
|
353
352
|
*/
|
|
354
|
-
Drive.prototype.
|
|
353
|
+
Drive.prototype.update = function(option) {
|
|
355
354
|
var msg = null;
|
|
356
355
|
return msg;
|
|
357
356
|
};
|
package/core/com/plugin/index.js
CHANGED
|
@@ -20,7 +20,7 @@ class Plugin extends Index {
|
|
|
20
20
|
this.type = "plugin";
|
|
21
21
|
this.title = title;
|
|
22
22
|
// 默认启用热更新
|
|
23
|
-
this.mode =
|
|
23
|
+
this.mode = 3;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -58,40 +58,35 @@ Plugin.prototype.init = function(option) {
|
|
|
58
58
|
var ret = "";
|
|
59
59
|
var lt = this.list;
|
|
60
60
|
for (var i = 0, o; o = lt[i++];) {
|
|
61
|
-
ret = o.
|
|
61
|
+
ret = o.exec('init', option);
|
|
62
62
|
}
|
|
63
63
|
return ret;
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
Plugin.prototype.sort = function() {
|
|
67
|
-
this.list.sortBy('sort');
|
|
68
|
-
};
|
|
69
|
-
|
|
70
66
|
/**
|
|
71
67
|
* 加载插件
|
|
72
68
|
* @param {String} path 检索路径
|
|
73
|
-
* @param {Boolean}
|
|
69
|
+
* @param {Boolean} accurate 是否精确路径
|
|
74
70
|
*/
|
|
75
|
-
Plugin.prototype.
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
Plugin.prototype.update_config_all = async function(path, accurate) {
|
|
72
|
+
var dir_plugin;
|
|
73
|
+
if (accurate) {
|
|
74
|
+
dir_plugin = path;
|
|
75
|
+
} else {
|
|
76
|
+
if (!path) {
|
|
77
|
+
path = '/app/' + this.scope;
|
|
78
|
+
}
|
|
79
|
+
dir_plugin = path + "/plugin/";
|
|
78
80
|
}
|
|
79
|
-
list = this.list;
|
|
80
|
-
var dir_plugin = path + "/plugin/";
|
|
81
81
|
if (dir_plugin.hasDir()) {
|
|
82
82
|
var list_scope = $.dir.get(dir_plugin);
|
|
83
|
-
|
|
84
83
|
// 遍历目录路径
|
|
85
|
-
|
|
84
|
+
for (var i = 0, o; o = list_scope[i++];) {
|
|
86
85
|
var file = './plugin.json'.fullname(o);
|
|
87
86
|
if (file.hasFile()) {
|
|
88
|
-
|
|
89
|
-
obj.load(file);
|
|
90
|
-
if (obj.config.name) {
|
|
91
|
-
list.push(obj);
|
|
92
|
-
}
|
|
87
|
+
await this.load_file(file, true);
|
|
93
88
|
}
|
|
94
|
-
}
|
|
89
|
+
}
|
|
95
90
|
}
|
|
96
91
|
};
|
|
97
92
|
|
|
@@ -138,7 +133,7 @@ Plugin.prototype.unzip = async function(file) {
|
|
|
138
133
|
Plugin.prototype.uninstall = async function(name) {
|
|
139
134
|
var plus = this.get(name);
|
|
140
135
|
if (plus) {
|
|
141
|
-
await plus.
|
|
136
|
+
await plus.exec('uninstall');
|
|
142
137
|
var obj = this.del(name, true);
|
|
143
138
|
if (obj) {
|
|
144
139
|
var file = obj.filename;
|