mm_os 2.5.1 → 2.5.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.
@@ -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) {
@@ -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
  };
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.2",
4
4
  "description": "这是超级美眉服务端框架,用于快速构建应用程序。",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -41,7 +41,7 @@
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
47
  "mm_mysql": "^1.8.1",