@rexxhayanasi/elaina-baileys 1.2.1-rc.3 → 1.2.1-rc.5
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/Utils/messages-media.js +4 -1
- package/lib/Utils/messages.js +37 -56
- package/package.json +1 -1
|
@@ -573,7 +573,10 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
|
|
|
573
573
|
}
|
|
574
574
|
};
|
|
575
575
|
exports.prepareStream = prepareStream;
|
|
576
|
-
const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
|
576
|
+
const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts, isNewsletter } = {}) => {
|
|
577
|
+
if (isNewsletter) {
|
|
578
|
+
throw new Error('encryptedStream must not be used for newsletter media');
|
|
579
|
+
}
|
|
577
580
|
const { stream, type } = await (0, exports.getStream)(media, opts);
|
|
578
581
|
logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
|
|
579
582
|
const mediaKey = Crypto.randomBytes(32);
|
package/lib/Utils/messages.js
CHANGED
|
@@ -108,10 +108,14 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
const isNewsletter = !!options.jid && (0, WABinary_1.isJidNewsletter)(options.jid);
|
|
111
|
+
|
|
112
|
+
if (isNewsletter && mediaType === 'audio') {
|
|
113
|
+
uploadData.mimetype = 'audio/mp4';
|
|
114
|
+
}
|
|
111
115
|
|
|
112
116
|
if (isNewsletter) {
|
|
113
117
|
logger === null || logger === void 0 ? void 0 : logger.info({ key: cacheableKey }, 'Preparing raw media for newsletter');
|
|
114
|
-
|
|
118
|
+
|
|
115
119
|
const { filePath, fileSha256, fileLength } = await (0, messages_media_1.getRawMediaUploadData)(
|
|
116
120
|
uploadData.media,
|
|
117
121
|
options.mediaTypeOverride || mediaType,
|
|
@@ -119,68 +123,47 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
119
123
|
);
|
|
120
124
|
|
|
121
125
|
const fileSha256B64 = fileSha256.toString('base64');
|
|
126
|
+
const uploadInput = filePath;
|
|
122
127
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
const { mediaUrl, directPath } = await options.upload(uploadInput, {
|
|
129
|
+
fileEncSha256B64: fileSha256B64,
|
|
130
|
+
mediaType
|
|
131
|
+
});
|
|
127
132
|
|
|
128
|
-
|
|
129
|
-
uploadData.width = originalImageDimensions.width;
|
|
130
|
-
uploadData.height = originalImageDimensions.height;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (mediaType === 'audio' || mediaType === 'video') {
|
|
135
|
-
if (typeof uploadData.seconds === 'undefined') {
|
|
136
|
-
uploadData.seconds = await (0, messages_media_1.getAudioDuration)(filePath);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (mediaType === 'audio' && uploadData.ptt === true) {
|
|
141
|
-
uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(filePath, logger);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
} catch (err) {
|
|
145
|
-
logger === null || logger === void 0 ? void 0 : logger.warn({ trace: err.stack }, 'Metadata generation failed');
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const streamToUpload = (0, fs_1.createReadStream)(filePath);
|
|
149
|
-
|
|
150
|
-
const uploaded = await options.upload(streamToUpload, {
|
|
151
|
-
fileEncSha256B64: fileSha256B64,
|
|
152
|
-
mediaType: mediaType,
|
|
153
|
-
timeoutMs: options.mediaUploadTimeoutMs
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
await fs_1.promises.unlink(filePath);
|
|
157
|
-
|
|
158
|
-
const finalUrl = uploaded.mediaUrl || uploaded.url || `https://mmg.whatsapp.net${uploaded.directPath}`;
|
|
133
|
+
await fs_1.promises.unlink(filePath);
|
|
159
134
|
|
|
160
135
|
const obj = Types_1.WAProto.Message.fromObject({
|
|
161
136
|
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
|
162
|
-
url:
|
|
163
|
-
directPath
|
|
164
|
-
mediaKey: undefined,
|
|
165
|
-
fileEncSha256: undefined,
|
|
137
|
+
url: mediaUrl,
|
|
138
|
+
directPath,
|
|
166
139
|
fileSha256,
|
|
167
140
|
fileLength,
|
|
168
|
-
staticUrl: uploaded.handle ? finalUrl : undefined,
|
|
169
141
|
...uploadData,
|
|
170
142
|
media: undefined
|
|
171
143
|
})
|
|
172
144
|
});
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
if (uploadData.ptv && mediaType === 'video') {
|
|
148
|
+
obj.ptvMessage = obj.videoMessage;
|
|
149
|
+
delete obj.videoMessage;
|
|
150
|
+
|
|
151
|
+
delete obj.ptvMessage.jpegThumbnail;
|
|
152
|
+
delete obj.ptvMessage.seconds;
|
|
153
|
+
delete obj.ptvMessage.gifPlayback;
|
|
154
|
+
delete obj.ptvMessage.contextInfo;
|
|
155
|
+
|
|
156
|
+
obj.ptvMessage.ptv = true;
|
|
157
|
+
obj.ptvMessage.mimetype = 'video/mp4';
|
|
158
|
+
}
|
|
173
159
|
|
|
174
|
-
if (uploadData.ptv) {
|
|
175
|
-
obj.ptvMessage = obj.videoMessage;
|
|
176
|
-
delete obj.videoMessage;
|
|
177
|
-
}
|
|
178
160
|
|
|
179
161
|
if (obj.stickerMessage) {
|
|
180
162
|
obj.stickerMessage.stickerSentTs = Date.now();
|
|
181
163
|
}
|
|
182
164
|
|
|
183
165
|
if (cacheableKey) {
|
|
166
|
+
logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'set cache');
|
|
184
167
|
options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
|
|
185
168
|
}
|
|
186
169
|
|
|
@@ -193,6 +176,7 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
193
176
|
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
|
|
194
177
|
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
195
178
|
|
|
179
|
+
// Enkripsi standar
|
|
196
180
|
const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, } = await (0, messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
197
181
|
logger,
|
|
198
182
|
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
@@ -241,7 +225,7 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
241
225
|
if (!Buffer.isBuffer(encWriteStream)) {
|
|
242
226
|
encWriteStream.destroy();
|
|
243
227
|
}
|
|
244
|
-
|
|
228
|
+
// remove tmp files
|
|
245
229
|
if (didSaveToTmpPath && bodyPath) {
|
|
246
230
|
try {
|
|
247
231
|
await fs_1.promises.access(bodyPath);
|
|
@@ -268,11 +252,11 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
268
252
|
})
|
|
269
253
|
});
|
|
270
254
|
|
|
271
|
-
if (uploadData.ptv) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
255
|
+
if (uploadData.ptv && mediaType === 'video') {
|
|
256
|
+
obj.ptvMessage = obj.videoMessage;
|
|
257
|
+
delete obj.videoMessage;
|
|
258
|
+
}
|
|
259
|
+
|
|
276
260
|
if (cacheableKey) {
|
|
277
261
|
logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'set cache');
|
|
278
262
|
options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
|
|
@@ -280,6 +264,7 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
280
264
|
return obj;
|
|
281
265
|
};
|
|
282
266
|
exports.prepareWAMessageMedia = prepareWAMessageMedia;
|
|
267
|
+
|
|
283
268
|
const prepareDisappearingMessageSettingContent = (ephemeralExpiration) => {
|
|
284
269
|
ephemeralExpiration = ephemeralExpiration || 0;
|
|
285
270
|
const content = {
|
|
@@ -306,7 +291,7 @@ const generateForwardMessageContent = (message, forceForward) => {
|
|
|
306
291
|
if (!content) {
|
|
307
292
|
throw new boom_1.Boom('no content in message', { statusCode: 400 });
|
|
308
293
|
}
|
|
309
|
-
|
|
294
|
+
// hacky copy
|
|
310
295
|
content = (0, exports.normalizeMessageContent)(content);
|
|
311
296
|
content = WAProto_1.proto.Message.decode(WAProto_1.proto.Message.encode(content).finish());
|
|
312
297
|
let key = Object.keys(content)[0];
|
|
@@ -463,10 +448,6 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
463
448
|
break;
|
|
464
449
|
}
|
|
465
450
|
}
|
|
466
|
-
else if ('ptv' in message && message.ptv) {
|
|
467
|
-
const { videoMessage } = await (0, exports.prepareWAMessageMedia)({ video: message.video }, options);
|
|
468
|
-
m.ptvMessage = videoMessage;
|
|
469
|
-
}
|
|
470
451
|
else if ('product' in message) {
|
|
471
452
|
const { imageMessage } = await (0, exports.prepareWAMessageMedia)({ image: message.product.productImage }, options);
|
|
472
453
|
m.productMessage = Types_1.WAProto.Message.ProductMessage.fromObject({
|