@rexxhayanasi/elaina-baileys 1.2.1-rc.1 → 1.2.1-rc.3

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.
@@ -107,13 +107,11 @@ const prepareWAMessageMedia = async (message, options) => {
107
107
  }
108
108
  }
109
109
 
110
- // --- [MULAI] LOGIKA KHUSUS NEWSLETTER (WHISKEYSOCKETS ADAPTATION) ---
111
110
  const isNewsletter = !!options.jid && (0, WABinary_1.isJidNewsletter)(options.jid);
112
111
 
113
112
  if (isNewsletter) {
114
113
  logger === null || logger === void 0 ? void 0 : logger.info({ key: cacheableKey }, 'Preparing raw media for newsletter');
115
-
116
- // 1. Dapatkan file mentah (RAW) menggunakan fungsi yang baru kita buat di messages-media.js
114
+
117
115
  const { filePath, fileSha256, fileLength } = await (0, messages_media_1.getRawMediaUploadData)(
118
116
  uploadData.media,
119
117
  options.mediaTypeOverride || mediaType,
@@ -121,54 +119,73 @@ const prepareWAMessageMedia = async (message, options) => {
121
119
  );
122
120
 
123
121
  const fileSha256B64 = fileSha256.toString('base64');
124
-
125
- // 2. Upload Stream Mentah
126
- // Kita buat ReadStream dari filePath agar kompatibel dengan sistem upload Baileys v6
122
+
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;
127
+
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
+
127
148
  const streamToUpload = (0, fs_1.createReadStream)(filePath);
128
-
129
- const { mediaUrl, directPath } = await options.upload(streamToUpload, {
149
+
150
+ const uploaded = await options.upload(streamToUpload, {
130
151
  fileEncSha256B64: fileSha256B64,
131
152
  mediaType: mediaType,
132
153
  timeoutMs: options.mediaUploadTimeoutMs
133
154
  });
134
155
 
135
- // Hapus file temp setelah upload selesai
136
156
  await fs_1.promises.unlink(filePath);
137
157
 
138
- // 3. Buat Objek Pesan
158
+ const finalUrl = uploaded.mediaUrl || uploaded.url || `https://mmg.whatsapp.net${uploaded.directPath}`;
159
+
139
160
  const obj = Types_1.WAProto.Message.fromObject({
140
161
  [`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
141
- url: mediaUrl,
142
- directPath,
162
+ url: finalUrl,
163
+ directPath: uploaded.directPath,
164
+ mediaKey: undefined,
165
+ fileEncSha256: undefined,
143
166
  fileSha256,
144
167
  fileLength,
168
+ staticUrl: uploaded.handle ? finalUrl : undefined,
145
169
  ...uploadData,
146
170
  media: undefined
147
171
  })
148
172
  });
149
173
 
150
- // 4. Ubah tipe pesan jadi PTV jika flag aktif
151
174
  if (uploadData.ptv) {
152
175
  obj.ptvMessage = obj.videoMessage;
153
176
  delete obj.videoMessage;
154
177
  }
155
178
 
156
- // Handle sticker timestamp
157
179
  if (obj.stickerMessage) {
158
180
  obj.stickerMessage.stickerSentTs = Date.now();
159
181
  }
160
182
 
161
183
  if (cacheableKey) {
162
- logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'set cache');
163
184
  options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
164
185
  }
165
186
 
166
187
  return obj;
167
188
  }
168
- // --- [SELESAI] LOGIKA NEWSLETTER ---
169
-
170
-
171
- // --- LOGIKA LAMA (E2E / CHAT BIASA) ---
172
189
  const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
173
190
  const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') &&
174
191
  (typeof uploadData['jpegThumbnail'] === 'undefined');
@@ -176,7 +193,6 @@ const prepareWAMessageMedia = async (message, options) => {
176
193
  const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
177
194
  const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
178
195
 
179
- // Enkripsi standar
180
196
  const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, } = await (0, messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
181
197
  logger,
182
198
  saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
@@ -225,7 +241,7 @@ const prepareWAMessageMedia = async (message, options) => {
225
241
  if (!Buffer.isBuffer(encWriteStream)) {
226
242
  encWriteStream.destroy();
227
243
  }
228
- // remove tmp files
244
+
229
245
  if (didSaveToTmpPath && bodyPath) {
230
246
  try {
231
247
  await fs_1.promises.access(bodyPath);
@@ -290,7 +306,7 @@ const generateForwardMessageContent = (message, forceForward) => {
290
306
  if (!content) {
291
307
  throw new boom_1.Boom('no content in message', { statusCode: 400 });
292
308
  }
293
- // hacky copy
309
+
294
310
  content = (0, exports.normalizeMessageContent)(content);
295
311
  content = WAProto_1.proto.Message.decode(WAProto_1.proto.Message.encode(content).finish());
296
312
  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.1",
3
+ "version": "1.2.1-rc.3",
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",