@iobroker/socket-classes 0.2.1 → 0.3.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/README.md CHANGED
@@ -69,6 +69,15 @@ io.close();
69
69
  -->
70
70
 
71
71
  ## Changelog
72
+ ### 0.3.2 (2022-05-19)
73
+ * (bluefox) Hide warn messages
74
+
75
+ ### 0.3.1 (2022-05-16)
76
+ * (bluefox) Added back compatibility with js-controller@4.0 for `writeDirAsZip`
77
+
78
+ ### 0.3.0 (2022-05-16)
79
+ * (bluefox) Process `writeDirAsZip` locally
80
+
72
81
  ### 0.2.1 (2022-05-12)
73
82
  * (bluefox) fixed `getObjects` command
74
83
 
@@ -1,4 +1,5 @@
1
1
  let axios = null;
2
+ let zipFiles;
2
3
 
3
4
  // taken from here: https://github.com/ioBroker/ioBroker.js-controller/blob/master/packages/common/src/lib/common/tools.ts#L2386
4
5
  /**
@@ -79,6 +80,7 @@ class SocketCommands {
79
80
  this.adapter = adapter;
80
81
  this.commands = {};
81
82
  this.subscribes = {};
83
+ this.logEnabled = false;
82
84
 
83
85
  this._updateSession = updateSession;
84
86
 
@@ -287,7 +289,10 @@ class SocketCommands {
287
289
  } else if (type === 'objectChange') {
288
290
  this.adapter.subscribeForeignObjects && this.adapter.subscribeForeignObjects(pattern);
289
291
  } else if (type === 'log') {
290
- this.adapter.requireLog && this.adapter.requireLog(true);
292
+ if (!this.logEnabled && this.adapter.requireLog) {
293
+ this.logEnabled = true;
294
+ this.adapter.requireLog(true);
295
+ }
291
296
  } else if (type === 'fileChange') {
292
297
  this.adapter.subscribeForeignFiles && this.adapter.subscribeForeignFiles(pattern, patternFile);
293
298
  }
@@ -331,7 +336,10 @@ class SocketCommands {
331
336
  this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern);
332
337
  } else if (type === 'log') {
333
338
  //console.log((socket._name || socket.id) + ' requireLog false');
334
- this.adapter.requireLog && this.adapter.requireLog(false);
339
+ if (this.logEnabled && this.adapter.requireLog) {
340
+ this.logEnabled = false;
341
+ this.adapter.requireLog(false);
342
+ }
335
343
  } else if (type === 'fileChange') {
336
344
  //console.log((socket._name || socket.id) + ' requireLog false');
337
345
  this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(pattern, patternFile);
@@ -613,7 +621,31 @@ class SocketCommands {
613
621
  if (this.sendToHost) {
614
622
  this.sendToHost(host, command, message, callback);
615
623
  } else {
616
- this.adapter.sendToHost(host, command, message, callback);
624
+ // Try to decode this file locally as redis has a limitation for files bigger than 20MB
625
+ if (command === 'writeDirAsZip' && message && message.data.length > 1024 * 1024) {
626
+ if (!zipFiles) {
627
+ const utils = require('@iobroker/adapter-core'); // Get common adapter utils
628
+ zipFiles = require(utils.controllerDir + '/lib/zipFiles.js');
629
+ }
630
+ zipFiles
631
+ .writeDirAsZip(
632
+ this.adapter, // normally we have to pass here the internal "objects" object, but as
633
+ // only writeFile is used, and it has the same name we can pass here the
634
+ // adapter, which has the function with the same name and arguments
635
+ message.id,
636
+ message.name,
637
+ Buffer.from(message.data, 'base64'),
638
+ message.options,
639
+ error => callback({ error }) // this is for back compatibility with js-controller@4.0 or older
640
+ )
641
+ .then(() => callback({}))
642
+ .catch(error => {
643
+ this.adapter.log.error(`Cannot write zip file as folder: ${error}`);
644
+ callback({ error });
645
+ });
646
+ } else {
647
+ this.adapter.sendToHost(host, command, message, callback);
648
+ }
617
649
  }
618
650
  }
619
651
  };
@@ -736,7 +768,7 @@ class SocketCommands {
736
768
  }
737
769
  options = options || {};
738
770
  options.user = socket._acl.user;
739
- this.adapter.log.warn('writeFile deprecated. Please use writeFile64');
771
+ this.adapter.log.debug('writeFile deprecated. Please use writeFile64');
740
772
  // const buffer = Buffer.from(data64, 'base64');
741
773
  this.adapter.writeFile(_adapter, fileName, data, {user: socket._acl.user}, (err, ...args) =>
742
774
  SocketCommands._fixCallback(callback, err, ...args));
@@ -143,6 +143,7 @@ class SocketCommandsAdmin extends SocketCommands {
143
143
  icon: obj.common.icon,
144
144
  materialize: obj.common.materialize,
145
145
  jsonConfig: obj.common.jsonConfig,
146
+ version: obj.common.version,
146
147
  };
147
148
  if (isTab) {
148
149
  config.tab = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iobroker/socket-classes",
3
- "version": "0.2.1",
3
+ "version": "0.3.2",
4
4
  "description": "ioBroker server-side web sockets",
5
5
  "author": {
6
6
  "name": "bluefox",