@realvare/based 2.6.25 → 2.6.252
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/lib/Socket/messages-send.js +4 -2
- package/lib/Utils/messages-media.js +18 -19
- package/package.json +11 -7
- package/lib/Utils/thumbnail.js +0 -18
|
@@ -16,7 +16,7 @@ const WABinary_1 = require("../WABinary");
|
|
|
16
16
|
const WAUSync_1 = require("../WAUSync");
|
|
17
17
|
const newsletter_1 = require("./newsletter");
|
|
18
18
|
const rate_limiter_1 = __importDefault(require("../Utils/rate-limiter"));
|
|
19
|
-
const { generateThumbnail } = require("../Utils/
|
|
19
|
+
const { generateThumbnail, getHttpStream, toBuffer } = require("../Utils/messages-media");
|
|
20
20
|
const makeMessagesSocket = (config) => {
|
|
21
21
|
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, } = config;
|
|
22
22
|
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
@@ -280,7 +280,9 @@ const makeMessagesSocket = (config) => {
|
|
|
280
280
|
if(message.contextInfo?.externalAdReply?.thumbnailUrl) {
|
|
281
281
|
try {
|
|
282
282
|
const { externalAdReply } = message.contextInfo;
|
|
283
|
-
const
|
|
283
|
+
const stream = await getHttpStream(externalAdReply.thumbnailUrl);
|
|
284
|
+
const buffer = await toBuffer(stream);
|
|
285
|
+
const { thumbnail } = await generateThumbnail(buffer, 'image', { logger });
|
|
284
286
|
message.contextInfo.externalAdReply = {
|
|
285
287
|
...externalAdReply,
|
|
286
288
|
thumbnail,
|
|
@@ -63,10 +63,22 @@ 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
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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('sharp'))).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 };
|
|
70
82
|
}
|
|
71
83
|
throw new boom_1.Boom('No image processing library available');
|
|
72
84
|
};
|
|
@@ -467,21 +479,8 @@ async function generateThumbnail(file, mediaType, options) {
|
|
|
467
479
|
};
|
|
468
480
|
}
|
|
469
481
|
const getHttpStream = async (url, options = {}) => {
|
|
470
|
-
const {
|
|
471
|
-
|
|
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
|
-
}
|
|
482
|
+
const fetched = await axios_1.default.get(url.toString(), { ...options, responseType: 'stream' });
|
|
483
|
+
return fetched.data;
|
|
485
484
|
};
|
|
486
485
|
exports.getHttpStream = getHttpStream;
|
|
487
486
|
const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@realvare/based",
|
|
3
|
-
"version": "2.6.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.6.252",
|
|
4
|
+
"description": "whatsapp api by sam",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baileys",
|
|
7
7
|
"whatsapp",
|
|
@@ -9,9 +9,7 @@
|
|
|
9
9
|
"whatsapp-web",
|
|
10
10
|
"whatsapp-bot",
|
|
11
11
|
"automation",
|
|
12
|
-
"multi-device"
|
|
13
|
-
"lid",
|
|
14
|
-
"based"
|
|
12
|
+
"multi-device"
|
|
15
13
|
],
|
|
16
14
|
"homepage": "https://github.com/realvare/based.git",
|
|
17
15
|
"repository": {
|
|
@@ -66,6 +64,7 @@
|
|
|
66
64
|
"@types/got": "^9.6.11",
|
|
67
65
|
"@types/jest": "^29.5.12",
|
|
68
66
|
"@types/node": "^20.14.0",
|
|
67
|
+
"@types/sharp": "^0.32.0",
|
|
69
68
|
"@types/ws": "^8.5.10",
|
|
70
69
|
"conventional-changelog-cli": "^2.2.2",
|
|
71
70
|
"eslint": "^8.57.0",
|
|
@@ -76,6 +75,7 @@
|
|
|
76
75
|
"open": "^10.1.0",
|
|
77
76
|
"qrcode-terminal": "^0.12.0",
|
|
78
77
|
"release-it": "^16.1.0",
|
|
78
|
+
"sharp": "^0.33.5",
|
|
79
79
|
"ts-jest": "^29.1.2",
|
|
80
80
|
"ts-node": "^10.9.2",
|
|
81
81
|
"typedoc": "^0.25.12",
|
|
@@ -84,7 +84,8 @@
|
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"audio-decode": "^2.1.3",
|
|
86
86
|
"link-preview-js": "^3.0.0",
|
|
87
|
-
"qrcode-terminal": "^0.12.0"
|
|
87
|
+
"qrcode-terminal": "^0.12.0",
|
|
88
|
+
"sharp": "^0.33.0"
|
|
88
89
|
},
|
|
89
90
|
"peerDependenciesMeta": {
|
|
90
91
|
"audio-decode": {
|
|
@@ -95,10 +96,13 @@
|
|
|
95
96
|
},
|
|
96
97
|
"link-preview-js": {
|
|
97
98
|
"optional": true
|
|
99
|
+
},
|
|
100
|
+
"sharp": {
|
|
101
|
+
"optional": true
|
|
98
102
|
}
|
|
99
103
|
},
|
|
100
104
|
"packageManager": "yarn@1.22.19",
|
|
101
105
|
"engines": {
|
|
102
106
|
"node": ">=20.0.0"
|
|
103
107
|
}
|
|
104
|
-
}
|
|
108
|
+
}
|
package/lib/Utils/thumbnail.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const Jimp = require('jimp');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Generates a high-quality JPEG thumbnail buffer for externalAdReply.
|
|
5
|
-
* @param {string | Buffer} imagePathOrBuffer - Path to image file, Buffer, or URL.
|
|
6
|
-
* @param {number} [size=150] - Target square size (default 150 for balance between quality and load time).
|
|
7
|
-
* @param {number} [quality=100] - JPEG quality (1-100, default 100 for maximum quality).
|
|
8
|
-
* @returns {Promise<Buffer>} - High-quality thumbnail buffer.
|
|
9
|
-
*/
|
|
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);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = { generateThumbnail };
|