@rexxhayanasi/elaina-baileys 1.2.1-rc.1 → 1.2.1-rc.2
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.js +62 -51
- package/package.json +1 -1
package/lib/Utils/messages.js
CHANGED
|
@@ -107,68 +107,80 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
const isNewsletter = !!options.jid && (0, WABinary_1.isJidNewsletter)(options.jid);
|
|
110
|
+
const isNewsletter = !!options.jid && (0, WABinary_1.isJidNewsletter)(options.jid);
|
|
112
111
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// 1. Dapatkan file mentah (RAW) menggunakan fungsi yang baru kita buat di messages-media.js
|
|
117
|
-
const { filePath, fileSha256, fileLength } = await (0, messages_media_1.getRawMediaUploadData)(
|
|
118
|
-
uploadData.media,
|
|
119
|
-
options.mediaTypeOverride || mediaType,
|
|
120
|
-
logger
|
|
121
|
-
);
|
|
112
|
+
if (isNewsletter) {
|
|
113
|
+
logger === null || logger === void 0 ? void 0 : logger.info({ key: cacheableKey }, 'Preparing raw media for newsletter');
|
|
122
114
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const { mediaUrl, directPath } = await options.upload(streamToUpload, {
|
|
130
|
-
fileEncSha256B64: fileSha256B64,
|
|
131
|
-
mediaType: mediaType,
|
|
132
|
-
timeoutMs: options.mediaUploadTimeoutMs
|
|
133
|
-
});
|
|
115
|
+
const { filePath, fileSha256, fileLength } = await (0, messages_media_1.getRawMediaUploadData)(
|
|
116
|
+
uploadData.media,
|
|
117
|
+
options.mediaTypeOverride || mediaType,
|
|
118
|
+
logger
|
|
119
|
+
);
|
|
134
120
|
|
|
135
|
-
|
|
136
|
-
await fs_1.promises.unlink(filePath);
|
|
121
|
+
const fileSha256B64 = fileSha256.toString('base64');
|
|
137
122
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
directPath,
|
|
143
|
-
fileSha256,
|
|
144
|
-
fileLength,
|
|
145
|
-
...uploadData,
|
|
146
|
-
media: undefined
|
|
147
|
-
})
|
|
148
|
-
});
|
|
123
|
+
try {
|
|
124
|
+
if (mediaType === 'video' || mediaType === 'image') {
|
|
125
|
+
const { thumbnail, originalImageDimensions } = await (0, messages_media_1.generateThumbnail)(filePath, mediaType, options);
|
|
126
|
+
uploadData.jpegThumbnail = thumbnail;
|
|
149
127
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
128
|
+
if (!uploadData.width && originalImageDimensions) {
|
|
129
|
+
uploadData.width = originalImageDimensions.width;
|
|
130
|
+
uploadData.height = originalImageDimensions.height;
|
|
131
|
+
}
|
|
154
132
|
}
|
|
155
133
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
134
|
+
if (mediaType === 'audio' || mediaType === 'video') {
|
|
135
|
+
if (typeof uploadData.seconds === 'undefined') {
|
|
136
|
+
uploadData.seconds = await (0, messages_media_1.getAudioDuration)(filePath);
|
|
137
|
+
}
|
|
159
138
|
}
|
|
160
139
|
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
|
|
140
|
+
if (mediaType === 'audio' && uploadData.ptt === true) {
|
|
141
|
+
uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(filePath, logger);
|
|
164
142
|
}
|
|
143
|
+
} catch (err) {
|
|
144
|
+
logger === null || logger === void 0 ? void 0 : logger.warn({ trace: err.stack }, 'Failed to generate metadata for newsletter media');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const streamToUpload = (0, fs_1.createReadStream)(filePath);
|
|
148
|
+
|
|
149
|
+
const { mediaUrl, directPath } = await options.upload(streamToUpload, {
|
|
150
|
+
fileEncSha256B64: fileSha256B64,
|
|
151
|
+
mediaType: mediaType,
|
|
152
|
+
timeoutMs: options.mediaUploadTimeoutMs
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
await fs_1.promises.unlink(filePath);
|
|
156
|
+
|
|
157
|
+
const obj = Types_1.WAProto.Message.fromObject({
|
|
158
|
+
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
|
159
|
+
url: mediaUrl,
|
|
160
|
+
directPath,
|
|
161
|
+
fileSha256,
|
|
162
|
+
fileLength,
|
|
163
|
+
...uploadData,
|
|
164
|
+
media: undefined
|
|
165
|
+
})
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
if (uploadData.ptv) {
|
|
169
|
+
obj.ptvMessage = obj.videoMessage;
|
|
170
|
+
delete obj.videoMessage;
|
|
171
|
+
}
|
|
165
172
|
|
|
166
|
-
|
|
173
|
+
if (obj.stickerMessage) {
|
|
174
|
+
obj.stickerMessage.stickerSentTs = Date.now();
|
|
167
175
|
}
|
|
168
|
-
// --- [SELESAI] LOGIKA NEWSLETTER ---
|
|
169
176
|
|
|
177
|
+
if (cacheableKey) {
|
|
178
|
+
logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'set cache');
|
|
179
|
+
options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
|
|
180
|
+
}
|
|
170
181
|
|
|
171
|
-
|
|
182
|
+
return obj;
|
|
183
|
+
}
|
|
172
184
|
const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
|
|
173
185
|
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') &&
|
|
174
186
|
(typeof uploadData['jpegThumbnail'] === 'undefined');
|
|
@@ -176,7 +188,6 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
176
188
|
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
|
|
177
189
|
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
178
190
|
|
|
179
|
-
// Enkripsi standar
|
|
180
191
|
const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, } = await (0, messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
181
192
|
logger,
|
|
182
193
|
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
@@ -225,7 +236,7 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
225
236
|
if (!Buffer.isBuffer(encWriteStream)) {
|
|
226
237
|
encWriteStream.destroy();
|
|
227
238
|
}
|
|
228
|
-
|
|
239
|
+
|
|
229
240
|
if (didSaveToTmpPath && bodyPath) {
|
|
230
241
|
try {
|
|
231
242
|
await fs_1.promises.access(bodyPath);
|
|
@@ -290,7 +301,7 @@ const generateForwardMessageContent = (message, forceForward) => {
|
|
|
290
301
|
if (!content) {
|
|
291
302
|
throw new boom_1.Boom('no content in message', { statusCode: 400 });
|
|
292
303
|
}
|
|
293
|
-
|
|
304
|
+
|
|
294
305
|
content = (0, exports.normalizeMessageContent)(content);
|
|
295
306
|
content = WAProto_1.proto.Message.decode(WAProto_1.proto.Message.encode(content).finish());
|
|
296
307
|
let key = Object.keys(content)[0];
|