mm_os 2.5.4 → 2.5.6
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 +24 -23
- package/core/com/api/index.js +3 -9
- package/core/com/cmd/drive.js +45 -34
- package/core/com/cmd/index.js +3 -16
- package/core/com/component/index.js +1 -6
- package/core/com/event/drive.js +8 -3
- package/core/com/event/index.js +9 -20
- package/core/com/eventer/com.js +1 -1
- package/core/com/mqtt/drive.js +27 -11
- package/core/com/mqtt/index.js +62 -22
- package/core/com/plugin/drive.js +12 -2
- package/core/com/plugin/index.js +1 -1
- package/core/com/static/drive.js +38 -34
- package/core/com/static/index.js +2 -11
- package/core/com/task/drive.js +18 -16
- package/core/com/timer/com.js +1 -1
- package/demo/config/development.json +1 -1
- package/package.json +4 -4
- package/static/file/image/user/1/2024_12_10_11_05_52.png +0 -0
- package/static/file/image/user/1/2024_12_10_11_06_22.png +0 -0
- package/static/file/image/user/1/2024_12_11_11_04_04.png +0 -0
- package/static/file/image/user/1/2024_12_11_11_04_18.png +0 -0
- package/static/file/image/user/1/2024_12_11_11_05_28.png +0 -0
- package/static/file/image/user/1/2024_12_11_11_06_09.png +0 -0
- package/static/file/image/user/29/2024_12_11_10_03_46.png +0 -0
package/core/com/api/drive.js
CHANGED
|
@@ -415,8 +415,7 @@ Drive.prototype.get_state = async function(ctx, db) {
|
|
|
415
415
|
ctx.session.user = obj.user;
|
|
416
416
|
o.token = ctx.session.uuid;
|
|
417
417
|
obj.state.token = o.token;
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
418
|
+
} else {
|
|
420
419
|
o = null;
|
|
421
420
|
}
|
|
422
421
|
} else {
|
|
@@ -483,28 +482,30 @@ Drive.prototype.main = async function(ctx, db) {
|
|
|
483
482
|
* @return {Object} 执行结果
|
|
484
483
|
*/
|
|
485
484
|
Drive.prototype.run = async function(ctx, db) {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
await this.before(ctx, db);
|
|
496
|
-
var ret = await this.check(ctx, db);
|
|
497
|
-
if (!ret) {
|
|
498
|
-
try {
|
|
499
|
-
ret = await this.main(ctx, db);
|
|
500
|
-
} catch (err) {
|
|
501
|
-
$.log.error("脚本文件错误", req.path, err);
|
|
502
|
-
ret = $.ret.error(10000, "脚本文件错误:" + err.toString());
|
|
485
|
+
try {
|
|
486
|
+
var body = await this.getCache(ctx);
|
|
487
|
+
if (!body) {
|
|
488
|
+
var req = ctx.request;
|
|
489
|
+
var md = this.config["method"].toLocaleUpperCase();
|
|
490
|
+
if (md !== req.method && md !== "ALL") {
|
|
491
|
+
return null;
|
|
503
492
|
}
|
|
493
|
+
await this.before(ctx, db);
|
|
494
|
+
var ret = await this.check(ctx, db);
|
|
495
|
+
if (!ret) {
|
|
496
|
+
try {
|
|
497
|
+
ret = await this.main(ctx, db);
|
|
498
|
+
} catch (err) {
|
|
499
|
+
$.log.error("脚本文件错误", req.path, err);
|
|
500
|
+
ret = $.ret.error(10000, "脚本文件错误:" + err.toString());
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
var res = ctx.response;
|
|
504
|
+
body = this.body(ret, res, req.type);
|
|
505
|
+
this.setCache(ctx, body, res.type);
|
|
504
506
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
this.setCache(ctx, body, res.type);
|
|
507
|
+
} catch (err) {
|
|
508
|
+
$.log.error("接口错误", ctx.path, err);
|
|
508
509
|
}
|
|
509
510
|
return body;
|
|
510
511
|
};
|
|
@@ -708,7 +709,7 @@ Drive.prototype.runRPC = async function(db, method, query, body) {
|
|
|
708
709
|
}
|
|
709
710
|
}
|
|
710
711
|
} catch (err) {
|
|
711
|
-
$.log.error(err);
|
|
712
|
+
$.log.error("运行RPC方法错误!", method, err);
|
|
712
713
|
ret = {
|
|
713
714
|
error: {
|
|
714
715
|
code: 500,
|
package/core/com/api/index.js
CHANGED
|
@@ -54,15 +54,9 @@ Api.prototype.run = async function(ctx, db) {
|
|
|
54
54
|
|
|
55
55
|
for (var i = 0, o; o = lt[i++];) {
|
|
56
56
|
if (o.config.state === 1 && path.has(o.config.path)) {
|
|
57
|
-
var ret;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (this.mode) {
|
|
61
|
-
o.load(o.filename);
|
|
62
|
-
}
|
|
63
|
-
} catch (error) {
|
|
64
|
-
$.log.error("接口错误", ctx.path, error);
|
|
65
|
-
//TODO handle the exception
|
|
57
|
+
var ret = await o.run(ctx, db);
|
|
58
|
+
if (this.mode) {
|
|
59
|
+
o.load(o.filename);
|
|
66
60
|
}
|
|
67
61
|
if (ret) {
|
|
68
62
|
db.ret = ret;
|
package/core/com/cmd/drive.js
CHANGED
|
@@ -244,7 +244,7 @@ Drive.prototype.fill = async function(msg, db, stage) {
|
|
|
244
244
|
return "";
|
|
245
245
|
}
|
|
246
246
|
var list = stage.param;
|
|
247
|
-
if(!list || list.length === 0){
|
|
247
|
+
if (!list || list.length === 0) {
|
|
248
248
|
return "";
|
|
249
249
|
}
|
|
250
250
|
var form = {};
|
|
@@ -394,15 +394,18 @@ Drive.prototype.end = async function(msg, db, ret) {
|
|
|
394
394
|
*/
|
|
395
395
|
Drive.prototype.run_cmd = async function(msg, db) {
|
|
396
396
|
var ret;
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
397
|
+
try {
|
|
398
|
+
// 第一步, 验证阶段
|
|
399
|
+
var bl = await this.check(msg, db);
|
|
400
|
+
if (bl) {
|
|
401
|
+
ret = await this.run(msg, db);
|
|
402
|
+
}
|
|
403
|
+
} catch (err) {
|
|
404
|
+
$.log.error("指令错误", this.config.name, err);
|
|
401
405
|
}
|
|
402
406
|
return ret;
|
|
403
407
|
};
|
|
404
408
|
|
|
405
|
-
|
|
406
409
|
/**
|
|
407
410
|
* 执行
|
|
408
411
|
* @param {Object} msg 消息上下文
|
|
@@ -411,14 +414,18 @@ Drive.prototype.run_cmd = async function(msg, db) {
|
|
|
411
414
|
*/
|
|
412
415
|
Drive.prototype.run_first = async function(msg, db) {
|
|
413
416
|
var ret;
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
417
|
+
try {
|
|
418
|
+
// 第一步, 验证阶段
|
|
419
|
+
var bl = await this.check(msg, db);
|
|
420
|
+
if (bl) {
|
|
421
|
+
ret = await this.run(msg, db);
|
|
422
|
+
if (ret) {
|
|
423
|
+
// 如果匹配指令则将该消息定义为使用该指令
|
|
424
|
+
db.msg.cmd = this.config.name;
|
|
425
|
+
}
|
|
421
426
|
}
|
|
427
|
+
} catch (err) {
|
|
428
|
+
$.log.error("指令错误", this.config.name, err);
|
|
422
429
|
}
|
|
423
430
|
return ret;
|
|
424
431
|
};
|
|
@@ -451,32 +458,36 @@ Drive.prototype.run_after = async function(msg, db, ret) {
|
|
|
451
458
|
* @return {Object} 返回执行结果
|
|
452
459
|
*/
|
|
453
460
|
Drive.prototype.run = async function(msg, db) {
|
|
461
|
+
var ret;
|
|
462
|
+
try {
|
|
463
|
+
// 第二步, 过滤阶段
|
|
464
|
+
msg.content = await this.filter(msg, db);
|
|
454
465
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
if (this[mode]) {
|
|
466
|
-
ret = await this[mode](msg, db, stage);
|
|
466
|
+
// 执行前
|
|
467
|
+
ret = await this.run_before(msg, db);
|
|
468
|
+
if (!ret) {
|
|
469
|
+
// 第三步, 信息补全或更新阶段
|
|
470
|
+
var stage = this.config["stage" + db.msg.stage];
|
|
471
|
+
if (stage) {
|
|
472
|
+
var mode = stage.mode ? stage.mode : "fill";
|
|
473
|
+
if (this[mode]) {
|
|
474
|
+
ret = await this[mode](msg, db, stage);
|
|
475
|
+
}
|
|
467
476
|
}
|
|
468
|
-
}
|
|
469
477
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
478
|
+
if (!ret) {
|
|
479
|
+
// 第五步, 执行阶段
|
|
480
|
+
ret = await this.main(msg, db);
|
|
473
481
|
|
|
474
|
-
|
|
475
|
-
|
|
482
|
+
// 第六步, 结束会话阶段
|
|
483
|
+
ret = this.end(msg, db, ret);
|
|
484
|
+
}
|
|
476
485
|
}
|
|
486
|
+
// 执行后
|
|
487
|
+
ret = await this.run_after(msg, db, ret);
|
|
488
|
+
} catch (error) {
|
|
489
|
+
$.log.error("指令执行失败!", this.config.name, error);
|
|
477
490
|
}
|
|
478
|
-
// 执行后
|
|
479
|
-
ret = await this.run_after(msg, db, ret);
|
|
480
491
|
return ret;
|
|
481
492
|
};
|
|
482
493
|
|
|
@@ -508,4 +519,4 @@ Drive.prototype.view = function(msg, db) {
|
|
|
508
519
|
return ret.trim();
|
|
509
520
|
};
|
|
510
521
|
|
|
511
|
-
module.exports = Drive;
|
|
522
|
+
module.exports = Drive;
|
package/core/com/cmd/index.js
CHANGED
|
@@ -77,11 +77,7 @@ Cmd.prototype.run = async function(msg, db, table) {
|
|
|
77
77
|
var lt = this.list_before;
|
|
78
78
|
for (var i = 0, o; o = lt[i++];) {
|
|
79
79
|
if (o.config.state === 1) {
|
|
80
|
-
|
|
81
|
-
ret = await o.run_cmd(msg, db);
|
|
82
|
-
} catch (error) {
|
|
83
|
-
$.log.error("指令错误", o.config.name, error);
|
|
84
|
-
}
|
|
80
|
+
ret = await o.run_cmd(msg, db);
|
|
85
81
|
if (ret) {
|
|
86
82
|
break;
|
|
87
83
|
}
|
|
@@ -124,11 +120,7 @@ Cmd.prototype.run = async function(msg, db, table) {
|
|
|
124
120
|
var lt = this.list_main;
|
|
125
121
|
for (var i = 0, o; o = lt[i++];) {
|
|
126
122
|
if (o.config.state === 1) {
|
|
127
|
-
|
|
128
|
-
ret = await o.run_first(msg, db);
|
|
129
|
-
} catch (error) {
|
|
130
|
-
$.log.error("指令错误", o.config.name, error);
|
|
131
|
-
}
|
|
123
|
+
ret = await o.run_first(msg, db);
|
|
132
124
|
if (ret) {
|
|
133
125
|
break;
|
|
134
126
|
}
|
|
@@ -139,12 +131,7 @@ Cmd.prototype.run = async function(msg, db, table) {
|
|
|
139
131
|
var lt = this.list_after;
|
|
140
132
|
for (var i = 0, o; o = lt[i++];) {
|
|
141
133
|
if (o.config.state === 1) {
|
|
142
|
-
|
|
143
|
-
ret = await o.run_first(msg, db);
|
|
144
|
-
} catch (error) {
|
|
145
|
-
$.log.error("指令错误", o.config.name, error);
|
|
146
|
-
}
|
|
147
|
-
|
|
134
|
+
ret = await o.run_first(msg, db);
|
|
148
135
|
if (ret) {
|
|
149
136
|
break;
|
|
150
137
|
}
|
|
@@ -92,12 +92,7 @@ Component.prototype.render = async function(page, position, ctx, db) {
|
|
|
92
92
|
position
|
|
93
93
|
});
|
|
94
94
|
if (obj && obj.onoff) {
|
|
95
|
-
var ret;
|
|
96
|
-
try {
|
|
97
|
-
ret = await o.run('main', ctx, db);
|
|
98
|
-
} catch (error) {
|
|
99
|
-
$.log.error("组件渲染失败", o.config.name, error);
|
|
100
|
-
}
|
|
95
|
+
var ret = await o.run('main', ctx, db);
|
|
101
96
|
if (ret) {
|
|
102
97
|
html += "\n" + ret;
|
|
103
98
|
}
|
package/core/com/event/drive.js
CHANGED
|
@@ -95,7 +95,7 @@ Drive.prototype.new_config = function(file) {
|
|
|
95
95
|
text = text.replaceAll('{0}', event_name);
|
|
96
96
|
text = text.replaceAll('{1}', '/' + event_name + '*');
|
|
97
97
|
}
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
file.saveText(text);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -109,7 +109,12 @@ Drive.prototype.new_config = function(file) {
|
|
|
109
109
|
* @return {Object} 执行结果
|
|
110
110
|
*/
|
|
111
111
|
Drive.prototype.run = async function(ctx, db, method = 'main') {
|
|
112
|
-
var ret
|
|
112
|
+
var ret;
|
|
113
|
+
try {
|
|
114
|
+
ret = await this[method](ctx, db);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
$.log.error("事件执行失败!", this.config.name, error);
|
|
117
|
+
}
|
|
113
118
|
return ret;
|
|
114
119
|
};
|
|
115
120
|
|
|
@@ -123,4 +128,4 @@ Drive.prototype.main = async function(ctx, db) {
|
|
|
123
128
|
return null;
|
|
124
129
|
};
|
|
125
130
|
|
|
126
|
-
module.exports = Drive;
|
|
131
|
+
module.exports = Drive;
|
package/core/com/event/index.js
CHANGED
|
@@ -145,17 +145,12 @@ Event.prototype.sort = function(stage) {
|
|
|
145
145
|
* 执行事件
|
|
146
146
|
*/
|
|
147
147
|
Event.prototype.doing = async function(o, ctx, db) {
|
|
148
|
-
var ret;
|
|
149
|
-
|
|
150
|
-
ret =
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (this.mode) {
|
|
155
|
-
o.load(o.filename);
|
|
156
|
-
}
|
|
157
|
-
} catch (err) {
|
|
158
|
-
console.error(err);
|
|
148
|
+
var ret = o.run(ctx, db);
|
|
149
|
+
if (types.isPromise(ret)) {
|
|
150
|
+
ret = await ret;
|
|
151
|
+
}
|
|
152
|
+
if (this.mode) {
|
|
153
|
+
o.load(o.filename);
|
|
159
154
|
}
|
|
160
155
|
return ret;
|
|
161
156
|
}
|
|
@@ -171,14 +166,9 @@ Event.prototype.doing = async function(o, ctx, db) {
|
|
|
171
166
|
Event.prototype.run_sub = async function(list, target, ctx, db) {
|
|
172
167
|
for (var i = 0, o; o = list[i++];) {
|
|
173
168
|
if (o.config.state === 1 && target.has(o.config.target)) {
|
|
174
|
-
var ret;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (this.mode) {
|
|
178
|
-
o.load(o.filename);
|
|
179
|
-
}
|
|
180
|
-
} catch (error) {
|
|
181
|
-
$.log.error("事件执行错误", o.config.name, error);
|
|
169
|
+
var ret = await o.run(ctx, db);
|
|
170
|
+
if (this.mode) {
|
|
171
|
+
o.load(o.filename);
|
|
182
172
|
}
|
|
183
173
|
if (ret) {
|
|
184
174
|
db.ret = ret;
|
|
@@ -255,7 +245,6 @@ Event.prototype.after = async function(target, ctx, db) {
|
|
|
255
245
|
* @return {Object} 执行结果
|
|
256
246
|
*/
|
|
257
247
|
Event.prototype.run = async function(target, ctx, db) {
|
|
258
|
-
console.log("运行了", target, ctx, db);
|
|
259
248
|
if (!db) {
|
|
260
249
|
db = {
|
|
261
250
|
ret: null
|
package/core/com/eventer/com.js
CHANGED
package/core/com/mqtt/drive.js
CHANGED
|
@@ -313,7 +313,7 @@ Drive.prototype.pushS = function(clientid, msg, longtime) {
|
|
|
313
313
|
*/
|
|
314
314
|
Drive.prototype.save_online = async function(clientid, online, ip) {
|
|
315
315
|
if (!clientid) {
|
|
316
|
-
|
|
316
|
+
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
|
|
@@ -379,9 +379,12 @@ Drive.prototype.del_msg = function(clientid, key) {
|
|
|
379
379
|
*/
|
|
380
380
|
Drive.prototype.run_event = function(clientid, key, json) {
|
|
381
381
|
var method = key.left("_");
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
382
|
+
if (this[method + "_event"]) {
|
|
383
|
+
try {
|
|
384
|
+
this[method + "_event"](clientid, json);
|
|
385
|
+
} catch (err) {
|
|
386
|
+
$.log.error("MQTT事件执行失败!", key, err);
|
|
387
|
+
}
|
|
385
388
|
}
|
|
386
389
|
}
|
|
387
390
|
|
|
@@ -398,7 +401,11 @@ Drive.prototype.exec = async function(clientid, key, json) {
|
|
|
398
401
|
}
|
|
399
402
|
if (o) {
|
|
400
403
|
delete this.drives[clientid][key];
|
|
401
|
-
|
|
404
|
+
try {
|
|
405
|
+
await o.func(json);
|
|
406
|
+
} catch (err) {
|
|
407
|
+
$.log.error("MQTT执行失败!", key, err);
|
|
408
|
+
}
|
|
402
409
|
} else {
|
|
403
410
|
await this.run_event(clientid, key, json);
|
|
404
411
|
}
|
|
@@ -505,7 +512,12 @@ Drive.prototype.handle = async function(push_topic, msg, topic, index) {
|
|
|
505
512
|
if (func) {
|
|
506
513
|
var id = json.id;
|
|
507
514
|
var params = json.params;
|
|
508
|
-
var ret
|
|
515
|
+
var ret;
|
|
516
|
+
try {
|
|
517
|
+
ret = func(json.clientid, params, msg, id);
|
|
518
|
+
} catch (err) {
|
|
519
|
+
$.log.error("事件回调失败!", err);
|
|
520
|
+
}
|
|
509
521
|
if (ret) {
|
|
510
522
|
if (util.types.isPromise(ret)) {
|
|
511
523
|
ret = await ret;
|
|
@@ -518,11 +530,15 @@ Drive.prototype.handle = async function(push_topic, msg, topic, index) {
|
|
|
518
530
|
if (id) {
|
|
519
531
|
obj[cg.msgid] = id;
|
|
520
532
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
533
|
+
try {
|
|
534
|
+
obj[cg.method] = this.get_method(json.method);
|
|
535
|
+
obj[cg.result] = ret;
|
|
536
|
+
var topic_receive = this.get_topic(arr_tc[index], json.clientid, params);
|
|
537
|
+
var reply_msg = this.convert_out(topic_receive, obj, topic, index);
|
|
538
|
+
await this.send(topic_receive, reply_msg);
|
|
539
|
+
} catch (err) {
|
|
540
|
+
$.log.error("MQTT事件响应失败!", err);
|
|
541
|
+
}
|
|
526
542
|
}
|
|
527
543
|
}
|
|
528
544
|
}
|
package/core/com/mqtt/index.js
CHANGED
|
@@ -132,12 +132,7 @@ MQTT.prototype.update_after = function() {
|
|
|
132
132
|
_this.send(topic, msg, qos, retain);
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
|
-
|
|
136
|
-
try {
|
|
137
|
-
o.run('init');
|
|
138
|
-
} catch (error) {
|
|
139
|
-
$.log.error("MQTT类初始化失败", o.config.name, error);
|
|
140
|
-
}
|
|
135
|
+
o.run('init');
|
|
141
136
|
var topics = o.config.topic;
|
|
142
137
|
if (topics) {
|
|
143
138
|
for (var i = 0; i < topics.length; i++) {
|
|
@@ -280,11 +275,7 @@ MQTT.prototype.receive = async function(push_topic, msg) {
|
|
|
280
275
|
for (var i = 0; i < topics.length; i++) {
|
|
281
276
|
var topic = topics[i];
|
|
282
277
|
if (this.match(push_topic, topic)) {
|
|
283
|
-
|
|
284
|
-
ret = await o.run("main", push_topic, msg, topic, i);
|
|
285
|
-
} catch (error) {
|
|
286
|
-
$.log.error("MQTT执行失败", o.config.name, error);
|
|
287
|
-
}
|
|
278
|
+
ret = await o.run("main", push_topic, msg, topic, i);
|
|
288
279
|
}
|
|
289
280
|
}
|
|
290
281
|
}
|
|
@@ -436,50 +427,99 @@ MQTT.prototype.save_online = async function(arr, online = 1) {
|
|
|
436
427
|
var db = sql.db();
|
|
437
428
|
db.table = "face_device";
|
|
438
429
|
db.size = 0;
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
430
|
+
var query = {};
|
|
431
|
+
if (arr) {
|
|
432
|
+
query.clientid_has = arr.join(",");
|
|
433
|
+
}
|
|
434
|
+
await db.set(query, body);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* 获取所有设备
|
|
439
|
+
*/
|
|
440
|
+
MQTT.prototype.get_drives = async function() {
|
|
441
|
+
var sql = $.mysql_admin('sys');
|
|
442
|
+
sql.open();
|
|
443
|
+
var db = sql.db();
|
|
444
|
+
db.table = "face_device";
|
|
445
|
+
db.size = 0;
|
|
446
|
+
return await db.get({}, "", "clientid, online");
|
|
442
447
|
}
|
|
443
448
|
|
|
444
449
|
/**
|
|
445
450
|
* 更新在线设备
|
|
446
451
|
*/
|
|
447
452
|
MQTT.prototype.update_online = async function() {
|
|
453
|
+
// 获取所有方案
|
|
448
454
|
var list = this.list;
|
|
449
455
|
var list_online = [];
|
|
450
456
|
var list_offline = [];
|
|
457
|
+
var list_has = [];
|
|
458
|
+
|
|
451
459
|
var now = new Date().getTime();
|
|
452
460
|
var online_expires = this.config.online_expires; // 180
|
|
461
|
+
|
|
462
|
+
// 获取所有设备
|
|
463
|
+
var drives = await this.get_drives();
|
|
453
464
|
for (var i = 0; i < list.length; i++) {
|
|
454
465
|
var dict = list[i].drives;
|
|
455
466
|
for (var clientid in dict) {
|
|
467
|
+
list_has.push(clientid);
|
|
468
|
+
var drive = drives.getObj({
|
|
469
|
+
clientid
|
|
470
|
+
});
|
|
456
471
|
var o = dict[clientid];
|
|
457
472
|
if (o.online === 1) {
|
|
458
473
|
if (o.time_last) {
|
|
459
474
|
var cha = now - o.time_last;
|
|
460
475
|
if (cha > online_expires) {
|
|
461
|
-
|
|
476
|
+
if (drive && drive.online) {
|
|
477
|
+
// 如果设备本身在线,需要改为离线
|
|
478
|
+
list_offline.push(clientid);
|
|
479
|
+
}
|
|
462
480
|
o.online = 0;
|
|
463
481
|
delete dict[clientid];
|
|
464
482
|
} else {
|
|
465
|
-
|
|
483
|
+
if (drive && !drive.online) {
|
|
484
|
+
// 如果设备本身离线,需要改为在线
|
|
485
|
+
list_online.push(clientid);
|
|
486
|
+
}
|
|
466
487
|
}
|
|
467
|
-
} else {
|
|
468
|
-
list_online.push(clientid);
|
|
469
488
|
}
|
|
470
489
|
} else {
|
|
471
|
-
|
|
490
|
+
if (drive && drive.online) {
|
|
491
|
+
// 如果设备本身在线,需要改为离线
|
|
492
|
+
list_offline.push(clientid);
|
|
493
|
+
}
|
|
472
494
|
}
|
|
473
495
|
}
|
|
474
496
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
497
|
+
|
|
498
|
+
// 如果设备没有出现过,则视为离线
|
|
499
|
+
for (var i = 0; i < drives.length; i++) {
|
|
500
|
+
var {
|
|
501
|
+
clientid,
|
|
502
|
+
online
|
|
503
|
+
} = drives[i];
|
|
504
|
+
if (online && list_has.indexOf(clientid) === -1) {
|
|
505
|
+
list_offline.push(clientid);
|
|
506
|
+
}
|
|
478
507
|
}
|
|
508
|
+
|
|
509
|
+
// console.log("在线设备变化", list_online);
|
|
510
|
+
// console.log("离线设备变化", list_offline);
|
|
511
|
+
|
|
512
|
+
// 先将设备离线
|
|
479
513
|
var list_off = list_offline.to2D(30);
|
|
480
514
|
for (var i = 0; i < list_off.length; i++) {
|
|
481
515
|
await this.save_online(list_off[i], 0);
|
|
482
516
|
}
|
|
517
|
+
|
|
518
|
+
// 再将设备在线
|
|
519
|
+
var list_on = list_online.to2D(30);
|
|
520
|
+
for (var i = 0; i < list_on.length; i++) {
|
|
521
|
+
await this.save_online(list_on[i], 1);
|
|
522
|
+
}
|
|
483
523
|
}
|
|
484
524
|
|
|
485
525
|
/**
|
package/core/com/plugin/drive.js
CHANGED
|
@@ -314,7 +314,12 @@ Drive.prototype.run_cmd = async function(content) {
|
|
|
314
314
|
if (!content) {
|
|
315
315
|
content = "";
|
|
316
316
|
}
|
|
317
|
-
var ret
|
|
317
|
+
var ret;
|
|
318
|
+
try {
|
|
319
|
+
ret = this.cmd(content);
|
|
320
|
+
} catch (err) {
|
|
321
|
+
$.log.error("运行插件指令失败!", this.config.name, err);
|
|
322
|
+
}
|
|
318
323
|
if (!ret) {
|
|
319
324
|
ret = "";
|
|
320
325
|
}
|
|
@@ -341,7 +346,12 @@ Drive.prototype.run_chat = async function(from_user, to_user, content, group, ty
|
|
|
341
346
|
if (!group) {
|
|
342
347
|
group = "";
|
|
343
348
|
}
|
|
344
|
-
var ret
|
|
349
|
+
var ret;
|
|
350
|
+
try {
|
|
351
|
+
ret = this.chat(from_user, to_user, group, content, type, msg_type, db);
|
|
352
|
+
} catch (err) {
|
|
353
|
+
$.log.error("运行插件聊天失败!", this.config.name, err);
|
|
354
|
+
}
|
|
345
355
|
if (!ret) {
|
|
346
356
|
ret = "";
|
|
347
357
|
}
|
package/core/com/plugin/index.js
CHANGED
package/core/com/static/drive.js
CHANGED
|
@@ -203,51 +203,55 @@ Drive.prototype.run = async function(ctx, path, next) {
|
|
|
203
203
|
var done;
|
|
204
204
|
var cg = this.config;
|
|
205
205
|
var ph = cg.path;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
this.after(ctx, p, done);
|
|
213
|
-
} catch (err) {
|
|
214
|
-
if (err.status !== 404) {
|
|
215
|
-
throw err;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
} else {
|
|
219
|
-
done = ' ';
|
|
220
|
-
if (ctx.status === 404) {
|
|
221
|
-
var file;
|
|
222
|
-
|
|
223
|
-
// 取到物理路径
|
|
224
|
-
var root = this.dir;
|
|
225
|
-
var dir = (root + p).fullname();
|
|
226
|
-
if (!p) {
|
|
227
|
-
file = dir + '/' + cg.index;
|
|
228
|
-
} else if (p.endWith('/')) {
|
|
229
|
-
file = dir + cg.index;
|
|
230
|
-
} else {
|
|
231
|
-
file = dir + '.html';
|
|
232
|
-
}
|
|
233
|
-
if (file.hasFile()) {
|
|
234
|
-
p = file.replace(root, '');
|
|
235
|
-
this.before(ctx, p);
|
|
206
|
+
try {
|
|
207
|
+
if (path.startWith(ph)) {
|
|
208
|
+
var p = path.replace(ph, '');
|
|
209
|
+
if (p.indexOf('.') !== -1) {
|
|
210
|
+
this.before(ctx, p);
|
|
211
|
+
try {
|
|
236
212
|
done = await this.main(ctx, p);
|
|
237
213
|
this.after(ctx, p, done);
|
|
238
|
-
}
|
|
239
|
-
|
|
214
|
+
} catch (err) {
|
|
215
|
+
if (err.status !== 404) {
|
|
216
|
+
throw err;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
done = ' ';
|
|
221
|
+
if (ctx.status === 404) {
|
|
222
|
+
var file;
|
|
223
|
+
|
|
224
|
+
// 取到物理路径
|
|
225
|
+
var root = this.dir;
|
|
226
|
+
var dir = (root + p).fullname();
|
|
227
|
+
if (!p) {
|
|
228
|
+
file = dir + '/' + cg.index;
|
|
229
|
+
} else if (p.endWith('/')) {
|
|
230
|
+
file = dir + cg.index;
|
|
231
|
+
} else {
|
|
232
|
+
file = dir + '.html';
|
|
233
|
+
}
|
|
240
234
|
if (file.hasFile()) {
|
|
241
|
-
p =
|
|
235
|
+
p = file.replace(root, '');
|
|
242
236
|
this.before(ctx, p);
|
|
243
237
|
done = await this.main(ctx, p);
|
|
244
238
|
this.after(ctx, p, done);
|
|
239
|
+
} else if (cg.redirect) {
|
|
240
|
+
var file = root + '/index.html';
|
|
241
|
+
if (file.hasFile()) {
|
|
242
|
+
p = '/index.html';
|
|
243
|
+
this.before(ctx, p);
|
|
244
|
+
done = await this.main(ctx, p);
|
|
245
|
+
this.after(ctx, p, done);
|
|
246
|
+
}
|
|
245
247
|
}
|
|
246
248
|
}
|
|
247
249
|
}
|
|
248
250
|
}
|
|
251
|
+
} catch (err) {
|
|
252
|
+
$.log.error("静态文件执行错误", this.config.name, err);
|
|
249
253
|
}
|
|
250
254
|
return done;
|
|
251
255
|
};
|
|
252
256
|
|
|
253
|
-
module.exports = Drive;
|
|
257
|
+
module.exports = Drive;
|
package/core/com/static/index.js
CHANGED
|
@@ -41,12 +41,7 @@ class Static extends Index {
|
|
|
41
41
|
for (var i = 0; i < len; i++) {
|
|
42
42
|
var o = list[i];
|
|
43
43
|
if (o.config.state === 1) {
|
|
44
|
-
|
|
45
|
-
done = await o.run(ctx, path, next);
|
|
46
|
-
} catch (error) {
|
|
47
|
-
$.log.error("静态文件执行错误", o.config.name, error);
|
|
48
|
-
}
|
|
49
|
-
|
|
44
|
+
done = await o.run(ctx, path, next);
|
|
50
45
|
if (done) {
|
|
51
46
|
break;
|
|
52
47
|
}
|
|
@@ -71,11 +66,7 @@ class Static extends Index {
|
|
|
71
66
|
}
|
|
72
67
|
break;
|
|
73
68
|
} else {
|
|
74
|
-
|
|
75
|
-
done = await o.run(ctx, path, next);
|
|
76
|
-
} catch (error) {
|
|
77
|
-
$.log.error("静态文件执行错误", o.config.name, error);
|
|
78
|
-
}
|
|
69
|
+
done = await o.run(ctx, path, next);
|
|
79
70
|
if (done) {
|
|
80
71
|
break;
|
|
81
72
|
}
|
package/core/com/task/drive.js
CHANGED
|
@@ -42,7 +42,7 @@ class Drive extends Item {
|
|
|
42
42
|
constructor(dir) {
|
|
43
43
|
super(dir, __dirname);
|
|
44
44
|
this.default_file = "./task.json";
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
/// 配置参数
|
|
47
47
|
this.config = {
|
|
48
48
|
// 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
|
|
@@ -70,7 +70,7 @@ class Drive extends Item {
|
|
|
70
70
|
// 执行顺序
|
|
71
71
|
"sort": 100
|
|
72
72
|
};
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
/// 状态
|
|
75
75
|
this.state = "start";
|
|
76
76
|
/// 等候器
|
|
@@ -139,15 +139,13 @@ Drive.prototype.setPeriod = function(func) {
|
|
|
139
139
|
func();
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
|
-
}
|
|
143
|
-
else if (arr.length == 2) {
|
|
142
|
+
} else if (arr.length == 2) {
|
|
144
143
|
fn = function() {
|
|
145
144
|
if (new Date().toStr('dd hh:mm') === time) {
|
|
146
145
|
func();
|
|
147
146
|
}
|
|
148
147
|
};
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
148
|
+
} else {
|
|
151
149
|
fn = function() {
|
|
152
150
|
if (new Date().toStr('dd hh') === time) {
|
|
153
151
|
func();
|
|
@@ -227,15 +225,19 @@ Drive.prototype.setNum = function(func) {
|
|
|
227
225
|
var _this = this;
|
|
228
226
|
return function() {
|
|
229
227
|
if (_this.state === 'start') {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
228
|
+
try {
|
|
229
|
+
if (_this.config.num < 1) {
|
|
230
|
+
func();
|
|
231
|
+
} else if (_this.num < _this.config.num) {
|
|
232
|
+
func();
|
|
233
|
+
_this.num += 1;
|
|
234
|
+
} else {
|
|
235
|
+
func();
|
|
236
|
+
_this.clear();
|
|
237
|
+
_this.notify(_this.config.name, 'completed');
|
|
238
|
+
}
|
|
239
|
+
} catch (err) {
|
|
240
|
+
$.log.error("定时任务执行失败!", _this.config.name, err);
|
|
239
241
|
}
|
|
240
242
|
}
|
|
241
243
|
};
|
|
@@ -371,4 +373,4 @@ Drive.prototype.dispose = function() {
|
|
|
371
373
|
this.timeout = undefined;
|
|
372
374
|
};
|
|
373
375
|
|
|
374
|
-
module.exports = Drive;
|
|
376
|
+
module.exports = Drive;
|
package/core/com/timer/com.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_os",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.6",
|
|
4
4
|
"description": "这是超级美眉服务端框架,用于快速构建应用程序。",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"mm_expand": "^1.7.4",
|
|
41
41
|
"mm_html": "^1.1.6",
|
|
42
42
|
"mm_koa_proxy": "^1.0.0",
|
|
43
|
-
"mm_logs": "^1.1.
|
|
44
|
-
"mm_machine": "^1.
|
|
43
|
+
"mm_logs": "^1.1.5",
|
|
44
|
+
"mm_machine": "^1.8.1",
|
|
45
45
|
"mm_mongodb": "^1.4.2",
|
|
46
46
|
"mm_mqtt": "^1.0.6",
|
|
47
|
-
"mm_mysql": "^1.8.
|
|
47
|
+
"mm_mysql": "^1.8.5",
|
|
48
48
|
"mm_redis": "^1.4.2",
|
|
49
49
|
"mm_ret": "^1.3.9",
|
|
50
50
|
"mm_session": "^1.4.8",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|