@iobroker/js-controller-common 4.0.0-alpha.45-20220114-88aaebdb → 4.0.0-alpha.49-20220121-e7aa4308
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/lib/common/tools.js +38 -47
- package/package.json +3 -3
package/lib/common/tools.js
CHANGED
|
@@ -434,9 +434,15 @@ function updateUuid(newUuid, _objects, callback) {
|
|
|
434
434
|
});
|
|
435
435
|
}
|
|
436
436
|
|
|
437
|
-
|
|
437
|
+
/**
|
|
438
|
+
* Generates a new uuid if non existing
|
|
439
|
+
*
|
|
440
|
+
* @param {object} objects - objects DB
|
|
441
|
+
* @return {Promise<void|string>} uuid if successfully created/updated
|
|
442
|
+
*/
|
|
443
|
+
async function createUuid(objects) {
|
|
438
444
|
const promiseCheckPassword = new Promise(resolve =>
|
|
439
|
-
|
|
445
|
+
objects.getObject('system.user.admin', (err, obj) => {
|
|
440
446
|
if (err || !obj) {
|
|
441
447
|
password = password || require('./password');
|
|
442
448
|
|
|
@@ -445,7 +451,7 @@ function createUuid(_objects, callback) {
|
|
|
445
451
|
err && console.error(err);
|
|
446
452
|
|
|
447
453
|
// Create user here and not in io-package.js because of hash password
|
|
448
|
-
|
|
454
|
+
objects.setObject(
|
|
449
455
|
'system.user.admin',
|
|
450
456
|
{
|
|
451
457
|
type: 'user',
|
|
@@ -456,7 +462,7 @@ function createUuid(_objects, callback) {
|
|
|
456
462
|
enabled: true
|
|
457
463
|
},
|
|
458
464
|
ts: new Date().getTime(),
|
|
459
|
-
from:
|
|
465
|
+
from: `system.host.${getHostName()}.tools`,
|
|
460
466
|
native: {}
|
|
461
467
|
},
|
|
462
468
|
() => {
|
|
@@ -471,7 +477,7 @@ function createUuid(_objects, callback) {
|
|
|
471
477
|
})
|
|
472
478
|
);
|
|
473
479
|
const promiseCheckUuid = new Promise(resolve =>
|
|
474
|
-
|
|
480
|
+
objects.getObject('system.meta.uuid', (err, obj) => {
|
|
475
481
|
if (!err && obj && obj.native && obj.native.uuid) {
|
|
476
482
|
const PROBLEM_UUIDS = [
|
|
477
483
|
'ab265f4a-67f9-a46a-c0b2-61e4b95cefe5',
|
|
@@ -485,10 +491,10 @@ function createUuid(_objects, callback) {
|
|
|
485
491
|
// if COMMON invalid docker uuid
|
|
486
492
|
if (PROBLEM_UUIDS.includes(obj.native.uuid)) {
|
|
487
493
|
// Read vis license
|
|
488
|
-
|
|
494
|
+
objects.getObject('system.adapter.vis.0', (err, licObj) => {
|
|
489
495
|
if (!licObj || !licObj.native || !licObj.native.license) {
|
|
490
496
|
// generate new UUID
|
|
491
|
-
updateUuid('',
|
|
497
|
+
updateUuid('', objects, _uuid => resolve(_uuid));
|
|
492
498
|
} else {
|
|
493
499
|
// decode obj.native.license
|
|
494
500
|
let data;
|
|
@@ -500,10 +506,10 @@ function createUuid(_objects, callback) {
|
|
|
500
506
|
|
|
501
507
|
if (!data || !data.uuid) {
|
|
502
508
|
// generate new UUID
|
|
503
|
-
updateUuid('',
|
|
509
|
+
updateUuid('', objects, __uuid => resolve(__uuid));
|
|
504
510
|
} else {
|
|
505
511
|
if (data.uuid !== obj.native.uuid) {
|
|
506
|
-
updateUuid(data.correct ? data.uuid : '',
|
|
512
|
+
updateUuid(data.correct ? data.uuid : '', objects, _uuid => resolve(_uuid));
|
|
507
513
|
} else {
|
|
508
514
|
// Show error
|
|
509
515
|
console.warn(
|
|
@@ -522,12 +528,13 @@ function createUuid(_objects, callback) {
|
|
|
522
528
|
}
|
|
523
529
|
} else {
|
|
524
530
|
// generate new UUID
|
|
525
|
-
updateUuid('',
|
|
531
|
+
updateUuid('', objects, _uuid => resolve(_uuid));
|
|
526
532
|
}
|
|
527
533
|
})
|
|
528
534
|
);
|
|
529
535
|
|
|
530
|
-
|
|
536
|
+
const result = await Promise.all([promiseCheckPassword, promiseCheckUuid]);
|
|
537
|
+
return result[1];
|
|
531
538
|
}
|
|
532
539
|
|
|
533
540
|
// Download file to tmp or return file name directly
|
|
@@ -1278,23 +1285,28 @@ async function getRepositoryFileAsync(url, hash, force, _actualRepo) {
|
|
|
1278
1285
|
};
|
|
1279
1286
|
}
|
|
1280
1287
|
|
|
1281
|
-
|
|
1282
|
-
|
|
1288
|
+
/**
|
|
1289
|
+
* Sends the given object to the diagnosis server
|
|
1290
|
+
*
|
|
1291
|
+
* @param {object} obj - diagnosis object
|
|
1292
|
+
* @return {Promise<void>}
|
|
1293
|
+
*/
|
|
1294
|
+
async function sendDiagInfo(obj) {
|
|
1295
|
+
const objStr = JSON.stringify(obj);
|
|
1296
|
+
console.log(`Send diag info: ${objStr}`);
|
|
1283
1297
|
axios = axios || require('axios');
|
|
1284
1298
|
const params = new URLSearchParams();
|
|
1285
|
-
params.append('data',
|
|
1299
|
+
params.append('data', objStr);
|
|
1286
1300
|
const config = {
|
|
1287
1301
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
1288
1302
|
timeout: 4000
|
|
1289
1303
|
};
|
|
1290
1304
|
|
|
1291
|
-
|
|
1292
|
-
.post(`http://download.${module.exports.appName}.net/diag.php`, params, config)
|
|
1293
|
-
|
|
1294
|
-
.
|
|
1295
|
-
|
|
1296
|
-
typeof callback === 'function' && callback(error);
|
|
1297
|
-
});
|
|
1305
|
+
try {
|
|
1306
|
+
await axios.post(`http://download.${module.exports.appName}.net/diag.php`, params, config);
|
|
1307
|
+
} catch (e) {
|
|
1308
|
+
console.log(`Cannot send diag info: ${e.message}`);
|
|
1309
|
+
}
|
|
1298
1310
|
}
|
|
1299
1311
|
|
|
1300
1312
|
/**
|
|
@@ -2817,7 +2829,7 @@ async function getAllInstances(adapters, objects) {
|
|
|
2817
2829
|
continue;
|
|
2818
2830
|
}
|
|
2819
2831
|
if (!adapters[i].includes('.')) {
|
|
2820
|
-
const inst = await
|
|
2832
|
+
const inst = await getInstances(adapters[i], objects, false);
|
|
2821
2833
|
for (let j = 0; j < inst.length; j++) {
|
|
2822
2834
|
if (!instances.includes(inst[j])) {
|
|
2823
2835
|
instances.push(inst[j]);
|
|
@@ -2854,35 +2866,15 @@ async function getAllEnums(objects) {
|
|
|
2854
2866
|
return allEnums;
|
|
2855
2867
|
}
|
|
2856
2868
|
|
|
2857
|
-
/**
|
|
2858
|
-
* get all instances of one adapter
|
|
2859
|
-
*
|
|
2860
|
-
* @alias getInstances
|
|
2861
|
-
* @param {string }adapter name of the adapter
|
|
2862
|
-
* @param {object }objects objects DB
|
|
2863
|
-
* @param {boolean} withObjects return objects instead of only ids
|
|
2864
|
-
* @param {function} callback callback to be executed
|
|
2865
|
-
*/
|
|
2866
|
-
function getInstances(adapter, objects, withObjects, callback) {
|
|
2867
|
-
if (typeof withObjects === 'function') {
|
|
2868
|
-
callback = withObjects;
|
|
2869
|
-
withObjects = false;
|
|
2870
|
-
}
|
|
2871
|
-
|
|
2872
|
-
return getInstancesAsync(adapter, objects, withObjects)
|
|
2873
|
-
.then(instances => callback(null, instances))
|
|
2874
|
-
.catch(error => callback(error));
|
|
2875
|
-
}
|
|
2876
|
-
|
|
2877
2869
|
/**
|
|
2878
2870
|
* get async all instances of one adapter
|
|
2879
2871
|
*
|
|
2880
|
-
* @alias
|
|
2881
|
-
* @param {string
|
|
2882
|
-
* @param {object
|
|
2872
|
+
* @alias getInstances
|
|
2873
|
+
* @param {string} adapter name of the adapter
|
|
2874
|
+
* @param {object}objects objects DB
|
|
2883
2875
|
* @param {boolean} withObjects return objects instead of only ids
|
|
2884
2876
|
*/
|
|
2885
|
-
async function
|
|
2877
|
+
async function getInstances(adapter, objects, withObjects) {
|
|
2886
2878
|
const arr = await objects.getObjectListAsync({
|
|
2887
2879
|
startkey: 'system.adapter.' + adapter + '.',
|
|
2888
2880
|
endkey: 'system.adapter.' + adapter + '.\u9999'
|
|
@@ -3625,7 +3617,6 @@ module.exports = {
|
|
|
3625
3617
|
generateDefaultCertificates,
|
|
3626
3618
|
getAdapterDir,
|
|
3627
3619
|
getInstances,
|
|
3628
|
-
getInstancesAsync,
|
|
3629
3620
|
getAllInstances,
|
|
3630
3621
|
getCertificateInfo,
|
|
3631
3622
|
getConfigFileName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iobroker/js-controller-common",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.49-20220121-e7aa4308",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=12.0.0"
|
|
6
6
|
},
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"event-stream": "^4.0.1",
|
|
16
16
|
"fs-extra": "^10.0.0",
|
|
17
17
|
"jsonwebtoken": "^8.5.1",
|
|
18
|
-
"node-forge": "^0.
|
|
18
|
+
"node-forge": "^1.0.0",
|
|
19
19
|
"node.extend": "^2.0.2",
|
|
20
20
|
"promisify-child-process": "^4.1.1",
|
|
21
21
|
"readline": "^1.3.0",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"lib/",
|
|
48
48
|
"index.js"
|
|
49
49
|
],
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "f42f117b74d3c4bfac0bc872c087d382ca897b7c"
|
|
51
51
|
}
|