iobroker.iot 3.5.2 → 4.0.1

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.
Files changed (111) hide show
  1. package/README.md +24 -9
  2. package/admin/assets/index-Y479CE6x.js +681 -0
  3. package/admin/index_m.html +1 -1
  4. package/admin/rules/assets/{ActionVisu-D9x2f6zu.js → ActionVisu-DE8dgNVF.js} +1 -1
  5. package/admin/rules/assets/{ActionVisu__loadShare__react__loadShare__-Cg21Ef1U.js → ActionVisu__loadShare__react__loadShare__-BKaC-p5K.js} +1 -1
  6. package/admin/rules/assets/{ActionVisu__loadShare__react_mf_2_dom__loadShare__-B1zRWn0u.js → ActionVisu__loadShare__react_mf_2_dom__loadShare__-Bs1o8DtQ.js} +2 -2
  7. package/admin/rules/assets/ActionVisu__mf_v__runtimeInit__mf_v__-DtUoI3FU.js +5 -0
  8. package/admin/rules/assets/bootstrap-Ba57tu25.js +1 -0
  9. package/admin/rules/assets/hostInit-hos3Txsy.js +1 -1
  10. package/admin/rules/assets/{index-Duo7mFlZ.js → index-CbxmbJvB.js} +2 -2
  11. package/admin/rules/assets/{index-CAAeiKCc.js → index-DjPMvPni.js} +2 -2
  12. package/admin/rules/assets/index-_Y2FN5EZ.js +1152 -0
  13. package/admin/rules/assets/{virtualExposes-BqVak7rX.js → virtualExposes-BNZJTatg.js} +2 -2
  14. package/admin/rules/customRuleBlocks.js +2 -2
  15. package/io-package.json +27 -27
  16. package/package.json +17 -14
  17. package/admin/assets/index-Df2NS929.js +0 -681
  18. package/admin/rules/assets/ActionVisu__mf_v__runtimeInit__mf_v__-Cz053nO7.js +0 -10
  19. package/admin/rules/assets/bootstrap-BCFKIiwZ.js +0 -1
  20. package/admin/rules/assets/index-BwcOGyWI.js +0 -1152
  21. package/lib/AlexaSmartHomeV3/Alexa/AlexaResponse.js +0 -262
  22. package/lib/AlexaSmartHomeV3/Alexa/Capabilities/Base.js +0 -124
  23. package/lib/AlexaSmartHomeV3/Alexa/Capabilities/BrightnessController.js +0 -15
  24. package/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorController.js +0 -10
  25. package/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorTemperatureController.js +0 -15
  26. package/lib/AlexaSmartHomeV3/Alexa/Capabilities/ContactSensor.js +0 -10
  27. package/lib/AlexaSmartHomeV3/Alexa/Capabilities/LockController.js +0 -10
  28. package/lib/AlexaSmartHomeV3/Alexa/Capabilities/ModeController.js +0 -69
  29. package/lib/AlexaSmartHomeV3/Alexa/Capabilities/MotionSensor.js +0 -10
  30. package/lib/AlexaSmartHomeV3/Alexa/Capabilities/PercentageController.js +0 -10
  31. package/lib/AlexaSmartHomeV3/Alexa/Capabilities/PowerController.js +0 -15
  32. package/lib/AlexaSmartHomeV3/Alexa/Capabilities/Speaker.js +0 -20
  33. package/lib/AlexaSmartHomeV3/Alexa/Capabilities/TemperatureSensor.js +0 -10
  34. package/lib/AlexaSmartHomeV3/Alexa/Capabilities/ThermostatController.js +0 -34
  35. package/lib/AlexaSmartHomeV3/Alexa/Capabilities/index.js +0 -14
  36. package/lib/AlexaSmartHomeV3/Alexa/Directives/Base.js +0 -27
  37. package/lib/AlexaSmartHomeV3/Alexa/Directives/ChangeReport.js +0 -75
  38. package/lib/AlexaSmartHomeV3/Alexa/Directives/Discovery.js +0 -39
  39. package/lib/AlexaSmartHomeV3/Alexa/Directives/ReportState.js +0 -50
  40. package/lib/AlexaSmartHomeV3/Alexa/Directives/index.js +0 -13
  41. package/lib/AlexaSmartHomeV3/Alexa/ModeValues/Base.js +0 -38
  42. package/lib/AlexaSmartHomeV3/Alexa/ModeValues/Closed.js +0 -55
  43. package/lib/AlexaSmartHomeV3/Alexa/ModeValues/Open.js +0 -56
  44. package/lib/AlexaSmartHomeV3/Alexa/ModeValues/index.js +0 -14
  45. package/lib/AlexaSmartHomeV3/Alexa/Properties/AdjustableProperty.js +0 -11
  46. package/lib/AlexaSmartHomeV3/Alexa/Properties/Base.js +0 -108
  47. package/lib/AlexaSmartHomeV3/Alexa/Properties/Brightness.js +0 -14
  48. package/lib/AlexaSmartHomeV3/Alexa/Properties/Color.js +0 -40
  49. package/lib/AlexaSmartHomeV3/Alexa/Properties/ColorTemperatureInKelvin.js +0 -62
  50. package/lib/AlexaSmartHomeV3/Alexa/Properties/DetectionState.js +0 -22
  51. package/lib/AlexaSmartHomeV3/Alexa/Properties/LockState.js +0 -40
  52. package/lib/AlexaSmartHomeV3/Alexa/Properties/Mode.js +0 -32
  53. package/lib/AlexaSmartHomeV3/Alexa/Properties/Muted.js +0 -17
  54. package/lib/AlexaSmartHomeV3/Alexa/Properties/Percentage.js +0 -14
  55. package/lib/AlexaSmartHomeV3/Alexa/Properties/PowerState.js +0 -25
  56. package/lib/AlexaSmartHomeV3/Alexa/Properties/TargetSetpoint.js +0 -28
  57. package/lib/AlexaSmartHomeV3/Alexa/Properties/Temperature.js +0 -20
  58. package/lib/AlexaSmartHomeV3/Alexa/Properties/ThermostatMode.js +0 -52
  59. package/lib/AlexaSmartHomeV3/Alexa/Properties/Volume.js +0 -19
  60. package/lib/AlexaSmartHomeV3/Alexa/Properties/index.js +0 -14
  61. package/lib/AlexaSmartHomeV3/Controls/AdjustableControl.js +0 -22
  62. package/lib/AlexaSmartHomeV3/Controls/AdjustablePercentageControl.js +0 -28
  63. package/lib/AlexaSmartHomeV3/Controls/AirCondition.js +0 -144
  64. package/lib/AlexaSmartHomeV3/Controls/Blind.js +0 -12
  65. package/lib/AlexaSmartHomeV3/Controls/ContactSensor.js +0 -17
  66. package/lib/AlexaSmartHomeV3/Controls/Control.js +0 -352
  67. package/lib/AlexaSmartHomeV3/Controls/Ct.js +0 -172
  68. package/lib/AlexaSmartHomeV3/Controls/Dimmer.js +0 -124
  69. package/lib/AlexaSmartHomeV3/Controls/Door.js +0 -9
  70. package/lib/AlexaSmartHomeV3/Controls/Gate.js +0 -42
  71. package/lib/AlexaSmartHomeV3/Controls/Hue.js +0 -207
  72. package/lib/AlexaSmartHomeV3/Controls/Light.js +0 -54
  73. package/lib/AlexaSmartHomeV3/Controls/Lock.js +0 -36
  74. package/lib/AlexaSmartHomeV3/Controls/Motion.js +0 -17
  75. package/lib/AlexaSmartHomeV3/Controls/ReadOnlyDetector.js +0 -25
  76. package/lib/AlexaSmartHomeV3/Controls/Slider.js +0 -10
  77. package/lib/AlexaSmartHomeV3/Controls/Socket.js +0 -21
  78. package/lib/AlexaSmartHomeV3/Controls/Temperature.js +0 -22
  79. package/lib/AlexaSmartHomeV3/Controls/Thermostat.js +0 -86
  80. package/lib/AlexaSmartHomeV3/Controls/VacuumCleaner.js +0 -28
  81. package/lib/AlexaSmartHomeV3/Controls/Volume.js +0 -109
  82. package/lib/AlexaSmartHomeV3/Controls/VolumeGroup.js +0 -9
  83. package/lib/AlexaSmartHomeV3/Controls/Window.js +0 -9
  84. package/lib/AlexaSmartHomeV3/Controls/index.js +0 -14
  85. package/lib/AlexaSmartHomeV3/Device.js +0 -84
  86. package/lib/AlexaSmartHomeV3/DeviceManager.js +0 -415
  87. package/lib/AlexaSmartHomeV3/Exceptions/AlexaV3Exception.js +0 -8
  88. package/lib/AlexaSmartHomeV3/Exceptions/HourlyDeviceRateLimitExceeded.js +0 -5
  89. package/lib/AlexaSmartHomeV3/Exceptions/OverallDailyRateLimitExceeded.js +0 -5
  90. package/lib/AlexaSmartHomeV3/Helpers/AdapterProvider.js +0 -46
  91. package/lib/AlexaSmartHomeV3/Helpers/FileHelper.js +0 -70
  92. package/lib/AlexaSmartHomeV3/Helpers/IotProxy.js +0 -44
  93. package/lib/AlexaSmartHomeV3/Helpers/Logger.js +0 -95
  94. package/lib/AlexaSmartHomeV3/Helpers/RateLimiter.js +0 -82
  95. package/lib/AlexaSmartHomeV3/Helpers/Utils.js +0 -583
  96. package/lib/Utils.js +0 -608
  97. package/lib/adminCommonSocket.js +0 -781
  98. package/lib/alexaCustom.js +0 -622
  99. package/lib/alexaSmartHomeV2.js +0 -2792
  100. package/lib/alexaSmartHomeV3.js +0 -117
  101. package/lib/alisa.js +0 -2412
  102. package/lib/devices.js +0 -20
  103. package/lib/functions.js +0 -21
  104. package/lib/googleHome.js +0 -3323
  105. package/lib/notifications.js +0 -37
  106. package/lib/remote.js +0 -1363
  107. package/lib/rooms.js +0 -45
  108. package/lib/texts.js +0 -79
  109. package/lib/translate.js +0 -19
  110. package/lib/visuApp.js +0 -157
  111. package/main.js +0 -1444
package/lib/Utils.js DELETED
@@ -1,608 +0,0 @@
1
- // this file was taken unchanged from admin/src-rx/src/Utils.js
2
-
3
- const ANSI_RESET = 0;
4
- const ANSI_RESET_COLOR = 39;
5
- const ANSI_RESET_BG_COLOR = 49;
6
- const ANSI_BOLD = 1;
7
- const ANSI_RESET_BOLD = 22;
8
-
9
- const STYLES = {
10
- 30: { color: 'black' }, // ANSI_BLACK
11
- 31: { color: 'red' }, // ANSI_RED
12
- 32: { color: 'green' }, // ANSI_GREEN
13
- 33: { color: 'yellow' }, // ANSI_YELLOW
14
- 34: { color: 'blue' }, // ANSI_BLUE
15
- 35: { color: 'purple' }, // ANSI_PURPLE
16
- 36: { color: 'cyan' }, // ANSI_CYAN
17
- 37: { color: 'white' }, // ANSI_WHITE
18
-
19
- 90: { color: 'grey' }, // ANSI_BRIGHT_BLACK
20
- 91: { color: 'lightred' }, // ANSI_BRIGHT_RED
21
- 92: { color: 'lightgreen' }, // ANSI_BRIGHT_GREEN
22
- 93: { color: 'lightyellow' }, // ANSI_BRIGHT_YELLOW
23
- 94: { color: 'lightblue' }, // ANSI_BRIGHT_BLUE
24
- 95: { color: 'lightpurple' }, // ANSI_BRIGHT_PURPLE
25
- 96: { color: 'lightcyan' }, // ANSI_BRIGHT_CYAN
26
- 97: { color: 'white' }, // ANSI_BRIGHT_WHITE
27
-
28
- 40: { backgroundColor: 'black' }, // ANSI_BG_BLACK
29
- 41: { backgroundColor: 'red' }, // ANSI_BG_RED
30
- 42: { backgroundColor: 'green' }, // ANSI_BG_GREEN
31
- 43: { backgroundColor: 'yellow' }, // ANSI_BG_YELLOW
32
- 44: { backgroundColor: 'blue' }, // ANSI_BG_BLUE
33
- 45: { backgroundColor: 'purple' }, // ANSI_BG_PURPLE
34
- 46: { backgroundColor: 'cyan' }, // ANSI_BG_CYAN
35
- 47: { backgroundColor: 'white' }, // ANSI_BG_WHITE
36
-
37
- 100: { backgroundColor: 'grey' }, // ANSI_BRIGHT_BG_BLACK
38
- 101: { backgroundColor: 'lightred' }, // ANSI_BRIGHT_BG_RED
39
- 102: { backgroundColor: 'lightgreen' }, // ANSI_BRIGHT_BG_GREEN
40
- 103: { backgroundColor: 'lightyellow' }, // ANSI_BRIGHT_BG_YELLOW
41
- 104: { backgroundColor: 'lightblue' }, // ANSI_BRIGHT_BG_BLUE
42
- 105: { backgroundColor: 'lightpurple' }, // ANSI_BRIGHT_BG_PURPLE
43
- 106: { backgroundColor: 'lightcyan' }, // ANSI_BRIGHT_BG_CYAN
44
- 107: { backgroundColor: 'white' }, // ANSI_BRIGHT_BG_WHITE
45
- };
46
-
47
- class Utils {
48
- /**
49
- * Format bytes to MB or GB
50
- * @param {!number} bytes
51
- * @returns {String}
52
- */
53
- static formatRam(bytes) {
54
- const GB = Math.floor((bytes / (1024 * 1024 * 1024)) * 10) / 10;
55
- bytes %= 1024 * 1024 * 1024;
56
- const MB = Math.floor((bytes / (1024 * 1024)) * 10) / 10;
57
- let text = '';
58
-
59
- if (GB > 1) {
60
- text += GB + ' GB';
61
- } else {
62
- text += MB + ' MB';
63
- }
64
-
65
- return text;
66
- }
67
-
68
- static formatSpeed(mhz) {
69
- return mhz + ' MHz';
70
- }
71
-
72
- static formatBytes(bytes) {
73
- if (Math.abs(bytes) < 1024) {
74
- return bytes + ' B';
75
- }
76
-
77
- const units = ['KB', 'MB', 'GB'];
78
- //const units = ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
79
- let u = -1;
80
-
81
- do {
82
- bytes /= 1024;
83
- ++u;
84
- } while (Math.abs(bytes) >= 1024 && u < units.length - 1);
85
-
86
- return bytes.toFixed(1) + ' ' + units[u];
87
- }
88
-
89
- static getFileExtension(fileName) {
90
- const pos = fileName.lastIndexOf('.');
91
- if (pos !== -1) {
92
- return fileName.substring(pos + 1).toLowerCase();
93
- } else {
94
- return null;
95
- }
96
- }
97
-
98
- // Big thanks to : https://stackoverflow.com/questions/35969656/how-can-i-generate-the-opposite-color-according-to-current-color
99
- static invertColor(hex, bw) {
100
- if (hex === undefined || hex === null || hex === '' || typeof hex !== 'string') {
101
- return '';
102
- }
103
- if (hex.indexOf('#') === 0) {
104
- hex = hex.slice(1);
105
- }
106
- // convert 3-digit hex to 6-digits.
107
- if (hex.length === 3) {
108
- hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
109
- }
110
- if (hex.length !== 6) {
111
- throw new Error('Invalid HEX color.');
112
- }
113
- let r = parseInt(hex.slice(0, 2), 16);
114
- let g = parseInt(hex.slice(2, 4), 16);
115
- let b = parseInt(hex.slice(4, 6), 16);
116
-
117
- if (bw) {
118
- // http://stackoverflow.com/a/3943023/112731
119
- return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? '#000000' : '#FFFFFF';
120
- }
121
- // invert color components
122
- r = (255 - r).toString(16);
123
- g = (255 - g).toString(16);
124
- b = (255 - b).toString(16);
125
- // pad each with zeros and return
126
- return '#' + r.padStart(2, '0') + g.padStart(2, '0') + b.padStart(2, '0');
127
- }
128
-
129
- /**
130
- * Format number in seconds to a time text
131
- * @param {string} seconds
132
- * @param {function} t translate function
133
- * @returns {String}
134
- */
135
- static formatSeconds(seconds, t) {
136
- const days = Math.floor(seconds / (3600 * 24));
137
- seconds %= 3600 * 24;
138
- let hours = Math.floor(seconds / 3600);
139
- if (hours < 10) {
140
- hours = `0${hours}`;
141
- }
142
- seconds %= 3600;
143
- let minutes = Math.floor(seconds / 60);
144
- if (minutes < 10) {
145
- minutes = `0${minutes}`;
146
- }
147
- seconds %= 60;
148
- seconds = Math.floor(seconds);
149
- if (seconds < 10) {
150
- seconds = `0${seconds}`;
151
- }
152
- let text = '';
153
- if (days) {
154
- text += `${days} ${t('daysShortText')} `;
155
- }
156
- text += `${hours}:${minutes}:${seconds}`;
157
-
158
- return text;
159
- }
160
-
161
- // internal use
162
- static _replaceLink(link, objects, adapterInstance, attr, placeholder, hosts, hostname, adminInstance) {
163
- if (attr === 'protocol') {
164
- attr = 'secure';
165
- }
166
-
167
- try {
168
- const object = objects['system.adapter.' + adapterInstance];
169
-
170
- if (link && object) {
171
- if (attr === 'secure') {
172
- link = link.replace(`%${placeholder}%`, object.native[attr] ? 'https' : 'http');
173
- } else {
174
- let value = object.native[attr];
175
- // workaround for port
176
- if ((attr === 'webinterfacePort' || attr === 'port') && (!value || value === '0')) {
177
- if (object.native.secure === true) {
178
- value = 443;
179
- } else {
180
- value = 80;
181
- }
182
- }
183
-
184
- if (attr === 'bind' || attr === 'ip') {
185
- let ip = object.native.bind || object.native.ip;
186
- if (ip === '0.0.0.0') {
187
- ip = Utils.getHostname(object, objects, hosts, hostname, adminInstance);
188
- }
189
- if (!link.includes(`%${placeholder}%`)) {
190
- link = link.replace(`%native_${placeholder}%`, ip || '');
191
- } else {
192
- link = link.replace(`%${placeholder}%`, ip || '');
193
- }
194
- } else if (!link.includes(`%${placeholder}%`)) {
195
- link = link.replace(`%native_${placeholder}%`, value);
196
- } else {
197
- link = link.replace(`%${placeholder}%`, value);
198
- }
199
- }
200
- } else {
201
- console.log('Cannot get link ' + attr);
202
- link = link.replace(`%${placeholder}%`, '');
203
- }
204
- } catch (error) {
205
- console.log(error);
206
- }
207
- return link;
208
- }
209
-
210
- static ip2int(ip) {
211
- return ip.split('.').reduce((ipInt, octet) => (ipInt << 8) + parseInt(octet, 10), 0) >>> 0;
212
- }
213
-
214
- static findNetworkAddressOfHost(obj, localIp) {
215
- const networkInterfaces = obj && obj.native && obj.native.hardware && obj.native.hardware.networkInterfaces;
216
- if (!networkInterfaces) {
217
- return null;
218
- }
219
-
220
- let hostIp;
221
- Object.keys(networkInterfaces).forEach(inter => {
222
- networkInterfaces[inter].forEach(ip => {
223
- if (ip.internal) {
224
- return;
225
- } else if (localIp.includes(':') && ip.family !== 'IPv6') {
226
- return;
227
- } else if (localIp.includes('.') && !localIp.match(/[^.\d]/) && ip.family !== 'IPv4') {
228
- return;
229
- }
230
- if (localIp === '127.0.0.0' || localIp === 'localhost' || localIp.match(/[^.\d]/)) {
231
- // if DNS name
232
- hostIp = ip.address;
233
- } else {
234
- if (
235
- ip.family === 'IPv4' &&
236
- localIp.includes('.') &&
237
- (Utils.ip2int(localIp) & Utils.ip2int(ip.netmask)) ===
238
- (Utils.ip2int(ip.address) & Utils.ip2int(ip.netmask))
239
- ) {
240
- hostIp = ip.address;
241
- } else {
242
- hostIp = ip.address;
243
- }
244
- }
245
- });
246
- });
247
-
248
- if (!hostIp) {
249
- Object.keys(networkInterfaces).forEach(inter => {
250
- networkInterfaces[inter].forEach(ip => {
251
- if (ip.internal) {
252
- return;
253
- } else if (localIp.includes(':') && ip.family !== 'IPv6') {
254
- return;
255
- } else if (localIp.includes('.') && !localIp.match(/[^.\d]/) && ip.family !== 'IPv4') {
256
- return;
257
- }
258
- if (localIp === '127.0.0.0' || localIp === 'localhost' || localIp.match(/[^.\d]/)) {
259
- // if DNS name
260
- hostIp = ip.address;
261
- } else {
262
- hostIp = ip.address;
263
- }
264
- });
265
- });
266
- }
267
-
268
- if (!hostIp) {
269
- Object.keys(networkInterfaces).forEach(inter => {
270
- networkInterfaces[inter].forEach(ip => {
271
- if (ip.internal) {
272
- return;
273
- }
274
- hostIp = ip.address;
275
- });
276
- });
277
- }
278
-
279
- return hostIp;
280
- }
281
-
282
- static getHostname(instanceObj, objects, hosts, currentHostname, adminInstance) {
283
- if (!instanceObj || !instanceObj.common) {
284
- return null;
285
- }
286
-
287
- let hostname;
288
- // check if the adapter from the same host as admin
289
- const adminHost =
290
- objects['system.adapter.' + adminInstance] &&
291
- objects['system.adapter.' + adminInstance].common &&
292
- objects['system.adapter.' + adminInstance].common.host;
293
- if (instanceObj.common.host !== adminHost) {
294
- // find IP address
295
- const host = hosts.find(obj => obj._id === 'system.host.' + instanceObj.common.host);
296
- if (host) {
297
- const ip = Utils.findNetworkAddressOfHost(host, currentHostname);
298
- if (ip) {
299
- hostname = ip;
300
- } else {
301
- console.warn(`Cannot find suitable IP in host ${instanceObj.common.host} for ${instanceObj._id}`);
302
- return null;
303
- }
304
- } else {
305
- console.warn(`Cannot find host ${instanceObj.common.host} for ${instanceObj._id}`);
306
- return null;
307
- }
308
- } else {
309
- hostname = currentHostname;
310
- }
311
- return hostname;
312
- }
313
-
314
- /**
315
- * Format number in seconds to time text
316
- * @param {string} link pattern for link
317
- * @param {string} adapter admin name
318
- * @param {string} instance admin instance
319
- * @param {object} context {objects, hostname(of browser), protocol(of browser)}
320
- * @returns {array<any>}
321
- */
322
- static replaceLink(link, adapter, instance, context) {
323
- const _urls = [];
324
- let port;
325
-
326
- if (link) {
327
- const instanceObj = context.objects[`system.adapter.${adapter}.${instance}`];
328
- const native = (instanceObj && instanceObj.native) || {};
329
-
330
- let placeholders = link.match(/%(\w+)%/g);
331
-
332
- if (placeholders) {
333
- for (let p = 0; p < placeholders.length; p++) {
334
- let placeholder = placeholders[p];
335
-
336
- if (placeholder === '%ip%') {
337
- let ip = native.bind || native.ip;
338
- if (!ip || ip === '127.0.0.1' || ip === 'localhost' || ip === '0.0.0.0') {
339
- // Check host
340
- ip = Utils.getHostname(
341
- instanceObj,
342
- context.objects,
343
- context.hosts,
344
- context.hostname,
345
- context.adminInstance,
346
- );
347
- }
348
-
349
- if (_urls.length) {
350
- _urls.forEach(item => (item.url = item.url.replace('%ip%', ip)));
351
- } else {
352
- link = link.replace('%ip%', ip || '');
353
- }
354
- } else if (placeholder === '%protocol%') {
355
- let protocol = native.secure === undefined ? native.protocol : native.secure;
356
- if (protocol === true || protocol === 'true') {
357
- protocol = 'https';
358
- } else if (protocol === false || protocol === 'false' || !protocol) {
359
- protocol = 'http';
360
- }
361
- protocol = protocol.replace(/:$/, '');
362
-
363
- if (_urls.length) {
364
- _urls.forEach(item => (item.url = item.url.replace('%protocol%', protocol)));
365
- } else {
366
- link = link.replace('%protocol%', protocol);
367
- }
368
- } else if (placeholder === '%instance%') {
369
- link = link.replace('%instance%', instance);
370
- if (_urls.length) {
371
- _urls.forEach(item => (item.url = item.url.replace('%instance%', instance)));
372
- } else {
373
- link = link.replace('%instance%', instance);
374
- }
375
- } else {
376
- // remove %%
377
- placeholder = placeholder.replace(/%/g, '');
378
-
379
- if (placeholder.startsWith('native_')) {
380
- placeholder = placeholder.substring(7);
381
- }
382
-
383
- // like web.0_port or web_protocol
384
- if (!placeholder.includes('_')) {
385
- // if only one instance
386
- const adapterInstance = adapter + '.' + instance;
387
- if (_urls.length) {
388
- _urls.forEach(
389
- item =>
390
- (item.url = Utils._replaceLink(
391
- item.url,
392
- context.objects,
393
- adapterInstance,
394
- placeholder,
395
- placeholder,
396
- context.hosts,
397
- context.hostname,
398
- context.adminInstance,
399
- )),
400
- );
401
- } else {
402
- link = Utils._replaceLink(
403
- link,
404
- context.objects,
405
- adapterInstance,
406
- placeholder,
407
- placeholder,
408
- context.hosts,
409
- context.hostname,
410
- context.adminInstance,
411
- );
412
- port =
413
- context.objects['system.adapter.' + adapterInstance] &&
414
- context.objects['system.adapter.' + adapterInstance].native &&
415
- context.objects['system.adapter.' + adapterInstance].native.port;
416
- }
417
- } else {
418
- const [adapterInstance, attr] = placeholder.split('_');
419
-
420
- // if instance number not found
421
- if (!adapterInstance.match(/\.[0-9]+$/)) {
422
- // list all possible instances
423
- let ids;
424
- if (adapter === adapterInstance) {
425
- // take only this one instance and that's all
426
- ids = [adapter + '.' + instance];
427
- } else {
428
- ids = Object.keys(context.objects)
429
- .filter(
430
- id =>
431
- id.startsWith('system.adapter.' + adapterInstance + '.') &&
432
- context.objects[id].common.enabled,
433
- )
434
- .map(id => id.substring(15));
435
- }
436
-
437
- // eslint-disable-next-line
438
- ids.forEach(id => {
439
- if (_urls.length) {
440
- const item = _urls.find(t => t.instance === id);
441
- if (item) {
442
- item.url = Utils._replaceLink(
443
- item.url,
444
- context.objects,
445
- id,
446
- attr,
447
- placeholder,
448
- context.hosts,
449
- context.hostname,
450
- context.adminInstance,
451
- );
452
- } else {
453
- // add new
454
- const _link = Utils._replaceLink(
455
- link,
456
- context.objects,
457
- id,
458
- attr,
459
- placeholder,
460
- context.hosts,
461
- context.hostname,
462
- context.adminInstance,
463
- );
464
- const _port =
465
- context.objects['system.adapter.' + id] &&
466
- context.objects['system.adapter.' + id].native &&
467
- context.objects['system.adapter.' + id].native.port;
468
- _urls.push({ url: _link, port: _port, instance: id });
469
- }
470
- } else {
471
- const _link = Utils._replaceLink(
472
- link,
473
- context.objects,
474
- id,
475
- attr,
476
- placeholder,
477
- context.hosts,
478
- context.hostname,
479
- context.adminInstance,
480
- );
481
- const _port =
482
- context.objects['system.adapter.' + id] &&
483
- context.objects['system.adapter.' + id].native &&
484
- context.objects['system.adapter.' + id].native.port;
485
- _urls.push({ url: _link, port: _port, instance: id });
486
- }
487
- });
488
- } else {
489
- link = Utils._replaceLink(
490
- link,
491
- context.objects,
492
- adapterInstance,
493
- attr,
494
- placeholder,
495
- context.hosts,
496
- context.hostname,
497
- context.adminInstance,
498
- );
499
- port =
500
- context.objects['system.adapter.' + adapterInstance] &&
501
- context.objects['system.adapter.' + adapterInstance].native &&
502
- context.objects['system.adapter.' + adapterInstance].native.port;
503
- }
504
- }
505
- }
506
- }
507
- }
508
- }
509
-
510
- if (_urls.length) {
511
- return _urls;
512
- } else {
513
- return [{ url: link, port }];
514
- }
515
- }
516
-
517
- static objectMap(object, callback) {
518
- let result = [];
519
- for (let key in object) {
520
- result.push(callback(object[key], key));
521
- }
522
- return result;
523
- }
524
-
525
- static fixAdminUI(obj) {
526
- if (obj && obj.common && !obj.common.adminUI) {
527
- if (obj.common.noConfig) {
528
- obj.common.adminUI = obj.common.adminUI || {};
529
- obj.common.adminUI.config = 'none';
530
- } else if (obj.common.jsonConfig) {
531
- obj.common.adminUI = obj.common.adminUI || {};
532
- obj.common.adminUI.config = 'json';
533
- } else if (obj.common.materialize) {
534
- obj.common.adminUI = obj.common.adminUI || {};
535
- obj.common.adminUI.config = 'materialize';
536
- } else {
537
- obj.common.adminUI = obj.common.adminUI || {};
538
- obj.common.adminUI.config = 'html';
539
- }
540
-
541
- if (obj.common.jsonCustom) {
542
- obj.common.adminUI = obj.common.adminUI || {};
543
- obj.common.adminUI.custom = 'json';
544
- } else if (obj.common.supportCustoms) {
545
- obj.common.adminUI = obj.common.adminUI || {};
546
- obj.common.adminUI.custom = 'json';
547
- }
548
-
549
- if (obj.common.materializeTab && obj.common.adminTab) {
550
- obj.common.adminUI = obj.common.adminUI || {};
551
- obj.common.adminUI.tab = 'materialize';
552
- } else if (obj.common.adminTab) {
553
- obj.common.adminUI = obj.common.adminUI || {};
554
- obj.common.adminUI.tab = 'html';
555
- }
556
-
557
- obj.common.adminUI &&
558
- console.warn(
559
- `Please add to "${obj._id.replace(/\.\d+$/, '')}" common.adminUI=${JSON.stringify(obj.common.adminUI)}`,
560
- );
561
- }
562
- }
563
-
564
- static parseColorMessage(text) {
565
- if (text && (text.includes('\u001b[') || text.includes('\u001B['))) {
566
- // eslint-disable-next-line
567
- let m = text.match(/\u001b\[\d+m/gi);
568
- if (m) {
569
- const original = text;
570
- const result = [];
571
- let style = {};
572
- for (let i = 0; i < m.length; i++) {
573
- const pos = text.indexOf(m[i]);
574
- if (pos) {
575
- result.push({ text: text.substring(0, pos), style: JSON.parse(JSON.stringify(style)) });
576
- }
577
- const code = parseInt(m[i].substring(2), 10);
578
- if (STYLES[code]) {
579
- Object.assign(style, STYLES[code]);
580
- } else if (ANSI_RESET_COLOR === code) {
581
- delete style.color;
582
- } else if (ANSI_RESET_BG_COLOR === code) {
583
- delete style.backgroundColor;
584
- } else if (ANSI_RESET_BOLD === code) {
585
- delete style.fontWeight;
586
- } else if (ANSI_BOLD === code) {
587
- style.fontWeight = 'bold';
588
- } else if (ANSI_RESET === code) {
589
- style = {};
590
- }
591
- text = text.substring(m[i].length + pos);
592
- }
593
- if (text) {
594
- result.push({ text, style: JSON.parse(JSON.stringify(style)) });
595
- }
596
-
597
- return { original, parts: result };
598
- } else {
599
- return text;
600
- }
601
- } else {
602
- return text;
603
- }
604
- }
605
- }
606
-
607
- module.exports = Utils;
608
- // export default Utils;