@iobroker/socket-classes 0.2.1 → 0.3.0
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 +3 -0
- package/lib/socketCommands.js +34 -3
- package/lib/socketCommandsAdmin.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/socketCommands.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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,30 @@ class SocketCommands {
|
|
|
613
621
|
if (this.sendToHost) {
|
|
614
622
|
this.sendToHost(host, command, message, callback);
|
|
615
623
|
} else {
|
|
616
|
-
this
|
|
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 agruments
|
|
635
|
+
message.id,
|
|
636
|
+
message.name,
|
|
637
|
+
Buffer.from(message.data, 'base64'),
|
|
638
|
+
message.options
|
|
639
|
+
)
|
|
640
|
+
.then(() => callback({}))
|
|
641
|
+
.catch(error => {
|
|
642
|
+
this.adapter.log.error(`Cannot write zip file as folder: ${error}`);
|
|
643
|
+
callback({ error });
|
|
644
|
+
});
|
|
645
|
+
} else {
|
|
646
|
+
this.adapter.sendToHost(host, command, message, callback);
|
|
647
|
+
}
|
|
617
648
|
}
|
|
618
649
|
}
|
|
619
650
|
};
|