@iobroker/socket-classes 0.1.4 → 0.1.7

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/README.md CHANGED
@@ -69,6 +69,15 @@ io.close();
69
69
  -->
70
70
 
71
71
  ## Changelog
72
+ ### 0.1.7 (2022-05-05)
73
+ * (bluefox) Caught some sentry errors
74
+
75
+ ### 0.1.6 (2022-05-05)
76
+ * (bluefox) fixed `delObject` command
77
+
78
+ ### 0.1.5 (2022-04-25)
79
+ * (bluefox) added updateRatings
80
+
72
81
  ### 0.1.4 (2022-04-24)
73
82
  * (bluefox) added passportSocket
74
83
 
@@ -140,10 +140,12 @@ class SocketAdmin extends SocketCommon {
140
140
  stateChange(id, state) {
141
141
  this.commands.stateChange(id, state);
142
142
 
143
- this.server.sockets.connected.forEach(socket =>
144
- this.__updateSession(socket));
143
+ if (this.server && this.server.sockets) {
144
+ this.server.sockets.connected.forEach(socket =>
145
+ this.__updateSession(socket));
145
146
 
146
- this.server.sockets.emit('stateChange', id, state);
147
+ this.server.sockets.emit('stateChange', id, state);
148
+ }
147
149
  }
148
150
 
149
151
  repoUpdated() {
@@ -153,15 +155,17 @@ class SocketAdmin extends SocketCommon {
153
155
  }
154
156
 
155
157
  objectChange(id, obj) {
156
- const clients = this.server.sockets.connected;
158
+ if (this.server && this.server.sockets) {
159
+ const clients = this.server.sockets.connected;
157
160
 
158
- for (const i in clients) {
159
- if (clients.hasOwnProperty(i)) {
160
- this.__updateSession(clients[i]);
161
+ for (const i in clients) {
162
+ if (clients.hasOwnProperty(i)) {
163
+ this.__updateSession(clients[i]);
164
+ }
161
165
  }
162
- }
163
166
 
164
- this.server.sockets.emit('objectChange', id, obj);
167
+ this.server.sockets.emit('objectChange', id, obj);
168
+ }
165
169
  }
166
170
 
167
171
  subscribe(type, pattern) {
@@ -173,6 +177,10 @@ class SocketAdmin extends SocketCommon {
173
177
  this.server.sockets.emit(obj.command, obj.message.id, obj.message.data);
174
178
  }
175
179
  }
180
+
181
+ updateRatings(uuid, isAutoUpdate) {
182
+ return this.commands.updateRatings(uuid, isAutoUpdate);
183
+ }
176
184
  }
177
185
 
178
186
  module.exports = SocketAdmin;
@@ -750,18 +750,18 @@ class SocketCommands {
750
750
  }
751
751
  };
752
752
 
753
- this.commands['chownFile'] = (socket, _adapter, filename, options, callback) => {
754
- if (this._checkPermissions(socket, 'chownFile', callback, filename)) {
753
+ this.commands['chownFile'] = (socket, _adapter, fileName, options, callback) => {
754
+ if (this._checkPermissions(socket, 'chownFile', callback, fileName)) {
755
755
  options = options || {};
756
756
  options.user = socket._acl.user;
757
- this.adapter.chownFile(_adapter, filename, options, (err, ...args) =>
757
+ this.adapter.chownFile(_adapter, fileName, options, (err, ...args) =>
758
758
  SocketCommands._fixCallback(callback, err, ...args));
759
759
  }
760
760
  };
761
761
 
762
- this.commands['fileExists'] = (socket, _adapter, filename, callback) => {
763
- if (this._checkPermissions(socket, 'fileExists', callback, filename)) {
764
- this.adapter.fileExists(_adapter, filename, {user: socket._acl.user}, (err, ...args) =>
762
+ this.commands['fileExists'] = (socket, _adapter, fileName, callback) => {
763
+ if (this._checkPermissions(socket, 'fileExists', callback, fileName)) {
764
+ this.adapter.fileExists(_adapter, fileName, {user: socket._acl.user}, (err, ...args) =>
765
765
  SocketCommands._fixCallback(callback, err, ...args));
766
766
  }
767
767
  };
@@ -97,6 +97,36 @@ class SocketCommandsAdmin extends SocketCommands {
97
97
  }
98
98
  }
99
99
 
100
+ async updateRatings(uuid) {
101
+ if (!uuid) {
102
+ const obj = await this.adapter.getForeignObjectAsync('system.meta.uuid');
103
+ uuid = obj.native.uuid;
104
+ }
105
+
106
+ try {
107
+ const response = await axios.get('https://rating.iobroker.net/rating?uuid=' + uuid, {timeout: 15000, validateStatus: status => status < 400})
108
+ this.adapter._ratings = response.data;
109
+ if (!this.adapter._ratings || typeof this.adapter._ratings !== 'object' || Array.isArray(this.adapter._ratings)) {
110
+ this.adapter._ratings = {};
111
+ }
112
+ this.adapter._ratings.uuid = uuid;
113
+
114
+ // auto update only in admin
115
+ if (this.adapter.name === 'admin') {
116
+ this.adapter.ratingTimeout && clearTimeout(this.adapter.ratingTimeout);
117
+ this.adapter.ratingTimeout = setTimeout(() => {
118
+ this.adapter.ratingTimeout = null;
119
+ this.updateRatings(uuid, true)
120
+ .then(() => this.adapter.log.info('Adapter rating updated'));
121
+ }, 24 * 3600000);
122
+ }
123
+
124
+ return this.adapter._ratings;
125
+ } catch (error) {
126
+ this.adapter.log.warn('Cannot update rating: ' + (error.response ? error.response.data : (error.message || error.code)));
127
+ }
128
+ }
129
+
100
130
  _readInstanceConfig(id, user, isTab, configs) {
101
131
  return new Promise(resolve =>
102
132
  this.adapter.getForeignObject('system.adapter.' + id, {user}, (err, obj) => {
@@ -607,25 +637,25 @@ class SocketCommandsAdmin extends SocketCommands {
607
637
  if (config && config.log && config.log.transport) {
608
638
  for (const transport in config.log.transport) {
609
639
  if (Object.prototype.hasOwnProperty.call(config.log.transport, transport) && config.log.transport[transport].type === 'file') {
610
- let filename = config.log.transport[transport].filename || 'log/';
611
- const parts = filename.replace(/\\/g, '/').split('/');
640
+ let fileName = config.log.transport[transport].filename || 'log/';
641
+ const parts = fileName.replace(/\\/g, '/').split('/');
612
642
  parts.pop();
613
- filename = parts.join('/');
614
- if (filename[0] !== '/' && !filename.match(/^\W:/)) {
615
- const _filename = path.normalize(__dirname + '/../../../') + filename;
643
+ fileName = parts.join('/');
644
+ if (fileName[0] !== '/' && !fileName.match(/^\W:/)) {
645
+ const _filename = path.normalize(__dirname + '/../../../') + fileName;
616
646
  if (!fs.existsSync(_filename)) {
617
- filename = path.normalize(__dirname + '/../../') + filename;
647
+ fileName = path.normalize(__dirname + '/../../') + fileName;
618
648
  } else {
619
- filename = _filename;
649
+ fileName = _filename;
620
650
  }
621
651
  }
622
- if (fs.existsSync(filename)) {
623
- const files = fs.readdirSync(filename);
652
+ if (fs.existsSync(fileName)) {
653
+ const files = fs.readdirSync(fileName);
624
654
 
625
655
  for (let f = 0; f < files.length; f++) {
626
656
  try {
627
657
  if (!files[f].endsWith('-audit.json')) {
628
- const stat = fs.lstatSync(filename + '/' + files[f]);
658
+ const stat = fs.lstatSync(fileName + '/' + files[f]);
629
659
  if (!stat.isDirectory()) {
630
660
  result.list.push({
631
661
  fileName: 'log/' + transport + '/' + files[f],
@@ -636,7 +666,7 @@ class SocketCommandsAdmin extends SocketCommands {
636
666
  } catch (e) {
637
667
  // push unchecked
638
668
  // result.list.push('log/' + transport + '/' + files[f]);
639
- this.adapter.log.error(`Cannot check file: ${filename}/${files[f]}`);
669
+ this.adapter.log.error(`Cannot check file: ${fileName}/${files[f]}`);
640
670
  }
641
671
  }
642
672
  }
@@ -679,7 +709,7 @@ class SocketCommandsAdmin extends SocketCommands {
679
709
  this.adapter.log.debug(`cmdExec on ${host}(${id}): ${cmd}`);
680
710
  // remember socket for this ID.
681
711
  this.cmdSessions[id] = {socket};
682
- this.adapter.sendToHost(host, 'cmdExec', {data: cmd, id: id});
712
+ this.adapter.sendToHost(host, 'cmdExec', {data: cmd, id});
683
713
  }
684
714
  };
685
715
 
@@ -692,8 +722,8 @@ class SocketCommandsAdmin extends SocketCommands {
692
722
  };
693
723
 
694
724
  this.commands['getRatings'] = (socket, update, callback) => {
695
- if (update) {
696
- this.adapter._updateRatings()
725
+ if (update || !this.adapter._ratings) {
726
+ this.updateRatings()
697
727
  .then(() => typeof callback === 'function' && callback(null, this.adapter._ratings));
698
728
  } else {
699
729
  typeof callback === 'function' && callback(null, this.adapter._ratings);
@@ -1033,7 +1063,7 @@ class SocketCommandsAdmin extends SocketCommands {
1033
1063
  }
1034
1064
  };
1035
1065
 
1036
- this.commands['delObjects'] = (socket, id, options, callback) => {
1066
+ this.commands['delObject'] = (socket, id, options, callback) => {
1037
1067
  if (this._checkPermissions(socket, 'delObject', callback, id)) {
1038
1068
  if (!options || typeof options !== 'object') {
1039
1069
  options = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iobroker/socket-classes",
3
- "version": "0.1.4",
3
+ "version": "0.1.7",
4
4
  "description": "ioBroker server-side web sockets",
5
5
  "author": {
6
6
  "name": "bluefox",
@@ -23,11 +23,11 @@
23
23
  "dependencies": {
24
24
  "passport": "^0.5.2",
25
25
  "cookie-parser": "^1.4.6",
26
- "axios": "^0.26.1"
26
+ "axios": "^0.27.2"
27
27
  },
28
28
  "devDependencies": {
29
- "@alcalzone/release-script": "^3.5.6",
30
- "@alcalzone/release-script-plugin-license": "^3.5.3",
29
+ "@alcalzone/release-script": "^3.5.9",
30
+ "@alcalzone/release-script-plugin-license": "^3.5.9",
31
31
  "chai": "^4.3.6",
32
32
  "mocha": "^9.2.2"
33
33
  },