@realvare/based 2.7.61 → 2.7.70
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/README.MD +25 -114
- package/WAProto/WAProto.proto +1073 -244
- package/WAProto/index.d.ts +16282 -8183
- package/WAProto/index.js +76605 -50628
- package/engine-requirements.js +10 -10
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +1 -1
- package/lib/Defaults/index.js +5 -5
- package/lib/Socket/chats.js +53 -16
- package/lib/Socket/groups.js +53 -9
- package/lib/Socket/messages-recv.js +1298 -1237
- package/lib/Socket/messages-send.js +350 -456
- package/lib/Socket/socket.js +1 -1
- package/lib/Socket/usync.js +57 -4
- package/lib/Store/make-in-memory-store.js +28 -15
- package/lib/Types/Message.d.ts +316 -6
- package/lib/Types/Message.js +1 -1
- package/lib/Utils/cache-manager.d.ts +16 -0
- package/lib/Utils/cache-manager.js +20 -4
- package/lib/Utils/chat-utils.js +17 -13
- package/lib/Utils/decode-wa-message.js +1 -11
- package/lib/Utils/event-buffer.js +103 -2
- package/lib/Utils/generics.js +4 -5
- package/lib/Utils/index.d.ts +5 -0
- package/lib/Utils/index.js +3 -0
- package/lib/Utils/jid-validation.d.ts +2 -0
- package/lib/Utils/jid-validation.js +36 -5
- package/lib/Utils/link-preview.js +38 -28
- package/lib/Utils/messages-media.js +21 -52
- package/lib/Utils/messages.js +540 -23
- package/lib/Utils/performance-config.d.ts +2 -0
- package/lib/Utils/performance-config.js +16 -7
- package/lib/Utils/process-message.js +124 -12
- package/lib/Utils/rate-limiter.js +15 -20
- package/lib/WABinary/jid-utils.js +257 -5
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +75 -5
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +59 -6
- package/lib/WAUSync/USyncQuery.js +64 -6
- package/lib/index.d.ts +1 -0
- package/lib/index.js +5 -2
- package/package.json +7 -13
- package/WAProto/index.ts.ts +0 -53473
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -196,21 +196,25 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
196
196
|
};
|
|
197
197
|
exports.decodeSyncdMutations = decodeSyncdMutations;
|
|
198
198
|
const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
199
|
+
try {
|
|
200
|
+
if (validateMacs) {
|
|
201
|
+
const base64Key = Buffer.from(msg.keyId.id).toString('base64');
|
|
202
|
+
const mainKeyObj = await getAppStateSyncKey(base64Key);
|
|
203
|
+
if (!mainKeyObj) {
|
|
204
|
+
throw new boom_1.Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } });
|
|
205
|
+
}
|
|
206
|
+
const mainKey = await mutationKeys(mainKeyObj.keyData);
|
|
207
|
+
const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32));
|
|
208
|
+
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, (0, generics_1.toNumber)(msg.version.version), name, mainKey.patchMacKey);
|
|
209
|
+
if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
|
|
210
|
+
throw new boom_1.Boom('Invalid patch mac');
|
|
211
|
+
}
|
|
210
212
|
}
|
|
213
|
+
const result = await (0, exports.decodeSyncdMutations)(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
|
|
214
|
+
return result;
|
|
215
|
+
} catch (error) {
|
|
216
|
+
throw error;
|
|
211
217
|
}
|
|
212
|
-
const result = await (0, exports.decodeSyncdMutations)(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
|
|
213
|
-
return result;
|
|
214
218
|
};
|
|
215
219
|
exports.decodeSyncdPatch = decodeSyncdPatch;
|
|
216
220
|
const extractSyncdPatches = async (result, options) => {
|
|
@@ -29,25 +29,15 @@ exports.NACK_REASONS = {
|
|
|
29
29
|
*/
|
|
30
30
|
function decodeMessageNode(stanza, meId, meLid) {
|
|
31
31
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
32
|
-
if (!stanza || !stanza.attrs) {
|
|
33
|
-
throw new boom_1.Boom('Invalid stanza or missing attributes', { statusCode: 400 });
|
|
34
|
-
}
|
|
35
32
|
let msgType;
|
|
36
33
|
let chatId;
|
|
37
34
|
let author;
|
|
38
35
|
const msgId = stanza.attrs.id;
|
|
39
|
-
if (!msgId) {
|
|
40
|
-
throw new boom_1.Boom('Missing message ID', { statusCode: 400 });
|
|
41
|
-
}
|
|
42
36
|
const from = stanza.attrs.from;
|
|
43
|
-
if (!from) {
|
|
44
|
-
throw new boom_1.Boom('Missing sender JID', { statusCode: 400 });
|
|
45
|
-
}
|
|
46
37
|
const senderPn = (_a = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _a === void 0 ? void 0 : _a.sender_pn;
|
|
47
38
|
const senderLid = (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.sender_lid;
|
|
48
39
|
const participant = stanza.attrs.participant;
|
|
49
40
|
const participantLid = (_c = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _c === void 0 ? void 0 : _c.participant_lid;
|
|
50
|
-
const participantPn = (_d = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _d === void 0 ? void 0 : _d.participant_pn;
|
|
51
41
|
const recipient = stanza.attrs.recipient;
|
|
52
42
|
const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
|
|
53
43
|
const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
|
|
@@ -214,4 +204,4 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
214
204
|
}
|
|
215
205
|
};
|
|
216
206
|
};
|
|
217
|
-
exports.decryptMessageNode = decryptMessageNode;
|
|
207
|
+
exports.decryptMessageNode = decryptMessageNode;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.makeEventBuffer = void 0;
|
|
7
7
|
const events_1 = __importDefault(require("events"));
|
|
8
8
|
const Types_1 = require("../Types");
|
|
9
|
+
const WABinary_1 = require("../WABinary");
|
|
9
10
|
const generics_1 = require("./generics");
|
|
10
11
|
const messages_1 = require("./messages");
|
|
11
12
|
const process_message_1 = require("./process-message");
|
|
@@ -87,6 +88,7 @@ const makeEventBuffer = (logger) => {
|
|
|
87
88
|
};
|
|
88
89
|
},
|
|
89
90
|
emit(event, evData) {
|
|
91
|
+
normalizeEventJids(evData);
|
|
90
92
|
if (buffersInProgress && BUFFERABLE_EVENT_SET.has(event)) {
|
|
91
93
|
append(data, historyCache, event, evData, logger);
|
|
92
94
|
return true;
|
|
@@ -116,6 +118,62 @@ const makeEventBuffer = (logger) => {
|
|
|
116
118
|
};
|
|
117
119
|
};
|
|
118
120
|
exports.makeEventBuffer = makeEventBuffer;
|
|
121
|
+
const LID_FIELD_DENYLIST = new Set([
|
|
122
|
+
'remoteLid',
|
|
123
|
+
'participantLid',
|
|
124
|
+
'subjectOwnerLid',
|
|
125
|
+
'ownerLid',
|
|
126
|
+
'descOwnerLid',
|
|
127
|
+
'lid',
|
|
128
|
+
]);
|
|
129
|
+
const shouldNormalizeField = (key) => {
|
|
130
|
+
if (!key || typeof key !== 'string') {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
if (LID_FIELD_DENYLIST.has(key)) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
if (key.endsWith('Lid')) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
|
+
};
|
|
141
|
+
const normalizeEventJids = (data) => {
|
|
142
|
+
try {
|
|
143
|
+
normalizeAny(data, undefined);
|
|
144
|
+
}
|
|
145
|
+
catch (_e) {
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const normalizeAny = (value, key) => {
|
|
149
|
+
if (typeof value === 'string') {
|
|
150
|
+
if ((0, WABinary_1.isLid)(value) && shouldNormalizeField(key)) {
|
|
151
|
+
return (0, WABinary_1.lidToJid)(value) || value;
|
|
152
|
+
}
|
|
153
|
+
return value;
|
|
154
|
+
}
|
|
155
|
+
if (!value || typeof value !== 'object') {
|
|
156
|
+
return value;
|
|
157
|
+
}
|
|
158
|
+
if (Array.isArray(value)) {
|
|
159
|
+
for (let i = 0; i < value.length; i++) {
|
|
160
|
+
const v = value[i];
|
|
161
|
+
const nv = normalizeAny(v, undefined);
|
|
162
|
+
if (nv !== v) {
|
|
163
|
+
value[i] = nv;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return value;
|
|
167
|
+
}
|
|
168
|
+
for (const k of Object.keys(value)) {
|
|
169
|
+
const v = value[k];
|
|
170
|
+
const nv = normalizeAny(v, k);
|
|
171
|
+
if (nv !== v) {
|
|
172
|
+
value[k] = nv;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return value;
|
|
176
|
+
};
|
|
119
177
|
const makeBufferData = () => {
|
|
120
178
|
return {
|
|
121
179
|
historySets: {
|
|
@@ -274,6 +332,10 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
274
332
|
case 'contacts.update':
|
|
275
333
|
const contactUpdates = eventData;
|
|
276
334
|
for (const update of contactUpdates) {
|
|
335
|
+
// Skip if update is undefined or has no id
|
|
336
|
+
if (!update || !update.id) {
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
277
339
|
const id = update.id;
|
|
278
340
|
// merge into prior upsert
|
|
279
341
|
const upsert = data.historySets.contacts[id] || data.contactUpserts[id];
|
|
@@ -358,7 +420,31 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
358
420
|
}
|
|
359
421
|
}
|
|
360
422
|
else {
|
|
361
|
-
//
|
|
423
|
+
// Handle delete all messages from a specific chat
|
|
424
|
+
const { jid } = deleteData;
|
|
425
|
+
// Remove all messages, updates, and reactions for this chat
|
|
426
|
+
for (const keyStr in data.messageUpserts) {
|
|
427
|
+
if (keyStr.includes(jid)) {
|
|
428
|
+
delete data.messageUpserts[keyStr];
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
for (const keyStr in data.messageUpdates) {
|
|
432
|
+
if (keyStr.includes(jid)) {
|
|
433
|
+
delete data.messageUpdates[keyStr];
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
for (const keyStr in data.messageReactions) {
|
|
437
|
+
if (keyStr.includes(jid)) {
|
|
438
|
+
delete data.messageReactions[keyStr];
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
for (const keyStr in data.messageDeletes) {
|
|
442
|
+
if (keyStr.includes(jid)) {
|
|
443
|
+
delete data.messageDeletes[keyStr];
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
// Store the delete all event
|
|
447
|
+
data.messageDeletes[`all:${jid}`] = { jid, all: true };
|
|
362
448
|
}
|
|
363
449
|
break;
|
|
364
450
|
case 'messages.reaction':
|
|
@@ -394,6 +480,10 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
394
480
|
case 'groups.update':
|
|
395
481
|
const groupUpdates = eventData;
|
|
396
482
|
for (const update of groupUpdates) {
|
|
483
|
+
// Skip if update is undefined or has no id
|
|
484
|
+
if (!update || !update.id) {
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
397
487
|
const id = update.id;
|
|
398
488
|
const groupUpdate = data.groupUpdates[id] || {};
|
|
399
489
|
if (!data.groupUpdates[id]) {
|
|
@@ -477,7 +567,18 @@ function consolidateEvents(data) {
|
|
|
477
567
|
}
|
|
478
568
|
const messageDeleteList = Object.values(data.messageDeletes);
|
|
479
569
|
if (messageDeleteList.length) {
|
|
480
|
-
|
|
570
|
+
// Separate individual message deletions from delete all events
|
|
571
|
+
const individualDeletes = messageDeleteList.filter(item => !('all' in item && item.all));
|
|
572
|
+
const deleteAllEvents = messageDeleteList.filter(item => ('all' in item && item.all));
|
|
573
|
+
|
|
574
|
+
if (individualDeletes.length) {
|
|
575
|
+
map['messages.delete'] = { keys: individualDeletes };
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// Emit delete all events separately
|
|
579
|
+
for (const deleteAllEvent of deleteAllEvents) {
|
|
580
|
+
map[`messages.delete.all.${deleteAllEvent.jid}`] = { jid: deleteAllEvent.jid, all: true };
|
|
581
|
+
}
|
|
481
582
|
}
|
|
482
583
|
const messageReactionList = Object.values(data.messageReactions).flatMap(({ key, reactions }) => reactions.flatMap(reaction => ({ key, reaction })));
|
|
483
584
|
if (messageReactionList.length) {
|
package/lib/Utils/generics.js
CHANGED
|
@@ -66,11 +66,10 @@ const PLATFORM_MAP = {
|
|
|
66
66
|
'sunos': 'Solaris'
|
|
67
67
|
};
|
|
68
68
|
exports.Browsers = {
|
|
69
|
-
ubuntu: (browser) => ['Ubuntu', browser, '
|
|
70
|
-
macOS: (browser) => ['Mac OS', browser, '
|
|
71
|
-
baileys: (browser) => ['Baileys', browser, '6.
|
|
72
|
-
windows: (browser) => ['Windows', browser, '10.0.
|
|
73
|
-
/** The appropriate browser based on your OS & release */
|
|
69
|
+
ubuntu: (browser) => ['Ubuntu', browser, '24.04.1'],
|
|
70
|
+
macOS: (browser) => ['Mac OS', browser, '15.2.0'],
|
|
71
|
+
baileys: (browser) => ['Baileys', browser, '6.7.9'],
|
|
72
|
+
windows: (browser) => ['Windows', browser, '10.0.26100'],
|
|
74
73
|
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
75
74
|
};
|
|
76
75
|
const getPlatformId = (browser) => {
|
package/lib/Utils/index.d.ts
CHANGED
|
@@ -15,3 +15,8 @@ export * from './use-multi-file-auth-state';
|
|
|
15
15
|
export * from './link-preview';
|
|
16
16
|
export * from './event-buffer';
|
|
17
17
|
export * from './process-message';
|
|
18
|
+
export * from './performance-config';
|
|
19
|
+
export { isValidJid, normalizeJid } from './jid-validation';
|
|
20
|
+
export * from './newsletter-utils';
|
|
21
|
+
export * from './logger';
|
|
22
|
+
export * from './cache-manager';
|
package/lib/Utils/index.js
CHANGED
|
@@ -32,4 +32,7 @@ __exportStar(require("./link-preview"), exports);
|
|
|
32
32
|
__exportStar(require("./event-buffer"), exports);
|
|
33
33
|
__exportStar(require("./process-message"), exports);
|
|
34
34
|
__exportStar(require("./performance-config"), exports);
|
|
35
|
+
__exportStar(require("./jid-validation"), exports);
|
|
35
36
|
__exportStar(require("./newsletter-utils"), exports);
|
|
37
|
+
__exportStar(require("./logger"), exports);
|
|
38
|
+
__exportStar(require("./cache-manager"), exports);
|
|
@@ -55,25 +55,56 @@ exports.normalizeJid = normalizeJid;
|
|
|
55
55
|
const getSenderLid = (msg) => {
|
|
56
56
|
try {
|
|
57
57
|
if (!msg || typeof msg !== 'object') {
|
|
58
|
-
return {
|
|
58
|
+
return {
|
|
59
|
+
jid: '',
|
|
60
|
+
lid: '',
|
|
61
|
+
isValid: false,
|
|
62
|
+
user: '',
|
|
63
|
+
timestamp: Date.now(),
|
|
64
|
+
error: 'Invalid message object'
|
|
65
|
+
};
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
// Extract from different possible fields
|
|
62
69
|
const jid = msg.key?.remoteJid || msg.remoteJid || msg.from;
|
|
63
70
|
const lid = msg.key?.participant || msg.participant || msg.lid;
|
|
64
71
|
|
|
72
|
+
if (!jid || typeof jid !== 'string') {
|
|
73
|
+
return {
|
|
74
|
+
jid: '',
|
|
75
|
+
lid: typeof lid === 'string' ? lid : '',
|
|
76
|
+
isValid: false,
|
|
77
|
+
user: '',
|
|
78
|
+
timestamp: Date.now(),
|
|
79
|
+
error: 'Missing or invalid JID'
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
65
83
|
// Validate and normalize
|
|
66
84
|
const normalizedJid = normalizeJid(jid);
|
|
67
85
|
const isValid = isValidJid(normalizedJid);
|
|
68
86
|
|
|
87
|
+
const decoded = (0, WABinary_1.jidDecode)(normalizedJid);
|
|
88
|
+
const user = decoded?.user || normalizedJid.split('@')[0] || '';
|
|
89
|
+
|
|
69
90
|
return {
|
|
70
91
|
jid: normalizedJid,
|
|
71
|
-
lid: lid,
|
|
72
|
-
isValid: isValid
|
|
92
|
+
lid: typeof lid === 'string' ? lid : '',
|
|
93
|
+
isValid: isValid,
|
|
94
|
+
user,
|
|
95
|
+
timestamp: Date.now(),
|
|
96
|
+
...(isValid ? {} : { error: 'Invalid JID format' })
|
|
73
97
|
};
|
|
74
98
|
} catch (error) {
|
|
75
99
|
performance_config_1.Logger.error('Error in getSenderLid:', error);
|
|
76
|
-
return {
|
|
100
|
+
return {
|
|
101
|
+
jid: '',
|
|
102
|
+
lid: '',
|
|
103
|
+
isValid: false,
|
|
104
|
+
user: '',
|
|
105
|
+
timestamp: Date.now(),
|
|
106
|
+
error: 'Error extracting sender information'
|
|
107
|
+
};
|
|
77
108
|
}
|
|
78
109
|
};
|
|
79
110
|
|
|
@@ -142,7 +173,7 @@ const validateJid = (jid) => {
|
|
|
142
173
|
return { isValid: false, error: `Invalid domain: ${domain}` };
|
|
143
174
|
}
|
|
144
175
|
|
|
145
|
-
return { isValid: true
|
|
176
|
+
return { isValid: true };
|
|
146
177
|
|
|
147
178
|
} catch (error) {
|
|
148
179
|
performance_config_1.Logger.error('Error in validateJid:', error);
|
|
@@ -70,46 +70,56 @@ const getUrlInfo = async (text, opts = {
|
|
|
70
70
|
}) => {
|
|
71
71
|
var _a;
|
|
72
72
|
try {
|
|
73
|
-
|
|
74
|
-
const retries = 0;
|
|
75
|
-
const maxRetry = 5;
|
|
76
|
-
const { getLinkPreview } = await Promise.resolve().then(() => __importStar(require('link-preview-js')));
|
|
73
|
+
const { unfurl } = await Promise.resolve().then(() => __importStar(require('unfurl.js')));
|
|
77
74
|
let previewLink = text;
|
|
78
75
|
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
79
76
|
previewLink = 'https://' + previewLink;
|
|
80
77
|
}
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
78
|
+
const requestHeaders = (() => {
|
|
79
|
+
const headers = opts.fetchOpts?.headers;
|
|
80
|
+
if (!headers || typeof headers !== 'object') {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const out = {};
|
|
84
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
85
|
+
if (typeof value === 'undefined' || value === null) {
|
|
86
|
+
continue;
|
|
89
87
|
}
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|| 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
|
|
93
|
-
retries + 1;
|
|
94
|
-
return true;
|
|
88
|
+
if (Array.isArray(value)) {
|
|
89
|
+
out[key] = value.map(v => v.toString()).join(', ');
|
|
95
90
|
}
|
|
96
91
|
else {
|
|
97
|
-
|
|
92
|
+
out[key] = value.toString();
|
|
98
93
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
})();
|
|
97
|
+
const info = await unfurl(previewLink, {
|
|
98
|
+
timeout: opts.fetchOpts?.timeout,
|
|
99
|
+
headers: requestHeaders,
|
|
100
|
+
follow: 5
|
|
101
101
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
const title = info?.title || info?.open_graph?.title || info?.twitter_card?.title;
|
|
103
|
+
if (title) {
|
|
104
|
+
const images = [];
|
|
105
|
+
if (info?.open_graph?.images?.length) {
|
|
106
|
+
images.push(...info.open_graph.images.map(img => img === null || img === void 0 ? void 0 : img.url).filter(Boolean));
|
|
107
|
+
}
|
|
108
|
+
if (info?.twitter_card?.images?.length) {
|
|
109
|
+
images.push(...info.twitter_card.images.map(img => img === null || img === void 0 ? void 0 : img.url).filter(Boolean));
|
|
110
|
+
}
|
|
111
|
+
const [image] = images;
|
|
112
|
+
const description = info?.description || info?.open_graph?.description || info?.twitter_card?.description;
|
|
113
|
+
const canonicalUrl = info?.canonical_url || info?.open_graph?.url || previewLink;
|
|
114
|
+
opts.logger?.debug({ url: previewLink, title, imageCount: images.length }, 'Fetched link preview info');
|
|
105
115
|
const urlInfo = {
|
|
106
|
-
'canonical-url':
|
|
116
|
+
'canonical-url': canonicalUrl,
|
|
107
117
|
'matched-text': text,
|
|
108
|
-
title
|
|
109
|
-
description
|
|
118
|
+
title,
|
|
119
|
+
description,
|
|
110
120
|
originalThumbnailUrl: image
|
|
111
121
|
};
|
|
112
|
-
if (opts.uploadImage) {
|
|
122
|
+
if (opts.uploadImage && image) {
|
|
113
123
|
const { imageMessage } = await (0, messages_1.prepareWAMessageMedia)({ image: { url: image } }, {
|
|
114
124
|
upload: opts.uploadImage,
|
|
115
125
|
mediaTypeOverride: 'thumbnail-link',
|
|
@@ -134,7 +144,7 @@ const getUrlInfo = async (text, opts = {
|
|
|
134
144
|
}
|
|
135
145
|
}
|
|
136
146
|
catch (error) {
|
|
137
|
-
if (!error.message.includes('receive a valid')) {
|
|
147
|
+
if (!error.message.includes('receive a valid') && !error.message.includes('Invalid URL')) {
|
|
138
148
|
throw error;
|
|
139
149
|
}
|
|
140
150
|
}
|
|
@@ -63,24 +63,11 @@ 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
|
-
(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;
|
|
66
|
+
const jimp = await (Promise.resolve().then(() => __importStar(require('jimp'))).catch(() => { }));
|
|
80
67
|
if (jimp) {
|
|
81
|
-
return { jimp };
|
|
68
|
+
return { jimp: jimp.default || jimp };
|
|
82
69
|
}
|
|
83
|
-
throw new boom_1.Boom('
|
|
70
|
+
throw new boom_1.Boom('Jimp image processing library not available');
|
|
84
71
|
};
|
|
85
72
|
const hkdfInfoKey = (type) => {
|
|
86
73
|
const hkdfInfo = Defaults_1.MEDIA_HKDF_KEY_MAPPING[type];
|
|
@@ -274,45 +261,24 @@ const extractVideoThumb = async (videoPath, time = '00:00:00', size = { width: 2
|
|
|
274
261
|
};
|
|
275
262
|
exports.extractVideoThumb = extractVideoThumb;
|
|
276
263
|
const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
277
|
-
var _a, _b;
|
|
278
264
|
if (bufferOrFilePath instanceof stream_1.Readable) {
|
|
279
265
|
bufferOrFilePath = await (0, exports.toBuffer)(bufferOrFilePath);
|
|
280
266
|
}
|
|
281
267
|
const lib = await getImageProcessingLibrary();
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
else if ('jimp' in lib && typeof ((_b = lib.jimp) === null || _b === void 0 ? void 0 : _b.read) === 'function') {
|
|
298
|
-
const { read, MIME_JPEG, RESIZE_BILINEAR, AUTO } = lib.jimp;
|
|
299
|
-
const jimp = await read(bufferOrFilePath);
|
|
300
|
-
const dimensions = {
|
|
301
|
-
width: jimp.getWidth(),
|
|
302
|
-
height: jimp.getHeight()
|
|
303
|
-
};
|
|
304
|
-
const buffer = await jimp
|
|
305
|
-
.quality(50)
|
|
306
|
-
.resize(width, AUTO, RESIZE_BILINEAR)
|
|
307
|
-
.getBufferAsync(MIME_JPEG);
|
|
308
|
-
return {
|
|
309
|
-
buffer,
|
|
310
|
-
original: dimensions
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
throw new boom_1.Boom('No image processing library available');
|
|
315
|
-
}
|
|
268
|
+
const { read, MIME_JPEG, RESIZE_BILINEAR, AUTO } = lib.jimp;
|
|
269
|
+
const jimp = await read(bufferOrFilePath);
|
|
270
|
+
const dimensions = {
|
|
271
|
+
width: jimp.getWidth(),
|
|
272
|
+
height: jimp.getHeight()
|
|
273
|
+
};
|
|
274
|
+
const buffer = await jimp
|
|
275
|
+
.quality(50)
|
|
276
|
+
.resize(width, AUTO, RESIZE_BILINEAR)
|
|
277
|
+
.getBufferAsync(MIME_JPEG);
|
|
278
|
+
return {
|
|
279
|
+
buffer,
|
|
280
|
+
original: dimensions
|
|
281
|
+
};
|
|
316
282
|
};
|
|
317
283
|
exports.extractImageThumb = extractImageThumb;
|
|
318
284
|
const encodeBase64EncodedStringForUpload = (b64) => (encodeURIComponent(b64
|
|
@@ -424,6 +390,9 @@ const getStream = async (item, opts) => {
|
|
|
424
390
|
if ('stream' in item) {
|
|
425
391
|
return { stream: item.stream, type: 'readable' };
|
|
426
392
|
}
|
|
393
|
+
if (!item || !item.url) {
|
|
394
|
+
throw new Error('Invalid media item: missing url property');
|
|
395
|
+
}
|
|
427
396
|
if (item.url.toString().startsWith('http://') || item.url.toString().startsWith('https://')) {
|
|
428
397
|
return { stream: await (0, exports.getHttpStream)(item.url, opts), type: 'remote' };
|
|
429
398
|
}
|
|
@@ -876,4 +845,4 @@ const MEDIA_RETRY_STATUS_MAP = {
|
|
|
876
845
|
};
|
|
877
846
|
function __importStar(arg0) {
|
|
878
847
|
throw new Error('Function not implemented.');
|
|
879
|
-
}
|
|
848
|
+
}
|