@apocaliss92/nodedreame 1.8.0 → 1.8.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.
- package/dist/index.cjs +35 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/support/version.ts
|
|
2
2
|
var LIBRARY_NAME = "nodedreame";
|
|
3
|
-
var LIBRARY_VERSION = "1.8.
|
|
3
|
+
var LIBRARY_VERSION = "1.8.1";
|
|
4
4
|
|
|
5
5
|
// src/transport/errors.ts
|
|
6
6
|
var DreameError = class extends Error {
|
|
@@ -1882,11 +1882,43 @@ function unwrapEnvelope(value, opts = {}) {
|
|
|
1882
1882
|
}
|
|
1883
1883
|
bytes = aesCbcDecrypt(bytes, key2, opts.iv);
|
|
1884
1884
|
}
|
|
1885
|
+
let inflated;
|
|
1885
1886
|
try {
|
|
1886
|
-
|
|
1887
|
+
inflated = zlib.inflateSync(bytes);
|
|
1887
1888
|
} catch (err) {
|
|
1888
1889
|
throw new MapDecodeError("envelope: zlib inflate failed", { cause: err });
|
|
1889
1890
|
}
|
|
1891
|
+
let guard = 0;
|
|
1892
|
+
while (guard < MAX_EXTRA_WRAP_LAYERS && looksLikeBase64Zlib(inflated)) {
|
|
1893
|
+
const text = inflated.toString("latin1").replace(/-/g, "+").replace(/_/g, "/");
|
|
1894
|
+
try {
|
|
1895
|
+
inflated = zlib.inflateSync(Buffer.from(text, "base64"));
|
|
1896
|
+
} catch (err) {
|
|
1897
|
+
throw new MapDecodeError("envelope: nested zlib inflate failed", { cause: err });
|
|
1898
|
+
}
|
|
1899
|
+
guard += 1;
|
|
1900
|
+
}
|
|
1901
|
+
return inflated;
|
|
1902
|
+
}
|
|
1903
|
+
var MAX_EXTRA_WRAP_LAYERS = 4;
|
|
1904
|
+
function looksLikeBase64Zlib(buf) {
|
|
1905
|
+
if (buf.length < 8) return false;
|
|
1906
|
+
for (const b of buf) {
|
|
1907
|
+
const isB64 = b >= 65 && b <= 90 || // A-Z
|
|
1908
|
+
b >= 97 && b <= 122 || // a-z
|
|
1909
|
+
b >= 48 && b <= 57 || // 0-9
|
|
1910
|
+
b === 43 || b === 47 || // + /
|
|
1911
|
+
b === 45 || b === 95 || // - _ (url-safe)
|
|
1912
|
+
b === 61;
|
|
1913
|
+
if (!isB64) return false;
|
|
1914
|
+
}
|
|
1915
|
+
try {
|
|
1916
|
+
const prefix = buf.subarray(0, 16).toString("latin1").replace(/-/g, "+").replace(/_/g, "/");
|
|
1917
|
+
const decoded = Buffer.from(prefix, "base64");
|
|
1918
|
+
return decoded.length >= 2 && decoded[0] === 120;
|
|
1919
|
+
} catch {
|
|
1920
|
+
return false;
|
|
1921
|
+
}
|
|
1890
1922
|
}
|
|
1891
1923
|
function aesCbcDecrypt(cipher, rawKey, iv) {
|
|
1892
1924
|
const keyBytes = Buffer.from(
|
|
@@ -2522,7 +2554,7 @@ function decodeCleanedAreaPixels(pixels, width, height) {
|
|
|
2522
2554
|
|
|
2523
2555
|
// src/models/vacuum/map/decode.ts
|
|
2524
2556
|
function decodeVacuumMap(input, opts = {}) {
|
|
2525
|
-
const inflated = typeof input === "string" ? unwrapEnvelope(input, opts) : input;
|
|
2557
|
+
const inflated = typeof input === "string" ? unwrapEnvelope(input, opts) : looksLikeBase64Zlib(input) ? unwrapEnvelope(input.toString("latin1"), opts) : input;
|
|
2526
2558
|
const { header, tail } = parseFrame(inflated);
|
|
2527
2559
|
const dimensions = mergeDimensions(header, tail);
|
|
2528
2560
|
const robot = pose(header.robotX, header.robotY, header.robotA, tail.nr === true);
|