@blurose/baileys 1.1.11 → 1.1.13

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.
@@ -96,10 +96,38 @@ export const prepareWAMessageMedia = async (message, options) => {
96
96
  return obj;
97
97
  }
98
98
  }
99
+ const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
100
+ const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') && typeof uploadData['jpegThumbnail'] === 'undefined';
101
+ const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true && typeof uploadData.waveform === 'undefined';
102
+ const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
103
+
99
104
  const isNewsletter = !!options.jid && isJidNewsletter(options.jid);
100
- if (false && isNewsletter) {
105
+ if (isNewsletter) {
101
106
  logger?.info({ key: cacheableKey }, 'Preparing raw media for newsletter');
102
107
  const { filePath, fileSha256, fileLength } = await getRawMediaUploadData(uploadData.media, options.mediaTypeOverride || mediaType, logger);
108
+
109
+ try {
110
+ if (requiresThumbnailComputation) {
111
+ const { thumbnail, originalImageDimensions } = await generateThumbnail(filePath, mediaType, options);
112
+ uploadData.jpegThumbnail = thumbnail;
113
+ if (!uploadData.width && originalImageDimensions) {
114
+ uploadData.width = originalImageDimensions.width;
115
+ uploadData.height = originalImageDimensions.height;
116
+ }
117
+ }
118
+ if (requiresDurationComputation) {
119
+ uploadData.seconds = await getAudioDuration(filePath);
120
+ }
121
+ if (requiresWaveformProcessing) {
122
+ uploadData.waveform = await getAudioWaveform(filePath, logger);
123
+ }
124
+ if (requiresAudioBackground) {
125
+ uploadData.backgroundArgb = await assertColor(options.backgroundColor);
126
+ }
127
+ } catch (error) {
128
+ logger?.warn({ trace: error.stack }, 'failed to obtain extra info for newsletter media');
129
+ }
130
+
103
131
  const fileSha256B64 = fileSha256.toString('base64');
104
132
  const { mediaUrl, directPath } = await options.upload(filePath, {
105
133
  fileEncSha256B64: fileSha256B64,
@@ -107,8 +135,8 @@ export const prepareWAMessageMedia = async (message, options) => {
107
135
  timeoutMs: options.mediaUploadTimeoutMs
108
136
  });
109
137
  await fs.unlink(filePath);
138
+
110
139
  const obj = WAProto.Message.fromObject({
111
- // todo: add more support here
112
140
  [`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
113
141
  url: mediaUrl,
114
142
  directPath,
@@ -131,10 +159,6 @@ export const prepareWAMessageMedia = async (message, options) => {
131
159
  }
132
160
  return obj;
133
161
  }
134
- const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
135
- const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') && typeof uploadData['jpegThumbnail'] === 'undefined';
136
- const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true && typeof uploadData.waveform === 'undefined';
137
- const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
138
162
  const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
139
163
  const { mediaKey, encFilePath, originalFilePath, fileEncSha256, fileSha256, fileLength } = await encryptedStream(uploadData.media, options.mediaTypeOverride || mediaType, {
140
164
  logger,
@@ -201,7 +225,6 @@ export const prepareWAMessageMedia = async (message, options) => {
201
225
  fileEncSha256,
202
226
  fileSha256,
203
227
  fileLength,
204
- mediaKeyTimestamp: unixTimestampSeconds(),
205
228
  ...uploadData,
206
229
  media: undefined
207
230
  })
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blurose/baileys",
3
3
  "type": "module",
4
- "version": "1.1.11",
4
+ "version": "1.1.13",
5
5
  "description": "A WebSockets library for interacting with WhatsApp Web",
6
6
  "keywords": [
7
7
  "whatsapp",