total5 0.0.9-1 → 0.0.9-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.
package/builders.js CHANGED
@@ -47,11 +47,6 @@ Options.prototype = {
47
47
  this.payload = value;
48
48
  },
49
49
 
50
- get hostname() {
51
- let ctrl = this.controller;
52
- return ctrl ? ((ctrl.protocol || 'https') + '://' + ctrl.headers.host) : null;
53
- },
54
-
55
50
  get url() {
56
51
  return (this.controller ? this.controller.url : '') || '';
57
52
  },
@@ -105,6 +100,11 @@ Options.prototype = {
105
100
  }
106
101
  };
107
102
 
103
+ Options.prototype.hostname = function(path) {
104
+ let ctrl = this.controller;
105
+ return ctrl ? ctrl.hostname(path) : path;
106
+ };
107
+
108
108
  Options.prototype.unauthorized = function() {
109
109
  var args = [this];
110
110
  for (let i = 0; i < arguments.length; i++)
package/changelog.txt CHANGED
@@ -5,6 +5,12 @@
5
5
  - added missing method `NEWMIDDLEWARE()`
6
6
  - fixed parsing `user-agent`
7
7
  - fixed `Message-ID` generator for email messages
8
+ - improved `Number.round()` by [Tomáš Novák](https://github.com/tomee03)
9
+ - added missing `$.hostname()` method in the `WebSocketController`
10
+ - added missing `$.address` property in the `WebSocketController`
11
+ - replaced `$.hostname` property with a method in the Schema/Auth Options
12
+ - __critital__ fixed cloning buffers in the `FlowStream`
13
+ - improved user-agent parser
8
14
 
9
15
  ========================
10
16
  0.0.8
package/controller.js CHANGED
@@ -143,7 +143,9 @@ Controller.prototype = {
143
143
  get ua() {
144
144
  if (this.$ua != null)
145
145
  return this.$ua;
146
- this.$ua = F.TUtils.parseUA(this.headers);
146
+ this.$ua = this.headers['user-agent'] || '';
147
+ if (this.$ua)
148
+ this.$ua = this.$ua.parseUA();
147
149
  return this.$ua;
148
150
  },
149
151
 
package/edit.js CHANGED
@@ -62,14 +62,11 @@ exports.init = function(url, dir) {
62
62
  });
63
63
 
64
64
  client.on('open', function() {
65
- console.log(new Date().toString('yyyy-MM-dd HH:mm:ss'), 'open');
66
65
  client.send({ TYPE: 'init', version: VERSION });
67
66
  });
68
67
 
69
68
  client.on('close', function(e) {
70
69
 
71
- console.log(new Date().toString('yyyy-MM-dd HH:mm:ss'), 'closed', e);
72
-
73
70
  initilaized = false;
74
71
 
75
72
  if (e === 4004) {
@@ -88,7 +85,6 @@ exports.init = function(url, dir) {
88
85
  });
89
86
 
90
87
  client.on('error', function(err) {
91
- console.log(new Date().toString('yyyy-MM-dd HH:mm:ss'), 'error', err);
92
88
  console.log(HEADER + ':', err.message);
93
89
  });
94
90
 
package/flowstream.js CHANGED
@@ -438,14 +438,8 @@ MP.send = function(outputindex, data, clonedata) {
438
438
  if (data != undefined)
439
439
  message.data = data;
440
440
 
441
- if (clonedata && message.data && typeof(message.data) === 'object') {
442
- if (message.data instanceof Buffer) {
443
- let buf = Buffer.alloc(message.data.length);
444
- buf.copy(message.data);
445
- message.data = buf;
446
- } else
447
- message.data = F.TUtils.clone(message.data);
448
- }
441
+ if (clonedata && message.data && typeof(message.data) === 'object')
442
+ message.data = message.data instanceof Buffer ? Buffer.from(message.data) : F.TUtils.clone(message.data);
449
443
 
450
444
  message.used++;
451
445
  message.instance = schema;
@@ -1120,14 +1114,8 @@ FP.ontrigger = function(outputindex, data, controller, events) {
1120
1114
  message.used = 1;
1121
1115
  }
1122
1116
 
1123
- if (i && (self.cloning != false) && message.data && typeof(message.data) === 'object') {
1124
- if (message.data instanceof Buffer) {
1125
- var buf = Buffer.alloc(message.data.length);
1126
- buf.copy(message.data);
1127
- message.data = buf;
1128
- } else
1129
- message.data = F.TUtils.clone(message.data);
1130
- }
1117
+ if (i && (self.cloning != false) && message.data && typeof(message.data) === 'object')
1118
+ message.data = message.data instanceof Buffer ? Buffer.from(message.data) : F.TUtils.clone(message.data);
1131
1119
 
1132
1120
  message.main = self;
1133
1121
  message.controller = controller;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "total5",
3
- "version": "0.0.9-1",
3
+ "version": "0.0.9-3",
4
4
  "description": "Total.js framework v5",
5
5
  "main": "index.js",
6
6
  "directories": {
package/utils.js CHANGED
@@ -75,6 +75,10 @@ const REG_HEADERPARSER = /(name|filename)=".*?"|content-type:\s[a-z0-9-./+]+/ig;
75
75
  const HEADEREND = Buffer.from('\r\n\r\n', 'ascii');
76
76
  const JSCHEMAS_NULLABLE = { json: 1, base64: 1, guid: 1, datauri: 1, uid: 1, string2: 1 };
77
77
 
78
+ const ARR_UA_OS = ['android', 'windows', 'ios', 'iphone', 'ubuntu', 'fedora', 'linux', 'mac os'];
79
+ const ARR_UA_BROWSER = ['xbox', 'playstation', 'nintendo', 'appletv', 'fxios', 'opera', 'edge', 'vivaldi', 'chrome', 'firefox', 'kindle', 'safari'];
80
+ const REG_UA_MOBILE = /iphone|android|mobile/i;
81
+
78
82
  exports.MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
79
83
  exports.DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
80
84
 
@@ -1587,18 +1591,7 @@ exports.filestreamer = function(filename, onbuffer, onend, size) {
1587
1591
 
1588
1592
  exports.parseUA = function(headers, structured) {
1589
1593
  let ua = (headers['user-agent'] || '');
1590
- if (ua) {
1591
- return ua ? ua.parseUA(structured) : ua;
1592
- } else {
1593
- ua = headers['sec-ch-ua'];
1594
- let platform = headers['sec-ch-ua-platform'] || '';
1595
- let mobile = headers['sec-ch-ua-mobile'] === '?1';
1596
- let index = ua.indexOf('";v');
1597
- let browser = ua.substring(1, index);
1598
- if (platform)
1599
- platform = platform.substring(1, platform.length - 1);
1600
- return structured ? { os: platform, browser: browser, device: mobile ? 'mobile' : 'desktop' } : ((platform ? (platform + ' ') : '') + browser + (mobile ? ' Mobile' : ''));
1601
- }
1594
+ return ua ? ua.parseUA(structured) : structured ? {} : ua;
1602
1595
  };
1603
1596
 
1604
1597
  exports.parseInt = function(obj, def) {
@@ -2689,165 +2682,36 @@ SP.parseUA = function(structured) {
2689
2682
  if (!ua)
2690
2683
  return '';
2691
2684
 
2692
- var arr = ua.match(REG_UA);
2693
- var uid = '';
2694
-
2695
- if (arr) {
2696
-
2697
- var data = {};
2698
-
2699
- for (var i = 0; i < arr.length; i++) {
2685
+ let lowered = ua.toLowerCase();
2686
+ let os = '';
2687
+ let device = '';
2688
+ let browser = '';
2700
2689
 
2701
- if (arr[i] === 'like' && arr[i + 1] === 'Gecko') {
2702
- i += 1;
2703
- continue;
2704
- }
2705
-
2706
- var key = arr[i].toLowerCase();
2707
- if (key === 'like')
2708
- break;
2690
+ for (let m of ARR_UA_OS) {
2691
+ let index = lowered.indexOf(m);
2692
+ if (index !== -1) {
2693
+ os = ua.substring(index, index + m.length);
2694
+ break;
2695
+ }
2696
+ }
2709
2697
 
2710
- switch (key) {
2711
- case 'linux':
2712
- case 'windows':
2713
- case 'mac':
2714
- case 'symbian':
2715
- case 'symbos':
2716
- case 'tizen':
2717
- case 'android':
2718
- data[arr[i]] = 2;
2719
- if (key === 'tizen' || key === 'android')
2720
- data.Mobile = 1;
2721
- break;
2722
- case 'webos':
2723
- data.WebOS = 2;
2724
- break;
2725
- case 'media':
2726
- case 'center':
2727
- case 'tv':
2728
- case 'smarttv':
2729
- case 'smart':
2730
- data[arr[i]] = 5;
2731
- break;
2732
- case 'iemobile':
2733
- case 'mobile':
2734
- data[arr[i]] = 1;
2735
- data.Mobile = 3;
2736
- break;
2737
- case 'ipad':
2738
- case 'ipod':
2739
- case 'iphone':
2740
- data.iOS = 2;
2741
- data.Mobile = 3;
2742
- data[arr[i]] = 1;
2743
- if (key === 'ipad')
2744
- data.Tablet = 4;
2745
- break;
2746
- case 'phone':
2747
- data.Mobile = 3;
2748
- break;
2749
- case 'tizenbrowser':
2750
- case 'blackberry':
2751
- case 'mini':
2752
- data.Mobile = 3;
2753
- data[arr[i]] = 1;
2754
- break;
2755
- case 'samsungbrowser':
2756
- case 'chrome':
2757
- case 'firefox':
2758
- case 'msie':
2759
- case 'opera':
2760
- case 'brave':
2761
- case 'vivaldi':
2762
- case 'outlook':
2763
- case 'safari':
2764
- case 'mail':
2765
- case 'edge':
2766
- case 'maxthon':
2767
- case 'electron':
2768
- data[arr[i]] = 1;
2769
- break;
2770
- case 'trident':
2771
- data.MSIE = 1;
2772
- break;
2773
- case 'opr':
2774
- data.Opera = 1;
2698
+ for (let m of ARR_UA_BROWSER) {
2699
+ let index = lowered.lastIndexOf(m);
2700
+ if (index !== -1) {
2701
+ switch (m) {
2702
+ case 'fxios':
2703
+ browser = 'Firefox';
2775
2704
  break;
2776
- case 'tablet':
2777
- data.Tablet = 4;
2705
+ default:
2706
+ browser = ua.substring(index, index + m.length);
2778
2707
  break;
2779
2708
  }
2709
+ break;
2780
2710
  }
2781
-
2782
- if (data.MSIE) {
2783
- data.IE = 1;
2784
- delete data.MSIE;
2785
- }
2786
-
2787
- if (data.WebOS || data.Android)
2788
- delete data.Linux;
2789
-
2790
- if (data.IEMobile) {
2791
- if (data.Android)
2792
- delete data.Android;
2793
- if (data.Safari)
2794
- delete data.Safari;
2795
- if (data.Chrome)
2796
- delete data.Chrome;
2797
- } else if (data.MSIE) {
2798
- if (data.Chrome)
2799
- delete data.Chrome;
2800
- if (data.Safari)
2801
- delete data.Safari;
2802
- } else if (data.Edge) {
2803
- if (data.Chrome)
2804
- delete data.Chrome;
2805
- if (data.Safari)
2806
- delete data.Safari;
2807
- } else if (data.Opera || data.Electron) {
2808
- if (data.Chrome)
2809
- delete data.Chrome;
2810
- if (data.Safari)
2811
- delete data.Safari;
2812
- } else if (data.Chrome) {
2813
- if (data.Safari)
2814
- delete data.Safari;
2815
- if (data.SamsungBrowser)
2816
- delete data.SamsungBrowser;
2817
- } else if (data.SamsungBrowser) {
2818
- if (data.Safari)
2819
- delete data.Safari;
2820
- }
2821
-
2822
- if (structured) {
2823
- var output = { os: '', browser: '', device: 'desktop' };
2824
-
2825
- if (data.Tablet)
2826
- output.device = 'tablet';
2827
- else if (data.Mobile)
2828
- output.device = 'mobile';
2829
-
2830
- for (var key in data) {
2831
- var val = data[key];
2832
- switch (val) {
2833
- case 1:
2834
- output.browser += (output.browser ? ' ' : '') + key;
2835
- break;
2836
- case 2:
2837
- output.os += (output.os ? ' ' : '') + key;
2838
- break;
2839
- case 5:
2840
- output.device = 'tv';
2841
- break;
2842
- }
2843
- }
2844
- return output;
2845
- }
2846
-
2847
- uid = Object.keys(data).join(' ');
2848
2711
  }
2849
2712
 
2850
- return uid;
2713
+ device = REG_UA_MOBILE.test(lowered) ? 'mobile' : 'desktop';
2714
+ return structured ? { os, browser, device } : ((os ? (os + ' ') : '') + (browser ? (browser + ' ') : '')).trim();
2851
2715
  };
2852
2716
 
2853
2717
  SP.parseCSV = function(delimiter) {
@@ -4230,8 +4094,8 @@ NP.padRight = function(max, c) {
4230
4094
  };
4231
4095
 
4232
4096
  NP.round = function(precision) {
4233
- var m = Math.pow(10, precision) || 1;
4234
- return Math.round(this * m) / m;
4097
+ var m = Math.round(this + 'e' + precision);
4098
+ return Number(m + 'e-' + precision);
4235
4099
  };
4236
4100
 
4237
4101
  NP.currency = function(currency, a, b, c) {
package/websocket.js CHANGED
@@ -48,6 +48,7 @@ function Controller(req, socket, head) {
48
48
  ctrl.current = {};
49
49
  ctrl.masking = false;
50
50
  ctrl.iswebsocket = true;
51
+ ctrl.protocol = req.connection.encrypted || req.headers['x-forwarded-ssl'] === 'on' || req.headers['x-forwarded-port'] === '443' || (req.headers['x-forwarded-proto'] || req.headers['x-forwarded-protocol']) === 'https' ? 'https' : 'http';
51
52
 
52
53
  for (let path of ctrl.split)
53
54
  ctrl.split2.push(path.toLowerCase());
@@ -70,7 +71,9 @@ Controller.prototype = {
70
71
  get ua() {
71
72
  if (this.$ua != null)
72
73
  return this.$ua;
73
- this.$ua = F.TUtils.parseUA(this.headers);
74
+ this.$ua = this.headers['user-agent'] || '';
75
+ if (this.$ua)
76
+ this.$ua = this.$ua.parseUA();
74
77
  return this.$ua;
75
78
  },
76
79
 
@@ -91,6 +94,14 @@ Controller.prototype = {
91
94
 
92
95
  get referrer() {
93
96
  return this.headers.referer;
97
+ },
98
+
99
+ get host() {
100
+ return this.headers.host;
101
+ },
102
+
103
+ get address() {
104
+ return (this.protocol + '://' + this.headers?.host || '') + (this.req?.url || '');
94
105
  }
95
106
 
96
107
  };
@@ -592,6 +603,11 @@ Controller.prototype.ping = function(ts) {
592
603
  return ctrl;
593
604
  };
594
605
 
606
+ Controller.prototype.hostname = function(path) {
607
+ var ctrl = this;
608
+ return ctrl.protocol + '://' + ctrl.headers.host + (path ? path : '');
609
+ };
610
+
595
611
  function websocketclientdestroy(ctrl) {
596
612
  ctrl.socket.destroy();
597
613
  F.TUtils.destroystream(ctrl.socket);