@rexxhayanasi/elaina-baileys 1.2.1-rc.2 → 1.2.1-rc.4
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 +41 -64
- package/package.json +1 -2
|
@@ -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
|
@@ -107,80 +107,55 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
const isNewsletter = !!options.jid && (0, WABinary_1.isJidNewsletter)(options.jid);
|
|
110
|
+
const isNewsletter = !!options.jid && (0, WABinary_1.isJidNewsletter)(options.jid);
|
|
111
111
|
|
|
112
|
-
if (isNewsletter) {
|
|
113
|
-
|
|
112
|
+
if (isNewsletter) {
|
|
113
|
+
logger === null || logger === void 0 ? void 0 : logger.info({ key: cacheableKey }, 'Preparing raw media for newsletter');
|
|
114
|
+
|
|
115
|
+
const { filePath, fileSha256, fileLength } = await (0, messages_media_1.getRawMediaUploadData)(
|
|
116
|
+
uploadData.media,
|
|
117
|
+
options.mediaTypeOverride || mediaType,
|
|
118
|
+
logger
|
|
119
|
+
);
|
|
114
120
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
options.mediaTypeOverride || mediaType,
|
|
118
|
-
logger
|
|
119
|
-
);
|
|
121
|
+
const fileSha256B64 = fileSha256.toString('base64');
|
|
122
|
+
const uploadInput = filePath;
|
|
120
123
|
|
|
121
|
-
|
|
124
|
+
const { mediaUrl, directPath } = await options.upload(uploadInput, {
|
|
125
|
+
fileEncSha256B64: fileSha256B64,
|
|
126
|
+
mediaType
|
|
127
|
+
});
|
|
122
128
|
|
|
123
|
-
|
|
124
|
-
if (mediaType === 'video' || mediaType === 'image') {
|
|
125
|
-
const { thumbnail, originalImageDimensions } = await (0, messages_media_1.generateThumbnail)(filePath, mediaType, options);
|
|
126
|
-
uploadData.jpegThumbnail = thumbnail;
|
|
129
|
+
await fs_1.promises.unlink(filePath);
|
|
127
130
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
131
|
+
const obj = Types_1.WAProto.Message.fromObject({
|
|
132
|
+
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
|
133
|
+
url: mediaUrl,
|
|
134
|
+
directPath,
|
|
135
|
+
fileSha256,
|
|
136
|
+
fileLength,
|
|
137
|
+
...uploadData,
|
|
138
|
+
media: undefined
|
|
139
|
+
})
|
|
140
|
+
});
|
|
139
141
|
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
+
if (uploadData.ptv) {
|
|
143
|
+
obj.ptvMessage = obj.videoMessage;
|
|
144
|
+
delete obj.videoMessage;
|
|
142
145
|
}
|
|
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
146
|
|
|
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
147
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
148
|
+
if (obj.stickerMessage) {
|
|
149
|
+
obj.stickerMessage.stickerSentTs = Date.now();
|
|
150
|
+
}
|
|
172
151
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
152
|
+
if (cacheableKey) {
|
|
153
|
+
logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'set cache');
|
|
154
|
+
options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
|
|
155
|
+
}
|
|
176
156
|
|
|
177
|
-
|
|
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());
|
|
157
|
+
return obj;
|
|
180
158
|
}
|
|
181
|
-
|
|
182
|
-
return obj;
|
|
183
|
-
}
|
|
184
159
|
const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
|
|
185
160
|
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') &&
|
|
186
161
|
(typeof uploadData['jpegThumbnail'] === 'undefined');
|
|
@@ -188,6 +163,7 @@ if (isNewsletter) {
|
|
|
188
163
|
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
|
|
189
164
|
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
190
165
|
|
|
166
|
+
// Enkripsi standar
|
|
191
167
|
const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, } = await (0, messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
192
168
|
logger,
|
|
193
169
|
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
@@ -236,7 +212,7 @@ if (isNewsletter) {
|
|
|
236
212
|
if (!Buffer.isBuffer(encWriteStream)) {
|
|
237
213
|
encWriteStream.destroy();
|
|
238
214
|
}
|
|
239
|
-
|
|
215
|
+
// remove tmp files
|
|
240
216
|
if (didSaveToTmpPath && bodyPath) {
|
|
241
217
|
try {
|
|
242
218
|
await fs_1.promises.access(bodyPath);
|
|
@@ -275,6 +251,7 @@ if (isNewsletter) {
|
|
|
275
251
|
return obj;
|
|
276
252
|
};
|
|
277
253
|
exports.prepareWAMessageMedia = prepareWAMessageMedia;
|
|
254
|
+
|
|
278
255
|
const prepareDisappearingMessageSettingContent = (ephemeralExpiration) => {
|
|
279
256
|
ephemeralExpiration = ephemeralExpiration || 0;
|
|
280
257
|
const content = {
|
|
@@ -301,7 +278,7 @@ const generateForwardMessageContent = (message, forceForward) => {
|
|
|
301
278
|
if (!content) {
|
|
302
279
|
throw new boom_1.Boom('no content in message', { statusCode: 400 });
|
|
303
280
|
}
|
|
304
|
-
|
|
281
|
+
// hacky copy
|
|
305
282
|
content = (0, exports.normalizeMessageContent)(content);
|
|
306
283
|
content = WAProto_1.proto.Message.decode(WAProto_1.proto.Message.encode(content).finish());
|
|
307
284
|
let key = Object.keys(content)[0];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexxhayanasi/elaina-baileys",
|
|
3
|
-
"version": "1.2.1-rc.
|
|
3
|
+
"version": "1.2.1-rc.4",
|
|
4
4
|
"description": "Custom Baileys WhatsApp API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baileys",
|
|
@@ -53,7 +53,6 @@
|
|
|
53
53
|
"audio-decode": "^2.1.3",
|
|
54
54
|
"axios": "^1.6.0",
|
|
55
55
|
"chalk": "^4.1.2",
|
|
56
|
-
"fflate": "^0.8.2",
|
|
57
56
|
"gradient-string": "^2.0.2",
|
|
58
57
|
"cache-manager": "^5.7.6",
|
|
59
58
|
"cheerio": "^1.0.0-rc.12",
|