@realvare/based 2.6.23 → 2.6.25

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.
@@ -63,22 +63,10 @@ const crypto_1 = require("./crypto");
63
63
  const generics_1 = require("./generics");
64
64
  const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
65
65
  const getImageProcessingLibrary = async () => {
66
- const [_jimp, sharp] = await Promise.all([
67
- (async () => {
68
- const jimp = await (Promise.resolve().then(() => __importStar(require('jimp'))).catch(() => { }));
69
- return jimp;
70
- })(),
71
- (async () => {
72
- const sharp = await (Promise.resolve().then(() => __importStar(require('@img/sharp-wasm32'))).catch(() => { }));
73
- return sharp;
74
- })()
75
- ]);
76
- if (sharp) {
77
- return { sharp };
78
- }
79
- const jimp = (_jimp === null || _jimp === void 0 ? void 0 : _jimp.default) || _jimp;
80
- if (jimp) {
81
- return { jimp };
66
+ const jimp = await (Promise.resolve().then(() => __importStar(require('jimp'))).catch(() => { }));
67
+ const jimpLib = (jimp === null || jimp === void 0 ? void 0 : jimp.default) || jimp;
68
+ if (jimpLib) {
69
+ return { jimp: jimpLib };
82
70
  }
83
71
  throw new boom_1.Boom('No image processing library available');
84
72
  };
@@ -479,8 +467,21 @@ async function generateThumbnail(file, mediaType, options) {
479
467
  };
480
468
  }
481
469
  const getHttpStream = async (url, options = {}) => {
482
- const fetched = await axios_1.default.get(url.toString(), { ...options, responseType: 'stream' });
483
- return fetched.data;
470
+ const { retryRequestDelayMs, maxMsgRetryCount } = options;
471
+ let retries = 0;
472
+ while (retries < maxMsgRetryCount) {
473
+ try {
474
+ const fetched = await axios_1.default.get(url.toString(), { ...options, responseType: 'stream' });
475
+ return fetched.data;
476
+ }
477
+ catch (error) {
478
+ retries++;
479
+ if (retries >= maxMsgRetryCount) {
480
+ throw error;
481
+ }
482
+ await (0, generics_1.delay)(retryRequestDelayMs || 1000);
483
+ }
484
+ }
484
485
  };
485
486
  exports.getHttpStream = getHttpStream;
486
487
  const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
@@ -1,35 +1,18 @@
1
- const sharp = require('@img/sharp-wasm32');
2
- const fs = require('fs/promises');
3
- const fetch = require('node-fetch');
1
+ const Jimp = require('jimp');
4
2
 
5
3
  /**
6
- * Generates an optimized JPEG thumbnail buffer for externalAdReply.
4
+ * Generates a high-quality JPEG thumbnail buffer for externalAdReply.
7
5
  * @param {string | Buffer} imagePathOrBuffer - Path to image file, Buffer, or URL.
8
6
  * @param {number} [size=150] - Target square size (default 150 for balance between quality and load time).
9
- * @param {number} [quality=85] - JPEG quality (1-100, default 85).
10
- * @returns {Promise<Buffer>} - Optimized thumbnail buffer.
7
+ * @param {number} [quality=100] - JPEG quality (1-100, default 100 for maximum quality).
8
+ * @returns {Promise<Buffer>} - High-quality thumbnail buffer.
11
9
  */
12
- async function generateThumbnail(imagePathOrBuffer, size = 150, quality = 85) {
13
- let input;
14
-
15
- if (typeof imagePathOrBuffer === 'string') {
16
- if (imagePathOrBuffer.startsWith('http')) {
17
- // Fetch from URL
18
- const response = await fetch(imagePathOrBuffer);
19
- input = Buffer.from(await response.arrayBuffer());
20
- } else {
21
- // Local file
22
- input = await fs.readFile(imagePathOrBuffer);
23
- }
24
- } else {
25
- input = imagePathOrBuffer;
26
- }
27
-
28
- return sharp(input)
29
- .resize(size, size, { fit: 'cover', kernel: sharp.kernel.lanczos3 }) // Lanczos for sharp resizing
30
- .sharpen() // Optional: Adds slight sharpness to counter blurring
31
- .jpeg({ quality, mozjpeg: true }) // Use high-quality JPEG compression
32
- .toBuffer();
10
+ async function generateThumbnail(imagePathOrBuffer, size = 150, quality = 100) {
11
+ const image = await Jimp.read(imagePathOrBuffer);
12
+ return image
13
+ .cover(size, size) // Cover fit for square thumbnail
14
+ .quality(quality) // Set JPEG quality
15
+ .getBufferAsync(Jimp.MIME_JPEG);
33
16
  }
34
17
 
35
18
  module.exports = { generateThumbnail };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realvare/based",
3
- "version": "2.6.23",
3
+ "version": "2.6.25",
4
4
  "description": "WhatsApp Web API by Sam",
5
5
  "keywords": [
6
6
  "baileys",
@@ -11,7 +11,7 @@
11
11
  "automation",
12
12
  "multi-device",
13
13
  "lid",
14
- "anti-ban"
14
+ "based"
15
15
  ],
16
16
  "homepage": "https://github.com/realvare/based.git",
17
17
  "repository": {
@@ -58,7 +58,6 @@
58
58
  "music-metadata": "^7.12.3",
59
59
  "pino": "^9.6",
60
60
  "protobufjs": "^7.2.5",
61
- "@img/sharp-wasm32": "^0.33.5",
62
61
  "uuid": "^10.0.0",
63
62
  "ws": "^8.18.0"
64
63
  },
@@ -77,7 +76,6 @@
77
76
  "open": "^10.1.0",
78
77
  "qrcode-terminal": "^0.12.0",
79
78
  "release-it": "^16.1.0",
80
- "@img/sharp-wasm32": "^0.33.5",
81
79
  "ts-jest": "^29.1.2",
82
80
  "ts-node": "^10.9.2",
83
81
  "typedoc": "^0.25.12",
@@ -86,8 +84,7 @@
86
84
  "peerDependencies": {
87
85
  "audio-decode": "^2.1.3",
88
86
  "link-preview-js": "^3.0.0",
89
- "qrcode-terminal": "^0.12.0",
90
- "@img/sharp-wasm32": "^0.33.0"
87
+ "qrcode-terminal": "^0.12.0"
91
88
  },
92
89
  "peerDependenciesMeta": {
93
90
  "audio-decode": {