@iobroker/socket-classes 0.1.4 → 0.1.5
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/socketAdmin.js +4 -0
- package/lib/socketCommands.js +6 -6
- package/lib/socketCommandsAdmin.js +43 -13
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/socketAdmin.js
CHANGED
|
@@ -173,6 +173,10 @@ class SocketAdmin extends SocketCommon {
|
|
|
173
173
|
this.server.sockets.emit(obj.command, obj.message.id, obj.message.data);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
+
|
|
177
|
+
updateRatings(uuid, isAutoUpdate) {
|
|
178
|
+
return this.commands.updateRatings(uuid, isAutoUpdate);
|
|
179
|
+
}
|
|
176
180
|
}
|
|
177
181
|
|
|
178
182
|
module.exports = SocketAdmin;
|
package/lib/socketCommands.js
CHANGED
|
@@ -750,18 +750,18 @@ class SocketCommands {
|
|
|
750
750
|
}
|
|
751
751
|
};
|
|
752
752
|
|
|
753
|
-
this.commands['chownFile'] = (socket, _adapter,
|
|
754
|
-
if (this._checkPermissions(socket, 'chownFile', callback,
|
|
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,
|
|
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,
|
|
763
|
-
if (this._checkPermissions(socket, 'fileExists', callback,
|
|
764
|
-
this.adapter.fileExists(_adapter,
|
|
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
|
|
611
|
-
const parts =
|
|
640
|
+
let fileName = config.log.transport[transport].filename || 'log/';
|
|
641
|
+
const parts = fileName.replace(/\\/g, '/').split('/');
|
|
612
642
|
parts.pop();
|
|
613
|
-
|
|
614
|
-
if (
|
|
615
|
-
const _filename = path.normalize(__dirname + '/../../../') +
|
|
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
|
-
|
|
647
|
+
fileName = path.normalize(__dirname + '/../../') + fileName;
|
|
618
648
|
} else {
|
|
619
|
-
|
|
649
|
+
fileName = _filename;
|
|
620
650
|
}
|
|
621
651
|
}
|
|
622
|
-
if (fs.existsSync(
|
|
623
|
-
const files = fs.readdirSync(
|
|
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(
|
|
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: ${
|
|
669
|
+
this.adapter.log.error(`Cannot check file: ${fileName}/${files[f]}`);
|
|
640
670
|
}
|
|
641
671
|
}
|
|
642
672
|
}
|
|
@@ -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.
|
|
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);
|