mm_os 2.5.1 → 2.5.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.
@@ -76,7 +76,7 @@ Cmd.prototype.run = async function(msg, db, table) {
76
76
 
77
77
  var lt = this.list_before;
78
78
  for (var i = 0, o; o = lt[i++];) {
79
- if (o.onOff) {
79
+ if (o.config.state === 1) {
80
80
  try {
81
81
  ret = await o.run_cmd(msg, db);
82
82
  } catch (error) {
@@ -123,7 +123,7 @@ Cmd.prototype.run = async function(msg, db, table) {
123
123
  if (!ret) {
124
124
  var lt = this.list_main;
125
125
  for (var i = 0, o; o = lt[i++];) {
126
- if (o.onOff) {
126
+ if (o.config.state === 1) {
127
127
  try {
128
128
  ret = await o.run_first(msg, db);
129
129
  } catch (error) {
@@ -138,7 +138,7 @@ Cmd.prototype.run = async function(msg, db, table) {
138
138
  if (!ret) {
139
139
  var lt = this.list_after;
140
140
  for (var i = 0, o; o = lt[i++];) {
141
- if (o.onOff) {
141
+ if (o.config.state === 1) {
142
142
  try {
143
143
  ret = await o.run_first(msg, db);
144
144
  } catch (error) {
@@ -143,11 +143,11 @@ Eventer.prototype.do_after = function() {
143
143
  /**
144
144
  * 执行事件
145
145
  */
146
- Eventer.prototype.doing = async function(o, msg) {
146
+ Eventer.prototype.doing = async function(o, ...msg) {
147
147
  o.num++;
148
148
  var ret;
149
149
  try {
150
- ret = o.func(msg, o.param, o.num);
150
+ ret = o.func(...msg, o.param, o.num);
151
151
  if (types.isPromise(ret)) {
152
152
  ret = await ret;
153
153
  }
@@ -167,10 +167,10 @@ Eventer.prototype.doing = async function(o, msg) {
167
167
  * 运行事件
168
168
  * @param {Array} list 列表
169
169
  * @param {String} type 类型
170
- * @param {Object} msg 事件消息
171
170
  * @param {Boolean} isBreak 是否中断
171
+ * @param {Object} msg 事件消息
172
172
  */
173
- Eventer.prototype.run_sub = async function(list, msg, isBreak = false) {
173
+ Eventer.prototype.run_sub = async function(list, isBreak, ...msg) {
174
174
  var ret;
175
175
  if (list) {
176
176
  for (var i = 0; i < list.length; i++) {
@@ -179,7 +179,7 @@ Eventer.prototype.run_sub = async function(list, msg, isBreak = false) {
179
179
  if (o.state == 1) {
180
180
  // 判断是否还需要执行
181
181
  if (o.count < 0 || o.num < o.count) {
182
- ret = await this.doing(o, msg);
182
+ ret = await this.doing(o, ...msg);
183
183
  if (ret && isBreak) {
184
184
  break;
185
185
  }
@@ -201,19 +201,19 @@ Eventer.prototype.run_sub = async function(list, msg, isBreak = false) {
201
201
  * @param {String} type 类型
202
202
  * @param {Object} msg 事件消息
203
203
  */
204
- Eventer.prototype.run = async function(type, msg) {
204
+ Eventer.prototype.run = async function(type, ...msg) {
205
205
  this.do_before();
206
206
  var ret;
207
207
  var dt = this.dict[type];
208
208
  if (dt) {
209
- ret = await this.run_sub(dt.before, msg, false);
210
- ret = await this.run_sub(dt.check, msg, true);
209
+ ret = await this.run_sub(dt.before, false, ...msg);
210
+ ret = await this.run_sub(dt.check, true, ...msg);
211
211
  if (ret) {
212
212
  return ret
213
213
  }
214
- ret = await this.run_sub(dt.main, msg, false);
214
+ ret = await this.run_sub(dt.main, false, ...msg);
215
215
  if (ret) {
216
- var ret_new = await this.run_sub(dt.after, msg, false);
216
+ var ret_new = await this.run_sub(dt.after, false, ...msg);
217
217
  ret = ret_new || ret;
218
218
  }
219
219
  }
@@ -305,6 +305,18 @@ Drive.prototype.pushS = function(clientid, msg, longtime) {
305
305
  });
306
306
  }
307
307
 
308
+ /**
309
+ *
310
+ * @param {Object} clientid
311
+ * @param {Object} online
312
+ * @param {Object} ip
313
+ */
314
+ Drive.prototype.save_online = async function(clientid, online, ip) {
315
+ if (!clientid) {
316
+
317
+ }
318
+ }
319
+
308
320
  /**
309
321
  * 更新设备在线
310
322
  * @param {String} clientid 客户端ID
@@ -126,28 +126,30 @@ MQTT.prototype.update_after = function() {
126
126
  var _this = this;
127
127
  var list = this.list;
128
128
  for (var i = 0, o; o = list[i++];) {
129
- o.send = function(topic, msg, qos = 0, retain = false) {
130
- if (topic) {
131
- _this.send(topic, msg, qos, retain);
132
- }
133
- };
129
+ if (o.config.state === 1) {
130
+ o.send = function(topic, msg, qos = 0, retain = false) {
131
+ if (topic) {
132
+ _this.send(topic, msg, qos, retain);
133
+ }
134
+ };
134
135
 
135
- try {
136
- o.run('init');
137
- } catch (error) {
138
- $.log.error("MQTT类初始化失败", o.config.name, error);
139
- }
140
- var topics = o.config.topic;
141
- if (topics) {
142
- for (var i = 0; i < topics.length; i++) {
143
- var tc = topics[i];
144
- var retain = o.config.retain || false;
145
- var qos = o.config.qos || 0;
146
- if (tc.indexOf("heartbeat") !== -1) {
147
- retain = false;
148
- qos = 0;
136
+ try {
137
+ o.run('init');
138
+ } catch (error) {
139
+ $.log.error("MQTT类初始化失败", o.config.name, error);
140
+ }
141
+ var topics = o.config.topic;
142
+ if (topics) {
143
+ for (var i = 0; i < topics.length; i++) {
144
+ var tc = topics[i];
145
+ var retain = o.config.retain || false;
146
+ var qos = o.config.qos || 0;
147
+ if (tc.indexOf("heartbeat") !== -1) {
148
+ retain = false;
149
+ qos = 0;
150
+ }
151
+ this.subscribe(tc, null, qos, retain);
149
152
  }
150
- this.subscribe(tc, null, qos, retain);
151
153
  }
152
154
  }
153
155
  }
@@ -272,15 +274,17 @@ MQTT.prototype.receive = async function(push_topic, msg) {
272
274
  var ret;
273
275
  var list = this.list;
274
276
  for (var i = 0, o; o = list[i++];) {
275
- var topics = o.config.topic;
276
- if (topics) {
277
- for (var i = 0; i < topics.length; i++) {
278
- var topic = topics[i];
279
- if (this.match(push_topic, topic)) {
280
- try {
281
- ret = await o.run("main", push_topic, msg, topic, i);
282
- } catch (error) {
283
- $.log.error("MQTT执行失败", o.config.name, error);
277
+ if (o.config.state === 1) {
278
+ var topics = o.config.topic;
279
+ if (topics) {
280
+ for (var i = 0; i < topics.length; i++) {
281
+ var topic = topics[i];
282
+ if (this.match(push_topic, topic)) {
283
+ try {
284
+ ret = await o.run("main", push_topic, msg, topic, i);
285
+ } catch (error) {
286
+ $.log.error("MQTT执行失败", o.config.name, error);
287
+ }
284
288
  }
285
289
  }
286
290
  }
@@ -348,20 +348,4 @@ Drive.prototype.run_chat = async function(from_user, to_user, content, group, ty
348
348
  return ret;
349
349
  };
350
350
 
351
- /**
352
- * 执行程序
353
- * @param {Object} param1 参数1
354
- * @param {Object} param2 参数2
355
- * @return {Object} 返回执行结果
356
- */
357
- Drive.prototype.exec = function(func_name, option) {
358
- var msg = "";
359
- if (this[func_name]) {
360
- msg = this[func_name](option);
361
- } else {
362
- msg = "错误的操作";
363
- }
364
- return msg;
365
- };
366
-
367
351
  module.exports = Drive;
@@ -40,14 +40,16 @@ class Static extends Index {
40
40
  if (path.indexOf('.') !== -1) {
41
41
  for (var i = 0; i < len; i++) {
42
42
  var o = list[i];
43
- try {
44
- done = await o.run(ctx, path, next);
45
- } catch (error) {
46
- $.log.error("静态文件执行错误", o.config.name, error);
47
- }
48
-
49
- if (done) {
50
- break;
43
+ if (o.config.state === 1) {
44
+ try {
45
+ done = await o.run(ctx, path, next);
46
+ } catch (error) {
47
+ $.log.error("静态文件执行错误", o.config.name, error);
48
+ }
49
+
50
+ if (done) {
51
+ break;
52
+ }
51
53
  }
52
54
  }
53
55
  await next();
@@ -56,25 +58,27 @@ class Static extends Index {
56
58
  var q = ctx.request.querystring;
57
59
  for (var i = 0; i < len; i++) {
58
60
  var o = list[i];
59
- var p = o.config.path;
60
- if (path === p) {
61
- done = ' ';
62
- if (ctx.status === 404) {
63
- if (q) {
64
- ctx.redirect(p + '/?' + q);
65
- } else {
66
- ctx.redirect(p + '/');
61
+ if (o.config.state === 1) {
62
+ var p = o.config.path;
63
+ if (path === p) {
64
+ done = ' ';
65
+ if (ctx.status === 404) {
66
+ if (q) {
67
+ ctx.redirect(p + '/?' + q);
68
+ } else {
69
+ ctx.redirect(p + '/');
70
+ }
67
71
  }
68
- }
69
- break;
70
- } else {
71
- try {
72
- done = await o.run(ctx, path, next);
73
- } catch (error) {
74
- $.log.error("静态文件执行错误", o.config.name, error);
75
- }
76
- if (done) {
77
72
  break;
73
+ } else {
74
+ try {
75
+ done = await o.run(ctx, path, next);
76
+ } catch (error) {
77
+ $.log.error("静态文件执行错误", o.config.name, error);
78
+ }
79
+ if (done) {
80
+ break;
81
+ }
78
82
  }
79
83
  }
80
84
  }
@@ -29,7 +29,7 @@ Task.prototype.run = async function(name) {
29
29
  var lt = this.list;
30
30
  if (name) {
31
31
  for (var i = 0, o; o = lt[i++];) {
32
- if (o.name === name) {
32
+ if (o.config.state === 1 && o.config.name === name) {
33
33
  try {
34
34
  o.run();
35
35
  } catch (error) {
@@ -40,10 +40,12 @@ Task.prototype.run = async function(name) {
40
40
  }
41
41
  } else {
42
42
  for (var i = 0, o; o = lt[i++];) {
43
- try {
44
- o.run();
45
- } catch (error) {
46
- $.log.error("定时任务错误", o.name, error);
43
+ if (o.config.state === 1) {
44
+ try {
45
+ o.run();
46
+ } catch (error) {
47
+ $.log.error("定时任务错误", o.name, error);
48
+ }
47
49
  }
48
50
  }
49
51
  }
@@ -14,7 +14,7 @@ async function main(ctx, db) {
14
14
 
15
15
  var user = await this.get_state(ctx, db);
16
16
 
17
- console.log("用户", user);
17
+ // console.log("用户", user);
18
18
  // return "hello world" + JSON.stringify(body);
19
19
 
20
20
  // 操作sql模板
@@ -28,6 +28,9 @@ async function main(ctx, db) {
28
28
  } else {
29
29
 
30
30
  }
31
+ // var plus = $.plugin_admin('test');
32
+ // plus.run("main", "start");
33
+ // plus.run("main", "stop");
31
34
  var ret = await this.sql.run(query, body, db);
32
35
  return ret;
33
36
  };
@@ -203,8 +203,8 @@ Server.prototype.exec_log = async function(clientid, log) {
203
203
  */
204
204
  Server.prototype.check_device = async function(clientid, key) {
205
205
  var tip;
206
- var db2 = dbs.new("face_device", "device_id");
207
- var device = await db2.getObj({
206
+ var db_device = dbs.new("face_device", "device_id");
207
+ var device = await db_device.getObj({
208
208
  clientid
209
209
  });
210
210
  if (device) {
package/lib/app.js CHANGED
@@ -28,8 +28,8 @@ App.prototype.fullAction = function(action) {
28
28
  // 创建插件
29
29
  this.plugin = $.plugin_admin(action.key, action.title || action.name);
30
30
  this.plugin.update(action.jsonFile.dirname()).then(() => {
31
- this.plugin.exec(null, 'init').then(() => {
32
- this.plugin.exec(null, 'start');
31
+ this.plugin.run(null, 'init').then(() => {
32
+ this.plugin.run(null, 'start');
33
33
  });
34
34
  });
35
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_os",
3
- "version": "2.5.1",
3
+ "version": "2.5.3",
4
4
  "description": "这是超级美眉服务端框架,用于快速构建应用程序。",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -37,14 +37,14 @@
37
37
  "koa-websocket": "^7.0.0",
38
38
  "mm_check": "^1.4.8",
39
39
  "mm_excel": "^1.2.0",
40
- "mm_expand": "^1.7.3",
40
+ "mm_expand": "^1.7.4",
41
41
  "mm_html": "^1.1.6",
42
42
  "mm_koa_proxy": "^1.0.0",
43
43
  "mm_logs": "^1.1.4",
44
- "mm_machine": "^1.7.6",
44
+ "mm_machine": "^1.7.8",
45
45
  "mm_mongodb": "^1.4.2",
46
46
  "mm_mqtt": "^1.0.6",
47
- "mm_mysql": "^1.8.1",
47
+ "mm_mysql": "^1.8.3",
48
48
  "mm_redis": "^1.4.2",
49
49
  "mm_ret": "^1.3.9",
50
50
  "mm_session": "^1.4.8",