@blurose/baileys 1.1.10 → 1.1.12

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
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,11 +135,13 @@ 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,
143
+ mediaKey: fileSha256, // Dummy key for clients
144
+ mediaKeyTimestamp: unixTimestampSeconds(),
115
145
  fileSha256,
116
146
  fileLength,
117
147
  ...uploadData,
@@ -131,10 +161,6 @@ export const prepareWAMessageMedia = async (message, options) => {
131
161
  }
132
162
  return obj;
133
163
  }
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
164
  const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
139
165
  const { mediaKey, encFilePath, originalFilePath, fileEncSha256, fileSha256, fileLength } = await encryptedStream(uploadData.media, options.mediaTypeOverride || mediaType, {
140
166
  logger,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blurose/baileys",
3
3
  "type": "module",
4
- "version": "1.1.10",
4
+ "version": "1.1.12",
5
5
  "description": "A WebSockets library for interacting with WhatsApp Web",
6
6
  "keywords": [
7
7
  "whatsapp",