amiudmodz 5.1.5 → 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.
- package/lib/Utils/messages-media.js +60 -10
- package/lib/Utils/messages.js +1 -30
- package/package.json +1 -1
|
@@ -442,16 +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
447
|
media = undefined; // Help GC
|
|
448
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
|
+
|
|
449
496
|
let bodyPath;
|
|
450
497
|
let didSaveToTmpPath = false;
|
|
451
498
|
let fileLength = 0;
|
|
452
499
|
const sha256 = Crypto.createHash('sha256');
|
|
453
|
-
|
|
454
|
-
|
|
455
500
|
const preparedPath = (0, path_1.join)(getTmpFilesDirectory(), `prepared-${mediaType}-${(0, generics_1.generateMessageID)()}`);
|
|
456
501
|
const preparedWriteStream = (0, fs_1.createWriteStream)(preparedPath);
|
|
457
502
|
|
|
@@ -465,7 +510,7 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
|
|
|
465
510
|
const writeStream = didSaveToTmpPath ? (0, fs_1.createWriteStream)(bodyPath) : undefined;
|
|
466
511
|
|
|
467
512
|
try {
|
|
468
|
-
for await (const chunk of
|
|
513
|
+
for await (const chunk of finalStream) {
|
|
469
514
|
fileLength += chunk.length;
|
|
470
515
|
sha256.update(chunk);
|
|
471
516
|
if (writeStream) {
|
|
@@ -477,13 +522,13 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
|
|
|
477
522
|
await (0, events_1.once)(preparedWriteStream, 'drain');
|
|
478
523
|
}
|
|
479
524
|
}
|
|
480
|
-
|
|
481
525
|
preparedWriteStream.end();
|
|
482
526
|
writeStream?.end();
|
|
483
|
-
|
|
484
527
|
const fileSha256 = sha256.digest();
|
|
485
528
|
logger === null || logger === void 0 ? void 0 : logger.debug('prepare stream data successfully');
|
|
486
|
-
|
|
529
|
+
if (opusSpillPath) {
|
|
530
|
+
await fs_1.promises.unlink(opusSpillPath).catch(() => { });
|
|
531
|
+
}
|
|
487
532
|
return {
|
|
488
533
|
mediaKey: undefined,
|
|
489
534
|
encWriteStream: (0, fs_1.createReadStream)(preparedPath),
|
|
@@ -492,16 +537,21 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
|
|
|
492
537
|
fileEncSha256: undefined,
|
|
493
538
|
bodyPath,
|
|
494
539
|
streamPath: preparedPath,
|
|
495
|
-
didSaveToTmpPath
|
|
540
|
+
didSaveToTmpPath,
|
|
541
|
+
opusConverted
|
|
496
542
|
};
|
|
497
543
|
}
|
|
498
544
|
catch (error) {
|
|
499
|
-
|
|
545
|
+
finalStream.destroy();
|
|
500
546
|
preparedWriteStream.destroy();
|
|
501
547
|
writeStream?.destroy();
|
|
548
|
+
if (opusSpillPath) {
|
|
549
|
+
await fs_1.promises.unlink(opusSpillPath).catch(() => { });
|
|
550
|
+
}
|
|
502
551
|
try {
|
|
503
552
|
await fs_1.promises.unlink(preparedPath);
|
|
504
|
-
}
|
|
553
|
+
}
|
|
554
|
+
catch { }
|
|
505
555
|
if (didSaveToTmpPath) {
|
|
506
556
|
try {
|
|
507
557
|
await fs_1.promises.unlink(bodyPath);
|
package/lib/Utils/messages.js
CHANGED
|
@@ -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];
|