amiudmodz 5.0.0 → 5.0.1
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/engine-requirements.js +1 -1
- package/lib/Defaults/index.js +1 -1
- package/lib/Utils/messages-media.js +36 -16
- package/lib/Utils/messages.js +1 -1
- package/package.json +1 -1
package/engine-requirements.js
CHANGED
package/lib/Defaults/index.js
CHANGED
|
@@ -141,7 +141,7 @@ exports.MEDIA_HKDF_KEY_MAPPING = {
|
|
|
141
141
|
exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
|
|
142
142
|
exports.MIN_PREKEY_COUNT = 5;
|
|
143
143
|
exports.INITIAL_PREKEY_COUNT = 30;
|
|
144
|
-
exports.UPLOAD_TIMEOUT =
|
|
144
|
+
exports.UPLOAD_TIMEOUT = 7200000; // 2 hours in ms
|
|
145
145
|
exports.MIN_UPLOAD_INTERVAL = 5000;
|
|
146
146
|
|
|
147
147
|
exports.TimeMs = {
|
|
@@ -400,23 +400,41 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
|
|
|
400
400
|
logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
|
|
401
401
|
let bodyPath;
|
|
402
402
|
let didSaveToTmpPath = false;
|
|
403
|
+
let fileLength = 0;
|
|
404
|
+
const sha256 = Crypto.createHash('sha256');
|
|
405
|
+
const encWriteStream = new stream_1.PassThrough();
|
|
406
|
+
|
|
407
|
+
// if it's already a file, we can use its path
|
|
408
|
+
if (type === 'file') {
|
|
409
|
+
bodyPath = media.url;
|
|
410
|
+
} else if (saveOriginalFileIfRequired) {
|
|
411
|
+
bodyPath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageID)());
|
|
412
|
+
didSaveToTmpPath = true;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const writeStream = bodyPath && !media.url ? (0, fs_1.createWriteStream)(bodyPath) : undefined;
|
|
416
|
+
|
|
403
417
|
try {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
418
|
+
for await (const chunk of stream) {
|
|
419
|
+
fileLength += chunk.length;
|
|
420
|
+
sha256.update(chunk);
|
|
421
|
+
if (writeStream) {
|
|
422
|
+
if (!writeStream.write(chunk)) {
|
|
423
|
+
await (0, events_1.once)(writeStream, 'drain');
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
encWriteStream.write(chunk);
|
|
412
427
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
428
|
+
|
|
429
|
+
encWriteStream.end();
|
|
430
|
+
writeStream?.end();
|
|
431
|
+
|
|
432
|
+
const fileSha256 = sha256.digest();
|
|
416
433
|
logger === null || logger === void 0 ? void 0 : logger.debug('prepare stream data successfully');
|
|
434
|
+
|
|
417
435
|
return {
|
|
418
436
|
mediaKey: undefined,
|
|
419
|
-
encWriteStream
|
|
437
|
+
encWriteStream, // Now a stream, not a buffer
|
|
420
438
|
fileLength,
|
|
421
439
|
fileSha256,
|
|
422
440
|
fileEncSha256: undefined,
|
|
@@ -425,8 +443,9 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
|
|
|
425
443
|
};
|
|
426
444
|
}
|
|
427
445
|
catch (error) {
|
|
428
|
-
|
|
429
446
|
stream.destroy();
|
|
447
|
+
encWriteStream.destroy();
|
|
448
|
+
writeStream?.destroy();
|
|
430
449
|
if (didSaveToTmpPath) {
|
|
431
450
|
try {
|
|
432
451
|
await fs_1.promises.unlink(bodyPath);
|
|
@@ -442,6 +461,7 @@ exports.prepareStream = prepareStream;
|
|
|
442
461
|
const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts, isPtt, forceOpus } = {}) => {
|
|
443
462
|
const { stream, type } = await (0, exports.getStream)(media, opts);
|
|
444
463
|
|
|
464
|
+
let finalStream = stream;
|
|
445
465
|
let opusConverted = false;
|
|
446
466
|
if (mediaType === 'audio' && (isPtt === true || forceOpus === true)) {
|
|
447
467
|
try {
|
|
@@ -664,7 +684,7 @@ function extensionForMediaMessage(message) {
|
|
|
664
684
|
}
|
|
665
685
|
exports.extensionForMediaMessage = extensionForMediaMessage;
|
|
666
686
|
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
667
|
-
return async (stream, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
|
|
687
|
+
return async (stream, { mediaType, fileEncSha256B64, newsletter, timeoutMs, fileLength }) => {
|
|
668
688
|
var _a, _b;
|
|
669
689
|
const { default: axios } = await import('axios');
|
|
670
690
|
|
|
@@ -683,9 +703,9 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
683
703
|
const url = `https://${hostname}${media}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
|
|
684
704
|
let result;
|
|
685
705
|
try {
|
|
686
|
-
const bodyLength = Buffer.isBuffer(reqBody) ? reqBody.length : 0;
|
|
706
|
+
const bodyLength = fileLength || (Buffer.isBuffer(reqBody) ? reqBody.length : 0);
|
|
687
707
|
if (maxContentLengthBytes && bodyLength > maxContentLengthBytes) {
|
|
688
|
-
throw new boom_1.Boom(`Body too large for "${hostname}"`, { statusCode: 413 });
|
|
708
|
+
throw new boom_1.Boom(`Body too large for "${hostname}" (${bodyLength} > ${maxContentLengthBytes})`, { statusCode: 413 });
|
|
689
709
|
}
|
|
690
710
|
const body = await axios.post(url, reqBody, {
|
|
691
711
|
...options,
|
package/lib/Utils/messages.js
CHANGED
|
@@ -165,7 +165,7 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
165
165
|
|
|
166
166
|
const [{ mediaUrl, directPath, handle }] = await Promise.all([
|
|
167
167
|
(async () => {
|
|
168
|
-
const result = await options.upload(encWriteStream, { fileEncSha256B64, mediaType, timeoutMs: options.mediaUploadTimeoutMs });
|
|
168
|
+
const result = await options.upload(encWriteStream, { fileEncSha256B64, mediaType, timeoutMs: options.mediaUploadTimeoutMs, fileLength });
|
|
169
169
|
logger === null || logger === void 0 ? void 0 : logger.debug({ mediaType, cacheableKey }, 'uploaded media');
|
|
170
170
|
return result;
|
|
171
171
|
})(),
|