zalo-agent-cli 1.0.16 → 1.0.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zalo-agent-cli",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "CLI tool for Zalo automation — multi-account, proxy support, bank transfers, QR payments",
5
5
  "type": "module",
6
6
  "bin": {
@@ -3,6 +3,7 @@
3
3
  * Manages a single Zalo instance per process. Swap on account switch.
4
4
  */
5
5
 
6
+ import fs from "fs";
6
7
  import { Zalo, LoginQRCallbackEventType } from "zca-js";
7
8
  import { HttpsProxyAgent } from "https-proxy-agent";
8
9
  import nodefetch from "node-fetch";
@@ -10,6 +11,67 @@ import { getActive } from "./accounts.js";
10
11
  import { loadCredentials } from "./credentials.js";
11
12
  import { info } from "../utils/output.js";
12
13
 
14
+ /**
15
+ * Read image dimensions from file header bytes (PNG, JPEG, GIF).
16
+ * Returns { width, height, size } or null on failure.
17
+ */
18
+ async function readImageMetadata(filePath) {
19
+ const stat = await fs.promises.stat(filePath);
20
+ const buf = Buffer.alloc(32);
21
+ const fh = await fs.promises.open(filePath, "r");
22
+ try {
23
+ await fh.read(buf, 0, 32, 0);
24
+ } finally {
25
+ await fh.close();
26
+ }
27
+
28
+ let width = 0;
29
+ let height = 0;
30
+
31
+ // PNG: bytes 0-3 = 0x89504E47, width at 16, height at 20 (big-endian)
32
+ if (buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47) {
33
+ width = buf.readUInt32BE(16);
34
+ height = buf.readUInt32BE(20);
35
+ }
36
+ // GIF: "GIF87a" or "GIF89a", width at 6, height at 8 (little-endian)
37
+ else if (buf[0] === 0x47 && buf[1] === 0x49 && buf[2] === 0x46) {
38
+ width = buf.readUInt16LE(6);
39
+ height = buf.readUInt16LE(8);
40
+ }
41
+ // JPEG: 0xFFD8 — scan segments via file handle to avoid loading entire file
42
+ else if (buf[0] === 0xff && buf[1] === 0xd8) {
43
+ const jfh = await fs.promises.open(filePath, "r");
44
+ try {
45
+ const seg = Buffer.alloc(9); // enough for marker(2) + length(2) + precision(1) + h(2) + w(2)
46
+ let pos = 2; // skip SOI
47
+ while (pos < stat.size - 9) {
48
+ const { bytesRead } = await jfh.read(seg, 0, 4, pos);
49
+ if (bytesRead < 4 || seg[0] !== 0xff) break;
50
+ const marker = seg[1];
51
+ if (
52
+ (marker >= 0xc0 && marker <= 0xc3) ||
53
+ (marker >= 0xc5 && marker <= 0xc7) ||
54
+ (marker >= 0xc9 && marker <= 0xcb) ||
55
+ (marker >= 0xcd && marker <= 0xcf)
56
+ ) {
57
+ // Read 5 more bytes: segment length(2) + precision(1) + height(2) + width(2)
58
+ await jfh.read(seg, 0, 7, pos + 2);
59
+ height = seg.readUInt16BE(3);
60
+ width = seg.readUInt16BE(5);
61
+ break;
62
+ }
63
+ const segLen = seg.readUInt16BE(2);
64
+ pos += 2 + segLen;
65
+ }
66
+ } finally {
67
+ await jfh.close();
68
+ }
69
+ }
70
+
71
+ if (width === 0 || height === 0) return null;
72
+ return { width, height, size: stat.size };
73
+ }
74
+
13
75
  let _api = null;
14
76
  let _ownId = null;
15
77
 
@@ -34,6 +96,7 @@ function createZalo(proxyUrl) {
34
96
  const opts = {
35
97
  // Suppress zca-js internal INFO logs when --json to keep stdout clean
36
98
  logging: !process.env.ZALO_JSON_MODE,
99
+ imageMetadataGetter: readImageMetadata,
37
100
  };
38
101
  if (proxyUrl) {
39
102
  opts.agent = new HttpsProxyAgent(proxyUrl);