amiudmodz 5.1.0 → 5.1.2
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 +12 -6
- package/package.json +1 -1
|
@@ -264,6 +264,7 @@ async function getAudioWaveform(buffer, logger) {
|
|
|
264
264
|
} else {
|
|
265
265
|
buffer.pipe(inputStream);
|
|
266
266
|
}
|
|
267
|
+
return await new Promise((resolve, reject) => {
|
|
267
268
|
const chunks = [];
|
|
268
269
|
const bars = 64;
|
|
269
270
|
|
|
@@ -586,11 +587,12 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
|
|
|
586
587
|
let sha256Plain = Crypto.createHash('sha256');
|
|
587
588
|
let sha256Enc = Crypto.createHash('sha256');
|
|
588
589
|
try {
|
|
590
|
+
let plainLength = 0;
|
|
589
591
|
for await (const data of finalStream) {
|
|
590
|
-
|
|
592
|
+
plainLength += data.length;
|
|
591
593
|
if (type === 'remote'
|
|
592
594
|
&& (opts?.maxContentLength)
|
|
593
|
-
&&
|
|
595
|
+
&& plainLength > opts.maxContentLength) {
|
|
594
596
|
throw new boom_1.Boom(`content length exceeded when encrypting "${type}"`, {
|
|
595
597
|
data: { media, type }
|
|
596
598
|
});
|
|
@@ -602,6 +604,7 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
|
|
|
602
604
|
}
|
|
603
605
|
}
|
|
604
606
|
const encrypted = aes.update(data);
|
|
607
|
+
fileLength += encrypted.length;
|
|
605
608
|
sha256Enc = sha256Enc.update(encrypted);
|
|
606
609
|
hmac = hmac.update(encrypted);
|
|
607
610
|
if (!encTempWriteStream.write(encrypted)) {
|
|
@@ -609,6 +612,7 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
|
|
|
609
612
|
}
|
|
610
613
|
}
|
|
611
614
|
const finalEnc = aes.final();
|
|
615
|
+
fileLength += finalEnc.length;
|
|
612
616
|
sha256Enc = sha256Enc.update(finalEnc);
|
|
613
617
|
hmac = hmac.update(finalEnc);
|
|
614
618
|
if (!encTempWriteStream.write(finalEnc)) {
|
|
@@ -616,6 +620,7 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
|
|
|
616
620
|
}
|
|
617
621
|
|
|
618
622
|
const mac = hmac.digest().slice(0, 10);
|
|
623
|
+
fileLength += mac.length;
|
|
619
624
|
sha256Enc = sha256Enc.update(mac);
|
|
620
625
|
if (!encTempWriteStream.write(mac)) {
|
|
621
626
|
await (0, events_1.once)(encTempWriteStream, 'drain');
|
|
@@ -825,7 +830,7 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
825
830
|
|
|
826
831
|
let result;
|
|
827
832
|
try {
|
|
828
|
-
const bodyLength = fileLength || (Buffer.isBuffer(reqBody) ? reqBody.length : 0);
|
|
833
|
+
const bodyLength = fileLength || (streamPath ? (await fs_1.promises.stat(streamPath)).size : (Buffer.isBuffer(reqBody) ? reqBody.length : 0));
|
|
829
834
|
if (maxContentLengthBytes && bodyLength > maxContentLengthBytes) {
|
|
830
835
|
throw new boom_1.Boom(`Body too large for "${hostname}" (${bodyLength} > ${maxContentLengthBytes})`, { statusCode: 413 });
|
|
831
836
|
}
|
|
@@ -835,7 +840,8 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
835
840
|
...options.headers || {},
|
|
836
841
|
'Content-Type': 'application/octet-stream',
|
|
837
842
|
'Content-Length': bodyLength.toString(),
|
|
838
|
-
'Origin': Defaults_1.DEFAULT_ORIGIN
|
|
843
|
+
'Origin': Defaults_1.DEFAULT_ORIGIN,
|
|
844
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
|
839
845
|
},
|
|
840
846
|
httpsAgent: fetchAgent,
|
|
841
847
|
timeout: timeoutMs || Defaults_1.UPLOAD_TIMEOUT,
|
|
@@ -862,8 +868,8 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
862
868
|
if (axios.isAxiosError(error)) {
|
|
863
869
|
result = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
864
870
|
}
|
|
865
|
-
const isLast = hostname === ((_b = hosts[
|
|
866
|
-
logger.warn({ trace: error.stack, uploadResult: result }, `Error in uploading to ${hostname} ${isLast ? '' : ', retrying...'}`);
|
|
871
|
+
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...'}`);
|
|
867
873
|
}
|
|
868
874
|
}
|
|
869
875
|
if (!urls) {
|