total5 0.0.16 → 0.0.17-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/changelog.txt CHANGED
@@ -1,3 +1,18 @@
1
+ ========================
2
+ 0.0.17
3
+ ========================
4
+
5
+ - fixed error handling in emails
6
+ - improved returing `origin` in the CORS
7
+ - fixed removing routes via `route.remove()` method
8
+ - fixed `beautify` and `replacer` arguments in the `controller.json()`
9
+ - fixed `mail` priority
10
+ - fixed `kB` and `GB` units in the routing as upload limits
11
+ - `DEBUG` is set according to the `process.env.NODE_ENV` variable
12
+ - fixed server pinging of all WebSocket connections
13
+ - improved code
14
+ - fixed typo in send method data assignment
15
+
1
16
  ========================
2
17
  0.0.16
3
18
  ========================
package/components.js CHANGED
@@ -233,7 +233,7 @@ Instance.prototype.input = function(input, data, callback) {
233
233
  Instance.prototype.send = function(output, data) {
234
234
  let msg = data instanceof Message ? data : this.newmessage();
235
235
  msg.output = output;
236
- msg.data = data;x
236
+ msg.data = data;
237
237
  msg.send(output);
238
238
  };
239
239
 
package/controller.js CHANGED
@@ -49,7 +49,6 @@ function Controller(req, res) {
49
49
  ctrl.split2.push(path.toLowerCase());
50
50
 
51
51
  ctrl.params = {};
52
- ctrl.query = ctrl.uri.search.parseEncoded();
53
52
  ctrl.files = [];
54
53
  ctrl.body = {};
55
54
 
@@ -173,7 +172,7 @@ Controller.prototype = {
173
172
  },
174
173
 
175
174
  get address() {
176
- return (this.protocol + '://' + this.headers?.host || '') + (this.req?.url || '');
175
+ return this.protocol + '://' + (this.headers?.host || '') + (this.req?.url || '');
177
176
  }
178
177
 
179
178
  };
@@ -300,7 +299,7 @@ Controller.prototype.json = function(value, beautify, replacer) {
300
299
  response.headers['cache-control'] = NOCACHE;
301
300
  response.headers.vary = 'Accept-Encoding, Last-Modified, User-Agent';
302
301
  response.headers.expires = '-1';
303
- response.value = JSON.stringify(value, beautify ? '\t' : null, replacer);
302
+ response.value = JSON.stringify(value, replacer, beautify ? '\t' : null);
304
303
  ctrl.flush();
305
304
  F.stats.response.json++;
306
305
  };
package/http.js CHANGED
@@ -27,7 +27,7 @@ exports.listen = function(req, res) {
27
27
  return;
28
28
  }
29
29
 
30
- if (F.config.$blacklist && F.config.$blacklist.indexOf(ctrl.ip) !== -1) {
30
+ if (F.config.$blacklist && F.config.$blacklist.includes(ctrl.ip)) {
31
31
  F.stats.request.blocked++;
32
32
  ctrl.fallback(400, 'IP address is blocked');
33
33
  return;
package/index.js CHANGED
@@ -23,7 +23,7 @@ Object.freeze(EMPTYARRAY);
23
23
 
24
24
  // Globals
25
25
  global.F = global.Total = {};
26
- global.DEBUG = true;
26
+ global.DEBUG = process.env.NODE_ENV !== 'production';
27
27
  global.CONF = {};
28
28
  global.REPO = {};
29
29
  global.MAIN = {};
@@ -38,7 +38,7 @@ global.DEF = {};
38
38
 
39
39
  F.id = '';
40
40
  F.clusterid = '';
41
- F.is5 = F.version = 5016;
41
+ F.is5 = F.version = 5017;
42
42
  F.isBundle = false;
43
43
  F.isLoaded = false;
44
44
  F.version_header = '5';
@@ -1148,10 +1148,10 @@ F.console = function() {
1148
1148
  if (!F.config.$imprint)
1149
1149
  return;
1150
1150
 
1151
- var memory = process.memoryUsage();
1152
- var nodemodules = require.resolve('./index');
1151
+ let memory = process.memoryUsage();
1152
+ let nodemodules = require.resolve('./index');
1153
1153
 
1154
- nodemodules = nodemodules.substring(0, nodemodules.length - (8 + 7));
1154
+ nodemodules = F.Path.dirname(nodemodules);
1155
1155
 
1156
1156
  print('====================================================');
1157
1157
  print('PID : ' + process.pid);
@@ -1171,19 +1171,19 @@ F.console = function() {
1171
1171
  // global.THREAD && print('Thread : ' + global.THREAD);
1172
1172
  print('====================================================');
1173
1173
  F.config.$root && print('Root : ' + F.config.$root);
1174
- print('Directory : ' + process.cwd());
1175
- print('node_modules : ' + nodemodules);
1174
+ print('Directory : ' + F.Path.join(process.cwd(), F.Path.sep));
1175
+ print('node_modules : ' + F.Path.join(nodemodules, F.Path.sep));
1176
1176
  print('====================================================\n');
1177
1177
 
1178
1178
  if (!F.isWorker && F.server) {
1179
1179
 
1180
- var hostname = F.unixsocket ? ('Socket: ' + F.unixsocket) : '{2}://{0}:{1}/'.format(F.config.$ip, F.config.$port, F.isHTTPS ? 'https' : 'http');
1180
+ let hostname = F.unixsocket ? ('Socket: ' + F.unixsocket) : '{2}://{0}:{1}/'.format(F.config.$ip, F.config.$port, F.isHTTPS ? 'https' : 'http');
1181
1181
 
1182
1182
  if (!F.unixsocket && F.ip === '0.0.0.0') {
1183
- var ni = F.Os.networkInterfaces();
1183
+ let ni = F.Os.networkInterfaces();
1184
1184
  if (ni.en0) {
1185
- for (var i = 0; i < ni.en0.length; i++) {
1186
- var nii = ni.en0[i];
1185
+ for (let i = 0; i < ni.en0.length; i++) {
1186
+ let nii = ni.en0[i];
1187
1187
  // nii.family === 'IPv6' ||
1188
1188
  if (nii.family === 'IPv4') {
1189
1189
  hostname += '\n{2}://{0}:{1}/'.format(nii.address, F.port, F.isHTTPS ? 'https' : 'http');
@@ -1215,7 +1215,7 @@ F.loadservices = function() {
1215
1215
  flow.service(F.internal.ticks);
1216
1216
  }
1217
1217
 
1218
- if (F.internal.ticks == 6 || F.internal.ticks == 12)
1218
+ if (F.internal.ticks == 3 || F.internal.ticks == 6 || F.internal.ticks == 12)
1219
1219
  F.TWebSocket.ping();
1220
1220
 
1221
1221
  // 1 minute
package/mail.js CHANGED
@@ -212,7 +212,7 @@ Message.prototype.send2 = function(callback) {
212
212
  data.subject = self.subject;
213
213
  data.type = self.type;
214
214
  data.body = self.body;
215
- data.priority = self.$priotity;
215
+ data.priority = self.$priority;
216
216
  data.unsubscribe = self.$unsubscribe;
217
217
  data.confidential = self.$confidential;
218
218
 
@@ -486,9 +486,25 @@ Mailer.send = function(opt, messages, callback) {
486
486
  opt.port = 465;
487
487
 
488
488
  if (!opt.server) {
489
- var err = new Error('No SMTP server configuration.');
490
- callback && callback(err);
491
- F.error(err, 'mail_smtp');
489
+ const err = new Error('No SMTP server configuration.');
490
+ let iscallback = false;
491
+
492
+
493
+ if (callback) {
494
+ iscallback = true;
495
+ callback(err);
496
+ }
497
+
498
+ for (let m of obj.messages) {
499
+ if (m.$callback) {
500
+ iscallback = true;
501
+ m.$callback(err);
502
+ }
503
+ }
504
+
505
+ if (!iscallback)
506
+ F.error(err, 'mail_smtp');
507
+
492
508
  return self;
493
509
  }
494
510
 
@@ -529,8 +545,17 @@ Mailer.send = function(opt, messages, callback) {
529
545
  if (obj.try || err.stack.indexOf('ECONNRESET') !== -1)
530
546
  return;
531
547
 
532
- if (!obj.try && !is)
533
- F.error(err, 'mail_smtp', opt.server);
548
+ if (!obj.try && !is) {
549
+ let iscallback = false;
550
+ for (let m of obj.messages) {
551
+ if (m.$callback) {
552
+ iscallback = true;
553
+ m.$callback(err);
554
+ }
555
+ }
556
+ if (!iscallback)
557
+ F.error(err, 'mail_smtp', opt.server);
558
+ }
534
559
 
535
560
  if (obj === F.temporary.smtp[opt.server])
536
561
  delete F.temporary.smtp[opt.server];
@@ -542,8 +567,17 @@ Mailer.send = function(opt, messages, callback) {
542
567
 
543
568
  Mailer.destroy(obj);
544
569
 
545
- if (!obj.try && !obj.callback)
546
- F.error(err, 'mail_smtp', opt.server);
570
+ if (!obj.try && !obj.callback) {
571
+ let iscallback = false;
572
+ for (let m of obj.messages) {
573
+ if (m.$callback) {
574
+ iscallback = true;
575
+ m.$callback(err);
576
+ }
577
+ }
578
+ if (!iscallback)
579
+ F.error(err, 'mail_smtp', opt.server);
580
+ }
547
581
 
548
582
  obj.callback && obj.callback(err);
549
583
  obj.callback = null;
@@ -561,8 +595,17 @@ Mailer.send = function(opt, messages, callback) {
561
595
  var err = F.TUtils.httpstatus(408);
562
596
  Mailer.destroy(obj);
563
597
 
564
- if (!obj.try && !obj.callback)
565
- F.error(err, 'mail_smtp', opt.server);
598
+ if (!obj.try && !obj.callback) {
599
+ let iscallback = false;
600
+ for (let m of obj.messages) {
601
+ if (m.$callback) {
602
+ iscallback = true;
603
+ m.$callback(err);
604
+ }
605
+ }
606
+ if (!iscallback)
607
+ F.error(err, 'mail_smtp', opt.server);
608
+ }
566
609
 
567
610
  obj.callback && obj.callback(err);
568
611
  obj.callback = null;
@@ -850,11 +893,15 @@ Mailer.$send = function(obj, options, autosend) {
850
893
  obj.logged = true;
851
894
  Mailer.$writeline(obj, value);
852
895
  } else {
853
- var err = new Error('Forbidden.');
896
+ const err2 = new Error('Forbidden.');
854
897
  Mailer.destroy(obj);
855
- obj.callback && obj.callback(err);
898
+ obj.callback && obj.callback(err2);
856
899
  obj.callback = null;
857
- Mailer.$events.error && !obj.try && Mailer.emit('error', err, obj);
900
+ for (let m of obj.messages) {
901
+ if (m.$callback)
902
+ m.$callback(err2);
903
+ }
904
+ Mailer.$events.error && !obj.try && Mailer.emit('error', err2, obj);
858
905
  }
859
906
 
860
907
  return;
@@ -876,23 +923,34 @@ Mailer.$send = function(obj, options, autosend) {
876
923
  return;
877
924
  }
878
925
 
879
- var err = line;
926
+ const err = line;
927
+ let iscallback = false;
880
928
 
881
929
  Mailer.$events.error && !obj.try && Mailer.emit('error', err, obj);
882
930
 
883
931
  if (obj.messagecallback) {
932
+ iscallback = true;
884
933
  obj.messagecallback(err, obj.instance);
885
934
  obj.messagecallback = null;
886
935
  }
887
936
 
888
937
  if (obj.messagecallback2) {
938
+ iscallback = true;
889
939
  obj.messagecallback2(err, obj.instance);
890
940
  obj.messagecallback2 = null;
891
941
  }
892
942
 
893
943
  if (obj.messages.length) {
894
944
 
895
- F.error(err, 'SMTP error');
945
+ for (let m of obj.messages) {
946
+ if (m.$callback) {
947
+ iscallback = true;
948
+ m.$callback(err);
949
+ }
950
+ }
951
+
952
+ if (!iscallback)
953
+ F.error(err, 'SMTP error');
896
954
 
897
955
  // a problem
898
956
  obj.buffer = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "total5",
3
- "version": "0.0.16",
3
+ "version": "0.0.17-2",
4
4
  "description": "Total.js framework v5",
5
5
  "main": "index.js",
6
6
  "directories": {
package/routing.js CHANGED
@@ -37,12 +37,12 @@ function parseSizeTimeout(route, value) {
37
37
  route.size = number;
38
38
  break;
39
39
  case 'kb':
40
- number = number / 1024;
40
+ number = number * 1024;
41
41
  if (route.size < number)
42
42
  route.size = number;
43
43
  break;
44
44
  case 'gb':
45
- number = (number * 1024 * 1024) * 1000;
45
+ number = number * 1024 * 1024 * 1024;
46
46
  if (route.size < number)
47
47
  route.size = number;
48
48
  break;
@@ -321,14 +321,14 @@ Route.prototype.remove = function() {
321
321
  case 'websocket':
322
322
  index = F.routes.websockets.indexOf(self);
323
323
  if (index !== -1)
324
- F.routes.websockets.splice(index);
324
+ F.routes.websockets.splice(index, 1);
325
325
  for (let conn of self.connections)
326
326
  conn.destroy();
327
327
  break;
328
328
  case 'file':
329
329
  index = F.routes.files.indexOf(self);
330
330
  if (index !== -1)
331
- F.routes.files.splice(index);
331
+ F.routes.files.splice(index, 1);
332
332
  break;
333
333
  default:
334
334
  if (self.apiendpoint) {
@@ -337,14 +337,14 @@ Route.prototype.remove = function() {
337
337
  if (Object.keys(self.parent.api).length == 0) {
338
338
  index = F.routes.routes.indexOf(self.parent);
339
339
  if (index !== -1)
340
- F.routes.routes.splice(index);
340
+ F.routes.routes.splice(index, 1);
341
341
  }
342
342
  } else {
343
343
  delete self.api[self.apiendpoint];
344
344
  if (Object.keys(self.api).length == 0) {
345
345
  index = F.routes.routes.indexOf(self);
346
346
  if (index !== -1)
347
- F.routes.routes.splice(index);
347
+ F.routes.routes.splice(index, 1);
348
348
  }
349
349
  }
350
350
  } else {
@@ -645,7 +645,7 @@ exports.lookupcors = function(ctrl) {
645
645
  return false;
646
646
  }
647
647
 
648
- let origin = ctrl.headers.origin;
648
+ let origin = ctrl.headers.origin || '';
649
649
 
650
650
  if (F.config.$cors !== '*' && !origin.endsWith(ctrl.headers.host)) {
651
651
 
package/websocket.js CHANGED
@@ -605,10 +605,11 @@ Controller.prototype.senddeflate = function() {
605
605
  };
606
606
 
607
607
  Controller.prototype.ping = function(ts) {
608
- var ctrl = this;
608
+ let ctrl = this;
609
+ ctrl.$ping = ts || Date.now();
610
+ ctrl.latency = null;
609
611
  if (!ctrl.isclosed) {
610
612
  try {
611
- ctrl.$ping = ts || Date.now();
612
613
  ctrl.socket.write(getWebSocketFrame(0, 'PING', 0x09, false, ctrl.masking));
613
614
  } catch (e) {
614
615
  // Socket error
@@ -1366,10 +1367,10 @@ WebSocketClient.prototype.connectforce = function(self, url, protocol, origin) {
1366
1367
 
1367
1368
  WebSocketClient.prototype.ping = function(timeout) {
1368
1369
  var self = this;
1370
+ self.$ping = Date.now();
1369
1371
  if (!self.isclosed && !self.timeout) {
1370
1372
  self.timeout = setTimeout(wsclient_timeout, timeout || 3000, self);
1371
1373
  self.socket.write(getWebSocketFrame(0, 'PING', 0x09, false, self.options.masking));
1372
- self.$ping = Date.now();
1373
1374
  }
1374
1375
  return self;
1375
1376
  };