@all-smart/all-smart-tools 1.0.5 → 1.0.11
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/main.js +25 -8
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -63,13 +63,30 @@ class asTools {
|
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
async createAdapterStorageObject(){
|
|
67
|
+
await this.adapter.setObjectNotExistsAsync(`${this.adapter.namespace.replace(/\.\d/g, '')}.storage`, {
|
|
68
|
+
"type": "config",
|
|
69
|
+
"common": {
|
|
70
|
+
"name": "Adapter storage",
|
|
71
|
+
"type": "config",
|
|
72
|
+
"expert": true
|
|
73
|
+
},
|
|
74
|
+
"native": {}
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
66
78
|
async block() {
|
|
67
79
|
return new Promise(async (resolve, reject) => {
|
|
80
|
+
await this.createAdapterStorageObject();
|
|
68
81
|
const check = async () => {
|
|
69
|
-
|
|
82
|
+
const adapterObject = await this.adapter.getForeignObjectAsync(`${this.adapter.namespace.replace(/\.\d/g, '')}.storage`);
|
|
83
|
+
if (adapterObject.native.licenseCertificate) {
|
|
70
84
|
if (await this.checkLocalLicenseCertificate()) {
|
|
71
|
-
this.adapter.log.info('License
|
|
85
|
+
this.adapter.log.info('License Certificate OK');
|
|
72
86
|
resolve(true);
|
|
87
|
+
} else {
|
|
88
|
+
this.adapter.log.warn('There was an error validating the license')
|
|
89
|
+
reject(false);
|
|
73
90
|
}
|
|
74
91
|
} else if (await this.checkLicenseKey()) {
|
|
75
92
|
resolve(true);
|
|
@@ -171,22 +188,22 @@ class asTools {
|
|
|
171
188
|
"majorVersion": majorVersion
|
|
172
189
|
}
|
|
173
190
|
// encode license certificate
|
|
174
|
-
const
|
|
191
|
+
const licenseCertificateEncoded = Buffer.from(JSON.stringify(licenseCertificate)).toString('base64');
|
|
192
|
+
this.adapter.log.debug(licenseCertificateEncoded);
|
|
175
193
|
// write license certificate
|
|
176
|
-
await this.adapter.extendForeignObjectAsync(
|
|
194
|
+
await this.adapter.extendForeignObjectAsync(`${this.adapter.namespace.replace(/\.\d/g, '')}.storage`, {
|
|
177
195
|
native: {
|
|
178
|
-
licenseCertificate:
|
|
196
|
+
licenseCertificate: licenseCertificateEncoded
|
|
179
197
|
}
|
|
180
198
|
})
|
|
181
199
|
}
|
|
182
200
|
|
|
183
201
|
async checkLocalLicenseCertificate(){
|
|
184
202
|
// read license certificate
|
|
185
|
-
const
|
|
186
|
-
const adapterObj = this.adapter.getForeignObjectAsync(`system.adapter.${this.adapter.namespace.replace(/\.\d/g, '')}`)
|
|
203
|
+
const adapterObj = await this.adapter.getForeignObjectAsync(`${this.adapter.namespace.replace(/\.\d/g, '')}.storage`);
|
|
187
204
|
const licenseCertificateEncoded = adapterObj.native.licenseCertificate;
|
|
188
205
|
// decode license file
|
|
189
|
-
const licenseCertificate = JSON.parse(
|
|
206
|
+
const licenseCertificate = JSON.parse(Buffer.from(licenseCertificateEncoded, 'base64').toString('ascii'));
|
|
190
207
|
// get system uuid
|
|
191
208
|
const systemMeta = await this.adapter.getForeignObjectAsync('system.meta.uuid');
|
|
192
209
|
const systemUuid = systemMeta.native.uuid;
|