iobroker.mywebui 1.42.31 → 1.42.32

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/io-package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "mywebui",
4
- "version": "1.42.31",
4
+ "version": "1.42.32",
5
5
  "titleLang": {
6
6
  "en": "mywebui",
7
7
  "de": "mywebui",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.mywebui",
3
- "version": "1.42.31",
3
+ "version": "1.42.32",
4
4
  "description": "ioBroker mywebui - Custom edited mywebui by gokturk413 with 3D Editor",
5
5
  "type": "module",
6
6
  "main": "dist/backend/main.js",
@@ -587,19 +587,51 @@ export class IobrokerHandler {
587
587
  }
588
588
  async _getObjectFromFile(name) {
589
589
  const file = await this.connection.readFile(this.namespaceFiles, name, false);
590
+ let bytes;
590
591
  if (file.mimeType == 'application/json' || file.mimeType == 'text/javascript') {
591
592
  return JSON.parse(file.file);
593
+ } else if (file.mimeType == 'application/octet-stream' && file.file instanceof ArrayBuffer) {
594
+ bytes = new Uint8Array(file.file);
595
+ } else {
596
+ bytes = Uint8Array.from(file.file.data);
592
597
  }
593
- if (file.mimeType == "application/octet-stream" && file.file instanceof ArrayBuffer) {
594
- const dec = new TextDecoder();
595
- return JSON.parse(dec.decode(file.file));
598
+ // Gzip magic bytes 1f 8b decompress transparently
599
+ if (bytes[0] === 0x1f && bytes[1] === 0x8b && window.DecompressionStream) {
600
+ bytes = await this._gunzipBytes(bytes);
596
601
  }
597
- const dec = new TextDecoder();
598
- return JSON.parse(dec.decode(Uint8Array.from(file.file.data)));
602
+ return JSON.parse(new TextDecoder().decode(bytes));
599
603
  }
600
604
  async _saveObjectToFile(obj, name) {
601
- const enc = new TextEncoder();
602
- await this.connection.writeFile64(this.namespaceFiles, name, enc.encode(JSON.stringify(obj)));
605
+ const bytes = new TextEncoder().encode(JSON.stringify(obj));
606
+ // Compress files >512 KB to prevent WebSocket message overflow
607
+ if (bytes.length > 512 * 1024 && window.CompressionStream) {
608
+ const compressed = await this._gzipBytes(bytes);
609
+ await this.connection.writeFile64(this.namespaceFiles, name, compressed.buffer);
610
+ } else {
611
+ await this.connection.writeFile64(this.namespaceFiles, name, bytes);
612
+ }
613
+ }
614
+ async _gzipBytes(bytes) {
615
+ const cs = new CompressionStream('gzip');
616
+ const w = cs.writable.getWriter();
617
+ w.write(bytes); w.close();
618
+ const r = cs.readable.getReader();
619
+ const chunks = []; let res;
620
+ while (!(res = await r.read()).done) chunks.push(res.value);
621
+ const out = new Uint8Array(chunks.reduce((s, c) => s + c.length, 0));
622
+ let off = 0; for (const c of chunks) { out.set(c, off); off += c.length; }
623
+ return out;
624
+ }
625
+ async _gunzipBytes(bytes) {
626
+ const ds = new DecompressionStream('gzip');
627
+ const w = ds.writable.getWriter();
628
+ w.write(bytes); w.close();
629
+ const r = ds.readable.getReader();
630
+ const chunks = []; let res;
631
+ while (!(res = await r.read()).done) chunks.push(res.value);
632
+ const out = new Uint8Array(chunks.reduce((s, c) => s + c.length, 0));
633
+ let off = 0; for (const c of chunks) { out.set(c, off); off += c.length; }
634
+ return out;
603
635
  }
604
636
  async _saveBinaryToFile(binary, name) {
605
637
  await this.connection.writeFile64(this.namespaceFiles, name, await binary.arrayBuffer());