@periskope/baileys 6.7.12-alpha.1 → 6.7.12-alpha.3
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.
|
@@ -84,15 +84,18 @@ const getUrlInfo = async (text, opts = {
|
|
|
84
84
|
originalThumbnailUrl: image
|
|
85
85
|
};
|
|
86
86
|
if (opts.uploadImage) {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
:
|
|
95
|
-
|
|
87
|
+
const imageBuffer = await (0, messages_media_1.processImage)(image);
|
|
88
|
+
if (imageBuffer) {
|
|
89
|
+
const { imageMessage } = await (0, messages_1.prepareWAMessageMedia)({ image: imageBuffer }, {
|
|
90
|
+
upload: opts.uploadImage,
|
|
91
|
+
mediaTypeOverride: 'thumbnail-link',
|
|
92
|
+
options: opts.fetchOpts
|
|
93
|
+
});
|
|
94
|
+
urlInfo.jpegThumbnail = (imageMessage === null || imageMessage === void 0 ? void 0 : imageMessage.jpegThumbnail)
|
|
95
|
+
? Buffer.from(imageMessage.jpegThumbnail)
|
|
96
|
+
: undefined;
|
|
97
|
+
urlInfo.highQualityThumbnail = imageMessage || undefined;
|
|
98
|
+
}
|
|
96
99
|
}
|
|
97
100
|
else {
|
|
98
101
|
try {
|
|
@@ -11,6 +11,7 @@ import { proto } from '../../WAProto';
|
|
|
11
11
|
import { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types';
|
|
12
12
|
import { BinaryNode } from '../WABinary';
|
|
13
13
|
export declare const hkdfInfoKey: (type: MediaType) => string;
|
|
14
|
+
export declare function processImage(imageUrl: string): Promise<Buffer | null>;
|
|
14
15
|
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
|
15
16
|
export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): MediaDecryptionKeyInfo;
|
|
16
17
|
export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.extensionForMediaMessage = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.getHttpStream = exports.generateThumbnail = exports.getStream = exports.toBuffer = exports.toReadable = exports.getAudioWaveform = exports.getAudioDuration = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.getMediaKeys = exports.hkdfInfoKey = void 0;
|
|
29
|
+
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.extensionForMediaMessage = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.getHttpStream = exports.generateThumbnail = exports.getStream = exports.toBuffer = exports.toReadable = exports.getAudioWaveform = exports.getAudioDuration = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.getMediaKeys = exports.processImage = exports.hkdfInfoKey = void 0;
|
|
30
30
|
const boom_1 = require("@hapi/boom");
|
|
31
31
|
const axios_1 = __importDefault(require("axios"));
|
|
32
32
|
const child_process_1 = require("child_process");
|
|
@@ -41,6 +41,7 @@ const Defaults_1 = require("../Defaults");
|
|
|
41
41
|
const WABinary_1 = require("../WABinary");
|
|
42
42
|
const crypto_1 = require("./crypto");
|
|
43
43
|
const generics_1 = require("./generics");
|
|
44
|
+
const sharp_1 = __importDefault(require("sharp"));
|
|
44
45
|
const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
|
|
45
46
|
const getImageProcessingLibrary = async () => {
|
|
46
47
|
const [_jimp, sharp] = await Promise.all([
|
|
@@ -67,6 +68,26 @@ const hkdfInfoKey = (type) => {
|
|
|
67
68
|
return `WhatsApp ${hkdfInfo} Keys`;
|
|
68
69
|
};
|
|
69
70
|
exports.hkdfInfoKey = hkdfInfoKey;
|
|
71
|
+
//!BK: Added a new function to get the URL info
|
|
72
|
+
async function processImage(imageUrl) {
|
|
73
|
+
try {
|
|
74
|
+
console.log('processing image', imageUrl);
|
|
75
|
+
// Fetch the image
|
|
76
|
+
const response = await fetch(imageUrl);
|
|
77
|
+
let imageBuffer = Buffer.from(await response.arrayBuffer());
|
|
78
|
+
// Convert WebP to JPEG if needed
|
|
79
|
+
const isWebP = imageUrl.endsWith('.webp');
|
|
80
|
+
if (isWebP) {
|
|
81
|
+
imageBuffer = await (0, sharp_1.default)(imageBuffer).jpeg().toBuffer(); // Convert to JPEG
|
|
82
|
+
}
|
|
83
|
+
return imageBuffer;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.error('Error processing image:', error);
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.processImage = processImage;
|
|
70
91
|
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
|
71
92
|
function getMediaKeys(buffer, mediaType) {
|
|
72
93
|
if (!buffer) {
|
|
@@ -150,7 +171,13 @@ const generateProfilePicture = async (mediaUpload) => {
|
|
|
150
171
|
bufferOrFilePath = mediaUpload;
|
|
151
172
|
}
|
|
152
173
|
else if ('url' in mediaUpload) {
|
|
153
|
-
|
|
174
|
+
const imageBuffer = await processImage(mediaUpload.url.toString());
|
|
175
|
+
if (imageBuffer) {
|
|
176
|
+
bufferOrFilePath = imageBuffer;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
bufferOrFilePath = mediaUpload.url.toString();
|
|
180
|
+
}
|
|
154
181
|
}
|
|
155
182
|
else {
|
|
156
183
|
bufferOrFilePath = await (0, exports.toBuffer)(mediaUpload.stream);
|