mm_os 2.7.1 → 2.7.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.
@@ -0,0 +1,7 @@
1
+ {
2
+ "appId": "",
3
+ "AppSecret": "ufQBwiUG2oaM9wjWJ6tgUI6uiWK9yncR1",
4
+ "token": "w14e85M4Mj6egshfKc3wADq1KMP87Qi3",
5
+ "intents": "",
6
+ "sandbox": false
7
+ }
@@ -34,6 +34,7 @@ class MQTT extends Index {
34
34
  publish_qos: 1,
35
35
  username: "de",
36
36
  password: "asd123",
37
+ table: "iot_device",
37
38
  clean: false,
38
39
  longtime: 15000,
39
40
  // 在线有效期时长判断 单位:毫秒,150000毫秒为2.5分钟
@@ -428,7 +429,7 @@ MQTT.prototype.save_online = async function(arr, online = 1) {
428
429
  var sql = $.mysql_admin('sys');
429
430
  sql.open();
430
431
  var db = sql.db();
431
- db.table = "face_device";
432
+ db.table = this.config.table || "iot_device";
432
433
  db.size = 0;
433
434
  var query = {};
434
435
  if (arr) {
@@ -444,7 +445,7 @@ MQTT.prototype.get_drives = async function() {
444
445
  var sql = $.mysql_admin('sys');
445
446
  sql.open();
446
447
  var db = sql.db();
447
- db.table = "face_device";
448
+ db.table = this.config.table || "iot_device";
448
449
  db.size = 0;
449
450
  return await db.get({}, "", "clientid, online");
450
451
  }
@@ -66,6 +66,8 @@ class Drive extends Item {
66
66
  // 配置
67
67
  "options": []
68
68
  };
69
+ // 配置
70
+ this.options = {};
69
71
  }
70
72
  }
71
73
 
@@ -74,7 +76,9 @@ class Drive extends Item {
74
76
  * @param {Object} config 配置
75
77
  */
76
78
  Drive.prototype.set_config = function(config) {
77
- this.config = conf(Object.assign({}, this.config, config || {}), this.filename);
79
+ var file = this.filename;
80
+ var cg = Object.assign({}, this.config, config || {});
81
+ this.config = conf(cg, file);
78
82
  this.set_config_after();
79
83
  }
80
84
 
@@ -88,6 +92,9 @@ Drive.prototype.set_config_after = function() {
88
92
  this.log = new Log({
89
93
  filename
90
94
  });
95
+ var options = this.get_config_options();
96
+ this.options = this.merge_options(options);
97
+ this.backup_options();
91
98
  }
92
99
 
93
100
  /**
@@ -114,7 +121,6 @@ Drive.prototype.update_options = function(options = []) {
114
121
  Object.assign(obj, o);
115
122
  } else {
116
123
  list.push(o);
117
- // options.splice(i, 1);
118
124
  }
119
125
  }
120
126
  for (var i = 0; i < options.length; i++) {
@@ -138,6 +144,14 @@ Drive.prototype.update_options_after = function(options) {
138
144
  * @return {Object} 返回配置参数
139
145
  */
140
146
  Drive.prototype.get_options = function() {
147
+ return this.options;
148
+ }
149
+
150
+ /**
151
+ * 获取配置参数
152
+ * @return {Object} 返回配置参数
153
+ */
154
+ Drive.prototype.get_config_options = function() {
141
155
  var op = this.config.options || [];
142
156
  var dict = {};
143
157
  for (var i = 0; i < op.length; i++) {
@@ -148,8 +162,12 @@ Drive.prototype.get_options = function() {
148
162
  } else if (o.type === "boolean") {
149
163
  var val = false;
150
164
  if (o.value) {
151
- if (o.value == '1' || o.value == 'true') {
152
- val = true;
165
+ if (typeof(o.value) == "string") {
166
+ if (o.value == '1' || o.value == 'true') {
167
+ val = true;
168
+ }
169
+ } else if (typeof(o.value) == "boolean") {
170
+ val = o.value;
153
171
  }
154
172
  }
155
173
  dict[o.name] = val;
@@ -161,6 +179,8 @@ Drive.prototype.get_options = function() {
161
179
  dict[o.name] = o.value.toJSON();
162
180
  } else if (o.value === "null") {
163
181
  dict[o.name] = null;
182
+ } else if (o.type === "string") {
183
+ dict[o.name] = o.value || "";
164
184
  } else {
165
185
  dict[o.name] = o.value;
166
186
  }
@@ -168,6 +188,64 @@ Drive.prototype.get_options = function() {
168
188
  return dict;
169
189
  }
170
190
 
191
+ /**
192
+ * 获取配置参数
193
+ * @param {Object} 设置配置
194
+ * @return {Object} 返回配置参数
195
+ */
196
+ Drive.prototype.design_option = function(body) {
197
+ var cg = this.config;
198
+ if (Array.isArray(body)) {
199
+ cg.options = body;
200
+ } else {
201
+ var options = cg.options || [];
202
+ var option = options.getObj({
203
+ name: body.name
204
+ });
205
+ if (option) {
206
+ Object.assign(option, body);
207
+ } else {
208
+ options.push(body);
209
+ }
210
+ cg.options = options;
211
+ }
212
+ }
213
+
214
+ /**
215
+ * 保存配置
216
+ */
217
+ Drive.prototype.save_option = function(options) {
218
+ this.options = options;
219
+ this.backup_options();
220
+ }
221
+
222
+ /**
223
+ * 保存配置
224
+ */
225
+ Drive.prototype.backup_options = function() {
226
+ var l = $.slash;
227
+ var file = "/cache/" + l + l + this.filename.right("app" + l).replaceAll(l + "plugin", "").replace(".json",
228
+ "/config.json");
229
+ file = file.fullname();
230
+ file.addDir();
231
+ file.saveJson(this.options);
232
+ }
233
+
234
+ /**
235
+ * 合并配置
236
+ * @param {Object} cg 配置
237
+ */
238
+ Drive.prototype.merge_options = function(options) {
239
+ var l = $.slash;
240
+ var file = "/cache/" + l + l + this.filename.right("app" + l).replaceAll(l + "plugin", "").replace(".json",
241
+ "/config.json");
242
+ var options_cache = file.loadJson();
243
+ if (options_cache) {
244
+ $.push(options, options_cache);
245
+ }
246
+ return options;
247
+ }
248
+
171
249
  /**
172
250
  * 新建脚本
173
251
  * @param {String} 文件
@@ -48,7 +48,7 @@ async function main(ctx, db) {
48
48
  // var plus = $.plugin_admin('test');
49
49
  // plus.run("main", "start");
50
50
  // plus.run("main", "stop");
51
- // var ret = await this.sql.run(query, body, db);
51
+ var ret = await this.sql.run(query, body, db);
52
52
  return ret;
53
53
  };
54
54
 
@@ -72,7 +72,9 @@
72
72
  // MQTT服务器密码
73
73
  "password": "asd123",
74
74
  // MQTT端口号
75
- "port": 1883
75
+ "port": 1883,
76
+ // 连接的数据表
77
+ "table": "face_device"
76
78
  },
77
79
  "mysql": {
78
80
  // 服务器地址
@@ -72,7 +72,10 @@
72
72
  "username": "server",
73
73
  // MQTT服务器密码
74
74
  "password": "asd123",
75
- "port": 1883
75
+ // MQTT端口号
76
+ "port": 1883,
77
+ // 连接的数据表
78
+ "table": "face_device"
76
79
  },
77
80
  "mysql": {
78
81
  // 服务器地址
@@ -104,6 +104,7 @@ module.exports = function(server, config) {
104
104
  num
105
105
  }), duration);
106
106
  ctx.request.ip = ip;
107
+ ctx.ip = ip;
107
108
  await next();
108
109
  } else {
109
110
  ctx.status = 429;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_os",
3
- "version": "2.7.1",
3
+ "version": "2.7.2",
4
4
  "description": "这是超级美眉服务端框架,用于快速构建应用程序。",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -44,7 +44,7 @@
44
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.8",
47
+ "mm_mysql": "^1.8.9",
48
48
  "mm_os": "^2.6.4",
49
49
  "mm_redis": "^1.4.2",
50
50
  "mm_ret": "^1.3.9",