@rexxhayanasi/elaina-baileys 1.2.1-rc.3 → 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.
@@ -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);
@@ -111,7 +111,7 @@ const prepareWAMessageMedia = async (message, options) => {
111
111
 
112
112
  if (isNewsletter) {
113
113
  logger === null || logger === void 0 ? void 0 : logger.info({ key: cacheableKey }, 'Preparing raw media for newsletter');
114
-
114
+
115
115
  const { filePath, fileSha256, fileLength } = await (0, messages_media_1.getRawMediaUploadData)(
116
116
  uploadData.media,
117
117
  options.mediaTypeOverride || mediaType,
@@ -119,53 +119,21 @@ const prepareWAMessageMedia = async (message, options) => {
119
119
  );
120
120
 
121
121
  const fileSha256B64 = fileSha256.toString('base64');
122
+ const uploadInput = filePath;
122
123
 
123
- try {
124
- if (mediaType === 'video' || mediaType === 'image') {
125
- const { thumbnail, originalImageDimensions } = await (0, messages_media_1.generateThumbnail)(filePath, mediaType, options);
126
- if (!uploadData.jpegThumbnail) uploadData.jpegThumbnail = thumbnail;
124
+ const { mediaUrl, directPath } = await options.upload(uploadInput, {
125
+ fileEncSha256B64: fileSha256B64,
126
+ mediaType
127
+ });
127
128
 
128
- if (!uploadData.width && originalImageDimensions) {
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}`;
129
+ await fs_1.promises.unlink(filePath);
159
130
 
160
131
  const obj = Types_1.WAProto.Message.fromObject({
161
132
  [`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
162
- url: finalUrl,
163
- directPath: uploaded.directPath,
164
- mediaKey: undefined,
165
- fileEncSha256: undefined,
133
+ url: mediaUrl,
134
+ directPath,
166
135
  fileSha256,
167
136
  fileLength,
168
- staticUrl: uploaded.handle ? finalUrl : undefined,
169
137
  ...uploadData,
170
138
  media: undefined
171
139
  })
@@ -176,11 +144,13 @@ const prepareWAMessageMedia = async (message, options) => {
176
144
  delete obj.videoMessage;
177
145
  }
178
146
 
147
+
179
148
  if (obj.stickerMessage) {
180
149
  obj.stickerMessage.stickerSentTs = Date.now();
181
150
  }
182
151
 
183
152
  if (cacheableKey) {
153
+ logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'set cache');
184
154
  options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
185
155
  }
186
156
 
@@ -193,6 +163,7 @@ const prepareWAMessageMedia = async (message, options) => {
193
163
  const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
194
164
  const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
195
165
 
166
+ // Enkripsi standar
196
167
  const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, } = await (0, messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
197
168
  logger,
198
169
  saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
@@ -241,7 +212,7 @@ const prepareWAMessageMedia = async (message, options) => {
241
212
  if (!Buffer.isBuffer(encWriteStream)) {
242
213
  encWriteStream.destroy();
243
214
  }
244
-
215
+ // remove tmp files
245
216
  if (didSaveToTmpPath && bodyPath) {
246
217
  try {
247
218
  await fs_1.promises.access(bodyPath);
@@ -280,6 +251,7 @@ const prepareWAMessageMedia = async (message, options) => {
280
251
  return obj;
281
252
  };
282
253
  exports.prepareWAMessageMedia = prepareWAMessageMedia;
254
+
283
255
  const prepareDisappearingMessageSettingContent = (ephemeralExpiration) => {
284
256
  ephemeralExpiration = ephemeralExpiration || 0;
285
257
  const content = {
@@ -306,7 +278,7 @@ const generateForwardMessageContent = (message, forceForward) => {
306
278
  if (!content) {
307
279
  throw new boom_1.Boom('no content in message', { statusCode: 400 });
308
280
  }
309
-
281
+ // hacky copy
310
282
  content = (0, exports.normalizeMessageContent)(content);
311
283
  content = WAProto_1.proto.Message.decode(WAProto_1.proto.Message.encode(content).finish());
312
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",
3
+ "version": "1.2.1-rc.4",
4
4
  "description": "Custom Baileys WhatsApp API",
5
5
  "keywords": [
6
6
  "baileys",