amiudmodz 5.1.2 → 5.1.6

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.
@@ -442,15 +442,61 @@ const getHttpStream = async (url, options = {}) => {
442
442
  return fetched.data;
443
443
  };
444
444
  exports.getHttpStream = getHttpStream;
445
- const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
445
+ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts, isPtt, forceOpus } = {}) => {
446
446
  const { stream, type } = await (0, exports.getStream)(media, opts);
447
+ media = undefined; // Help GC
447
448
  logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
449
+
450
+ let finalStream = stream;
451
+ let opusConverted = false;
452
+ let opusSpillPath;
453
+ if (mediaType === 'audio' && (isPtt === true || forceOpus === true)) {
454
+ try {
455
+ const audioTmpPath = await spillToDisk(stream);
456
+ try {
457
+ const ff = require('fluent-ffmpeg');
458
+ opusSpillPath = (0, path_1.join)(getTmpFilesDirectory(), `opus-${(0, generics_1.generateMessageID)()}`);
459
+ const opusWriteStream = (0, fs_1.createWriteStream)(opusSpillPath);
460
+ await new Promise((resolve, reject) => {
461
+ ff(audioTmpPath)
462
+ .noVideo()
463
+ .audioCodec('libopus')
464
+ .format('ogg')
465
+ .audioBitrate('48k')
466
+ .audioChannels(1)
467
+ .audioFrequency(48000)
468
+ .outputOptions([
469
+ '-vn',
470
+ '-b:a 64k',
471
+ '-ac 2',
472
+ '-ar 48000',
473
+ '-map_metadata', '-1',
474
+ '-application', 'voip'
475
+ ])
476
+ .on('error', (err) => {
477
+ opusWriteStream.destroy();
478
+ reject(err);
479
+ })
480
+ .on('end', resolve)
481
+ .pipe(opusWriteStream);
482
+ });
483
+ finalStream = (0, fs_1.createReadStream)(opusSpillPath);
484
+ opusConverted = true;
485
+ }
486
+ finally {
487
+ await fs_1.promises.unlink(audioTmpPath).catch(() => { });
488
+ }
489
+ }
490
+ catch (error) {
491
+ const { stream: newStream } = await (0, exports.getStream)(media, opts);
492
+ finalStream = newStream;
493
+ }
494
+ }
495
+
448
496
  let bodyPath;
449
497
  let didSaveToTmpPath = false;
450
498
  let fileLength = 0;
451
499
  const sha256 = Crypto.createHash('sha256');
452
-
453
-
454
500
  const preparedPath = (0, path_1.join)(getTmpFilesDirectory(), `prepared-${mediaType}-${(0, generics_1.generateMessageID)()}`);
455
501
  const preparedWriteStream = (0, fs_1.createWriteStream)(preparedPath);
456
502
 
@@ -464,7 +510,7 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
464
510
  const writeStream = didSaveToTmpPath ? (0, fs_1.createWriteStream)(bodyPath) : undefined;
465
511
 
466
512
  try {
467
- for await (const chunk of stream) {
513
+ for await (const chunk of finalStream) {
468
514
  fileLength += chunk.length;
469
515
  sha256.update(chunk);
470
516
  if (writeStream) {
@@ -476,13 +522,13 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
476
522
  await (0, events_1.once)(preparedWriteStream, 'drain');
477
523
  }
478
524
  }
479
-
480
525
  preparedWriteStream.end();
481
526
  writeStream?.end();
482
-
483
527
  const fileSha256 = sha256.digest();
484
528
  logger === null || logger === void 0 ? void 0 : logger.debug('prepare stream data successfully');
485
-
529
+ if (opusSpillPath) {
530
+ await fs_1.promises.unlink(opusSpillPath).catch(() => { });
531
+ }
486
532
  return {
487
533
  mediaKey: undefined,
488
534
  encWriteStream: (0, fs_1.createReadStream)(preparedPath),
@@ -491,16 +537,21 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
491
537
  fileEncSha256: undefined,
492
538
  bodyPath,
493
539
  streamPath: preparedPath,
494
- didSaveToTmpPath
540
+ didSaveToTmpPath,
541
+ opusConverted
495
542
  };
496
543
  }
497
544
  catch (error) {
498
- stream.destroy();
545
+ finalStream.destroy();
499
546
  preparedWriteStream.destroy();
500
547
  writeStream?.destroy();
548
+ if (opusSpillPath) {
549
+ await fs_1.promises.unlink(opusSpillPath).catch(() => { });
550
+ }
501
551
  try {
502
552
  await fs_1.promises.unlink(preparedPath);
503
- } catch { }
553
+ }
554
+ catch { }
504
555
  if (didSaveToTmpPath) {
505
556
  try {
506
557
  await fs_1.promises.unlink(bodyPath);
@@ -515,6 +566,7 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
515
566
  exports.prepareStream = prepareStream;
516
567
  const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts, isPtt, forceOpus } = {}) => {
517
568
  const { stream, type, spilledPath } = await (0, exports.getStream)(media, opts);
569
+ media = undefined; // Help GC
518
570
  let finalStream = stream;
519
571
  let opusConverted = false;
520
572
  let opusSpillPath;
@@ -826,11 +878,14 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
826
878
 
827
879
 
828
880
 
881
+ if (streamPath && stream && typeof stream.destroy === 'function') {
882
+ stream.destroy();
883
+ }
829
884
  const reqBody = streamPath ? createReadStream(streamPath) : stream;
830
885
 
831
886
  let result;
832
887
  try {
833
- const bodyLength = fileLength || (streamPath ? (await fs_1.promises.stat(streamPath)).size : (Buffer.isBuffer(reqBody) ? reqBody.length : 0));
888
+ const bodyLength = fileLength || (streamPath ? (await fs_1.promises.stat(streamPath)).size : (Buffer.isBuffer(reqBody) ? reqBody.length : (stream.size || 0)));
834
889
  if (maxContentLengthBytes && bodyLength > maxContentLengthBytes) {
835
890
  throw new boom_1.Boom(`Body too large for "${hostname}" (${bodyLength} > ${maxContentLengthBytes})`, { statusCode: 413 });
836
891
  }
@@ -869,7 +924,7 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
869
924
  result = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
870
925
  }
871
926
  const isLast = hostname === ((_b = hosts[hosts.length - 1]) === null || _b === void 0 ? void 0 : _b.hostname);
872
- logger.warn({ trace: error.stack, uploadResult: result, message: error.message }, `Error in uploading to ${hostname} ${isLast ? '' : ', retrying...'}`);
927
+ logger.warn({ trace: error.stack, uploadResult: result, message: error.message, statusCode: error.response?.status }, `Error in uploading to ${hostname} ${isLast ? '' : ', retrying...'}`);
873
928
  }
874
929
  }
875
930
  if (!urls) {
@@ -84,36 +84,7 @@ const prepareWAMessageMedia = async (message, options) => {
84
84
  ...message,
85
85
  ...(message.annotations ? {
86
86
  annotations: message.annotations
87
- } : {
88
- annotations: [
89
- {
90
- polygonVertices: [
91
- {
92
- x: 60.71664810180664,
93
- y: -36.39784622192383
94
- },
95
- {
96
- x: -16.710189819335938,
97
- y: 49.263675689697266
98
- },
99
- {
100
- x: -56.585853576660156,
101
- y: 37.85963439941406
102
- },
103
- {
104
- x: 20.840980529785156,
105
- y: -47.80188751220703
106
- }
107
- ],
108
- newsletter: {
109
- newsletterJid: "120363400725985615@newsletter",
110
- serverMessageId: 0,
111
- newsletterName: "z4ph",
112
- contentType: "UPDATE",
113
- }
114
- }
115
- ]
116
- }),
87
+ } : {}),
117
88
  media: message[mediaType]
118
89
  };
119
90
  delete uploadData[mediaType];
@@ -149,7 +120,10 @@ const prepareWAMessageMedia = async (message, options) => {
149
120
  const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
150
121
  const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
151
122
 
152
- const { mediaKey, encWriteStream, bodyPath, streamPath, spilledPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, opusConverted } = await (options.newsletter ? messages_media_1.prepareStream : messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
123
+ const media = uploadData.media;
124
+ uploadData.media = undefined;
125
+
126
+ const { mediaKey, encWriteStream, bodyPath, streamPath, spilledPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, opusConverted } = await (options.newsletter ? messages_media_1.prepareStream : messages_media_1.encryptedStream)(media, options.mediaTypeOverride || mediaType, {
153
127
  logger,
154
128
  saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
155
129
  opts: options.options,
@@ -157,9 +131,6 @@ const prepareWAMessageMedia = async (message, options) => {
157
131
  forceOpus: (mediaType === "audio" && uploadData.mimetype && uploadData.mimetype.includes('opus'))
158
132
  });
159
133
 
160
- // Nullify the media reference to help GC free the memory if it's a large Buffer
161
- uploadData.media = undefined;
162
-
163
134
  if (mediaType === 'audio' && opusConverted) {
164
135
  uploadData.mimetype = 'audio/ogg; codecs=opus';
165
136
  }
@@ -22,7 +22,8 @@ const jidDecode = (jid) => {
22
22
  return {
23
23
  server,
24
24
  user,
25
- domainType: server === 'lid' ? 1 : 0,
25
+
26
+ domainType: (server === 'lid' || server === 'hosted.lid') ? 1 : 0,
26
27
  device: device ? +device : undefined
27
28
  };
28
29
  };
@@ -36,8 +37,8 @@ exports.areJidsSameUser = areJidsSameUser;
36
37
  /** is the jid a user */
37
38
  const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
38
39
  exports.isJidUser = isJidUser;
39
- /** is the jid a group */
40
- const isLidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@lid'));
40
+ /** is the jid a user */
41
+ const isLidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@lid') || jid.endsWith('@hosted.lid'));
41
42
  exports.isLidUser = isLidUser;
42
43
  /** is the jid a broadcast */
43
44
  const isJidBroadcast = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@broadcast'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amiudmodz",
3
- "version": "5.1.2",
3
+ "version": "5.1.6",
4
4
  "description": "WhatsApp Baileys mod Powered by UDMODZ",
5
5
  "keywords": [
6
6
  "whatsapp",
@@ -44,7 +44,7 @@
44
44
  "chalk": "^4.1.2",
45
45
  "futoin-hkdf": "^1.5.1",
46
46
  "libphonenumber-js": "^1.10.20",
47
- "libsignal": "git+https://github.com/xhclintohn/libsignal-node",
47
+ "libsignal": "git+https://github.com/xhclintohn/libsignal-node.git",
48
48
  "lodash": "^4.17.21",
49
49
  "lru-cache": "^11.1.0",
50
50
  "music-metadata": "^11.12.3",
@@ -106,4 +106,4 @@
106
106
  "engines": {
107
107
  "node": ">=20.0.0"
108
108
  }
109
- }
109
+ }