@iobroker/socket-classes 0.1.10 → 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 +9 -0
- package/lib/socketCommands.js +34 -3
- package/lib/socketCommandsAdmin.js +18 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,6 +69,15 @@ io.close();
|
|
|
69
69
|
-->
|
|
70
70
|
|
|
71
71
|
## Changelog
|
|
72
|
+
### 0.3.0 (2022-05-16)
|
|
73
|
+
* (bluefox) Process `writeDirAsZip` locally
|
|
74
|
+
|
|
75
|
+
### 0.2.1 (2022-05-12)
|
|
76
|
+
* (bluefox) fixed `getObjects` command
|
|
77
|
+
|
|
78
|
+
### 0.2.0 (2022-05-09)
|
|
79
|
+
* (bluefox) fixed `delObjects` command
|
|
80
|
+
|
|
72
81
|
### 0.1.10 (2022-05-09)
|
|
73
82
|
* (bluefox) Added support for fileChanges
|
|
74
83
|
|
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
|
};
|
|
@@ -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;
|
|
@@ -1071,7 +1072,19 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1071
1072
|
options = {};
|
|
1072
1073
|
}
|
|
1073
1074
|
options.user = socket._acl.user;
|
|
1074
|
-
options.recursive = true;
|
|
1075
|
+
// options.recursive = true; // the only difference between delObject and delObjects is this line
|
|
1076
|
+
this.adapter.delForeignObject(id, options, (err, ...args) =>
|
|
1077
|
+
SocketCommands._fixCallback(callback, err, ...args));
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1080
|
+
|
|
1081
|
+
this.commands['delObjects'] = (socket, id, options, callback) => {
|
|
1082
|
+
if (this._checkPermissions(socket, 'delObject', callback, id)) {
|
|
1083
|
+
if (!options || typeof options !== 'object') {
|
|
1084
|
+
options = {};
|
|
1085
|
+
}
|
|
1086
|
+
options.user = socket._acl.user;
|
|
1087
|
+
options.recursive = true; // the only difference between delObject and delObjects is this line
|
|
1075
1088
|
this.adapter.delForeignObject(id, options, (err, ...args) =>
|
|
1076
1089
|
SocketCommands._fixCallback(callback, err, ...args));
|
|
1077
1090
|
}
|
|
@@ -1099,9 +1112,10 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1099
1112
|
__initCommandsObjects() {
|
|
1100
1113
|
super.__initCommandsObjects();
|
|
1101
1114
|
|
|
1102
|
-
this.commands['getAllObjects'] = (socket, callback) =>
|
|
1103
|
-
|
|
1104
|
-
|
|
1115
|
+
this.commands['getAllObjects'] = (socket, callback) => this._getAllObjects(socket, callback);
|
|
1116
|
+
|
|
1117
|
+
// Identical to getAllObjects
|
|
1118
|
+
this.commands['getObjects'] = (socket, callback) => this._getAllObjects(socket, callback);
|
|
1105
1119
|
|
|
1106
1120
|
this.commands['extendObject'] = (socket, id, obj, callback) => {
|
|
1107
1121
|
if (this._checkPermissions(socket, 'extendObject', callback, id)) {
|