gifted-baileys 1.5.5 → 1.5.7
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/README.md +6 -1642
- package/WAProto/WAProto.proto +969 -88
- package/WAProto/index.d.ts +13199 -1260
- package/WAProto/index.js +124901 -74525
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +284 -0
- package/{src → lib}/Defaults/index.js +7 -14
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +161 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/{src → lib}/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.d.ts +17 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +62 -0
- package/lib/Socket/business.d.ts +170 -0
- package/{src → lib}/Socket/business.js +28 -33
- package/lib/Socket/chats.d.ts +81 -0
- package/{src → lib}/Socket/chats.js +174 -176
- package/lib/Socket/groups.d.ts +115 -0
- package/{src → lib}/Socket/groups.js +80 -68
- package/lib/Socket/index.d.ts +172 -0
- package/{src → lib}/Socket/index.js +4 -1
- package/lib/Socket/messages-recv.d.ts +158 -0
- package/{src → lib}/Socket/messages-recv.js +378 -211
- package/lib/Socket/messages-send.d.ts +155 -0
- package/{src → lib}/Socket/messages-send.js +452 -177
- package/lib/Socket/newsletter.d.ts +132 -0
- package/{src → lib}/Socket/newsletter.js +107 -98
- package/lib/Socket/registration.d.ts +264 -0
- package/{src → lib}/Socket/registration.js +56 -48
- package/lib/Socket/socket.d.ts +44 -0
- package/{src → lib}/Socket/socket.js +77 -77
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/{src → lib}/Store/make-cache-manager-store.js +25 -34
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/{src → lib}/Store/make-in-memory-store.js +36 -32
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/{src → lib}/Store/object-repository.js +1 -1
- package/lib/Types/Auth.d.ts +109 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Chat.d.ts +107 -0
- package/{src/Types/Contact.ts → lib/Types/Contact.d.ts} +8 -9
- package/lib/Types/Events.d.ts +172 -0
- package/lib/Types/GroupMetadata.d.ts +56 -0
- package/lib/Types/Label.d.ts +46 -0
- package/{src/Types/LabelAssociation.ts → lib/Types/LabelAssociation.d.ts} +16 -22
- package/lib/Types/Message.d.ts +433 -0
- package/lib/Types/Newsletter.d.ts +92 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/{src/Types/Socket.ts → lib/Types/Socket.d.ts} +61 -68
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/{src → lib}/Utils/auth-utils.js +73 -90
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +22 -0
- package/{src → lib}/Utils/business.js +15 -43
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/{src → lib}/Utils/chat-utils.js +87 -94
- package/lib/Utils/crypto.d.ts +40 -0
- package/{src → lib}/Utils/crypto.js +4 -2
- package/lib/Utils/decode-wa-message.d.ts +36 -0
- package/lib/Utils/decode-wa-message.js +226 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/{src → lib}/Utils/event-buffer.js +4 -13
- package/lib/Utils/generics.d.ts +88 -0
- package/{src → lib}/Utils/generics.js +67 -86
- package/lib/Utils/history.d.ts +19 -0
- package/{src → lib}/Utils/history.js +13 -39
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/{src → lib}/Utils/link-preview.js +17 -54
- package/lib/Utils/logger.d.ts +2 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/{src → lib}/Utils/make-mutex.js +4 -13
- package/lib/Utils/messages-media.d.ts +113 -0
- package/{src → lib}/Utils/messages-media.js +193 -255
- package/lib/Utils/messages.d.ts +77 -0
- package/{src → lib}/Utils/messages.js +588 -118
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/{src → lib}/Utils/process-message.js +27 -30
- package/lib/Utils/signal.d.ts +33 -0
- package/{src → lib}/Utils/signal.js +25 -42
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/{src → lib}/Utils/use-multi-file-auth-state.js +27 -28
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/{src → lib}/Utils/validate-connection.js +40 -9
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/{src → lib}/WABinary/encode.js +16 -10
- package/lib/WABinary/generic-utils.d.ts +14 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +26 -0
- package/lib/WAUSync/USyncQuery.js +79 -0
- package/lib/WAUSync/USyncUser.d.ts +10 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/{src → lib}/index.js +1 -0
- package/package.json +26 -8
- package/LICENSE +0 -21
- package/src/Defaults/baileys-version.json +0 -3
- package/src/Defaults/index.ts +0 -131
- package/src/Signal/libsignal.js +0 -180
- package/src/Signal/libsignal.ts +0 -141
- package/src/Socket/Client/abstract-socket-client.ts +0 -19
- package/src/Socket/Client/index.ts +0 -3
- package/src/Socket/Client/mobile-socket-client.js +0 -78
- package/src/Socket/Client/mobile-socket-client.ts +0 -66
- package/src/Socket/Client/web-socket-client.js +0 -75
- package/src/Socket/Client/web-socket-client.ts +0 -57
- package/src/Socket/business.ts +0 -281
- package/src/Socket/chats.ts +0 -1030
- package/src/Socket/groups.ts +0 -356
- package/src/Socket/index.ts +0 -13
- package/src/Socket/messages-recv.ts +0 -985
- package/src/Socket/messages-send.ts +0 -871
- package/src/Socket/newsletter.ts +0 -282
- package/src/Socket/registration.ts +0 -250
- package/src/Socket/socket.ts +0 -777
- package/src/Store/index.ts +0 -3
- package/src/Store/make-cache-manager-store.ts +0 -100
- package/src/Store/make-in-memory-store.ts +0 -475
- package/src/Store/make-ordered-dictionary.ts +0 -86
- package/src/Store/object-repository.ts +0 -32
- package/src/Tests/test.app-state-sync.js +0 -204
- package/src/Tests/test.app-state-sync.ts +0 -207
- package/src/Tests/test.event-buffer.js +0 -270
- package/src/Tests/test.event-buffer.ts +0 -319
- package/src/Tests/test.key-store.js +0 -76
- package/src/Tests/test.key-store.ts +0 -92
- package/src/Tests/test.libsignal.js +0 -141
- package/src/Tests/test.libsignal.ts +0 -186
- package/src/Tests/test.media-download.js +0 -93
- package/src/Tests/test.media-download.ts +0 -76
- package/src/Tests/test.messages.js +0 -33
- package/src/Tests/test.messages.ts +0 -37
- package/src/Tests/utils.js +0 -34
- package/src/Tests/utils.ts +0 -36
- package/src/Types/Auth.ts +0 -113
- package/src/Types/Call.ts +0 -15
- package/src/Types/Chat.ts +0 -106
- package/src/Types/Events.ts +0 -93
- package/src/Types/GroupMetadata.ts +0 -53
- package/src/Types/Label.ts +0 -36
- package/src/Types/Message.ts +0 -288
- package/src/Types/Newsletter.ts +0 -98
- package/src/Types/Product.ts +0 -85
- package/src/Types/Signal.ts +0 -68
- package/src/Types/State.ts +0 -29
- package/src/Types/index.ts +0 -59
- package/src/Utils/auth-utils.ts +0 -222
- package/src/Utils/baileys-event-stream.js +0 -92
- package/src/Utils/baileys-event-stream.ts +0 -66
- package/src/Utils/business.ts +0 -275
- package/src/Utils/chat-utils.ts +0 -860
- package/src/Utils/crypto.ts +0 -131
- package/src/Utils/decode-wa-message.js +0 -211
- package/src/Utils/decode-wa-message.ts +0 -228
- package/src/Utils/event-buffer.ts +0 -613
- package/src/Utils/generics.ts +0 -434
- package/src/Utils/history.ts +0 -112
- package/src/Utils/index.ts +0 -17
- package/src/Utils/link-preview.ts +0 -122
- package/src/Utils/logger.ts +0 -3
- package/src/Utils/lt-hash.ts +0 -61
- package/src/Utils/make-mutex.ts +0 -44
- package/src/Utils/messages-media.ts +0 -847
- package/src/Utils/messages.ts +0 -956
- package/src/Utils/noise-handler.ts +0 -197
- package/src/Utils/process-message.ts +0 -414
- package/src/Utils/signal.ts +0 -177
- package/src/Utils/use-multi-file-auth-state.ts +0 -90
- package/src/Utils/validate-connection.ts +0 -238
- package/src/WABinary/constants.ts +0 -42
- package/src/WABinary/decode.ts +0 -265
- package/src/WABinary/encode.ts +0 -236
- package/src/WABinary/generic-utils.ts +0 -121
- package/src/WABinary/index.ts +0 -5
- package/src/WABinary/jid-utils.ts +0 -68
- package/src/WABinary/types.ts +0 -17
- package/src/WAM/BinaryInfo.ts +0 -12
- package/src/WAM/constants.ts +0 -15382
- package/src/WAM/encode.ts +0 -174
- package/src/WAM/index.ts +0 -3
- package/src/gifted +0 -1
- package/src/index.ts +0 -13
- /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
- /package/{src → lib}/Socket/Client/abstract-socket-client.js +0 -0
- /package/{src → lib}/Store/index.js +0 -0
- /package/{src → lib}/Store/make-ordered-dictionary.js +0 -0
- /package/{src → lib}/Types/Auth.js +0 -0
- /package/{src → lib}/Types/Call.js +0 -0
- /package/{src → lib}/Types/Chat.js +0 -0
- /package/{src → lib}/Types/Contact.js +0 -0
- /package/{src → lib}/Types/Events.js +0 -0
- /package/{src → lib}/Types/GroupMetadata.js +0 -0
- /package/{src → lib}/Types/Label.js +0 -0
- /package/{src → lib}/Types/LabelAssociation.js +0 -0
- /package/{src → lib}/Types/Message.js +0 -0
- /package/{src → lib}/Types/Newsletter.js +0 -0
- /package/{src → lib}/Types/Product.js +0 -0
- /package/{src → lib}/Types/Signal.js +0 -0
- /package/{src → lib}/Types/Socket.js +0 -0
- /package/{src → lib}/Types/State.js +0 -0
- /package/{src/WABinary/types.js → lib/Types/USync.js} +0 -0
- /package/{src → lib}/Types/index.js +0 -0
- /package/{src → lib}/Utils/index.js +0 -0
- /package/{src → lib}/Utils/logger.js +0 -0
- /package/{src → lib}/Utils/lt-hash.js +0 -0
- /package/{src → lib}/Utils/noise-handler.js +0 -0
- /package/{src → lib}/WABinary/constants.js +0 -0
- /package/{src → lib}/WABinary/decode.js +0 -0
- /package/{src → lib}/WABinary/generic-utils.js +0 -0
- /package/{src → lib}/WABinary/index.js +0 -0
- /package/{src → lib}/WABinary/jid-utils.js +0 -0
- /package/{src → lib}/WAM/BinaryInfo.js +0 -0
- /package/{src → lib}/WAM/constants.js +0 -0
- /package/{src → lib}/WAM/encode.js +0 -0
- /package/{src → lib}/WAM/index.js +0 -0
|
@@ -32,22 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
45
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
46
|
-
var m = o[Symbol.asyncIterator], i;
|
|
47
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
48
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
49
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
50
|
-
};
|
|
51
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
36
|
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.prepareStream = exports.getHttpStream = exports.getStream = exports.toBuffer = exports.toReadable = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.hkdfInfoKey = void 0;
|
|
53
37
|
exports.getMediaKeys = getMediaKeys;
|
|
@@ -69,16 +53,18 @@ const WABinary_1 = require("../WABinary");
|
|
|
69
53
|
const crypto_1 = require("./crypto");
|
|
70
54
|
const generics_1 = require("./generics");
|
|
71
55
|
const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
|
|
72
|
-
const getImageProcessingLibrary = () =>
|
|
73
|
-
const [_jimp, sharp] =
|
|
74
|
-
(() =>
|
|
75
|
-
const jimp =
|
|
56
|
+
const getImageProcessingLibrary = async () => {
|
|
57
|
+
const [_jimp, sharp] = await Promise.all([
|
|
58
|
+
(async () => {
|
|
59
|
+
const jimp = await (import('jimp')
|
|
60
|
+
.catch(() => { }));
|
|
76
61
|
return jimp;
|
|
77
|
-
})
|
|
78
|
-
(() =>
|
|
79
|
-
const sharp =
|
|
62
|
+
})(),
|
|
63
|
+
(async () => {
|
|
64
|
+
const sharp = await (import('sharp')
|
|
65
|
+
.catch(() => { }));
|
|
80
66
|
return sharp;
|
|
81
|
-
})
|
|
67
|
+
})()
|
|
82
68
|
]);
|
|
83
69
|
if (sharp) {
|
|
84
70
|
return { sharp };
|
|
@@ -88,7 +74,7 @@ const getImageProcessingLibrary = () => __awaiter(void 0, void 0, void 0, functi
|
|
|
88
74
|
return { jimp };
|
|
89
75
|
}
|
|
90
76
|
throw new boom_1.Boom('No image processing library available');
|
|
91
|
-
}
|
|
77
|
+
};
|
|
92
78
|
const hkdfInfoKey = (type) => {
|
|
93
79
|
const hkdfInfo = Defaults_1.MEDIA_HKDF_KEY_MAPPING[type];
|
|
94
80
|
return `WhatsApp ${hkdfInfo} Keys`;
|
|
@@ -111,29 +97,27 @@ function getMediaKeys(buffer, mediaType) {
|
|
|
111
97
|
};
|
|
112
98
|
}
|
|
113
99
|
/** Extracts video thumb using FFMPEG */
|
|
114
|
-
const extractVideoThumb = (path, destPath, time, size) =>
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
});
|
|
100
|
+
const extractVideoThumb = async (path, destPath, time, size) => new Promise((resolve, reject) => {
|
|
101
|
+
const cmd = `ffmpeg -ss ${time} -i ${path} -y -vf scale=${size.width}:-1 -vframes 1 -f image2 ${destPath}`;
|
|
102
|
+
(0, child_process_1.exec)(cmd, (err) => {
|
|
103
|
+
if (err) {
|
|
104
|
+
reject(err);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
resolve();
|
|
108
|
+
}
|
|
125
109
|
});
|
|
126
110
|
});
|
|
127
|
-
const extractImageThumb =
|
|
111
|
+
const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
128
112
|
var _a, _b;
|
|
129
113
|
if (bufferOrFilePath instanceof stream_1.Readable) {
|
|
130
|
-
bufferOrFilePath =
|
|
114
|
+
bufferOrFilePath = await (0, exports.toBuffer)(bufferOrFilePath);
|
|
131
115
|
}
|
|
132
|
-
const lib =
|
|
116
|
+
const lib = await getImageProcessingLibrary();
|
|
133
117
|
if ('sharp' in lib && typeof ((_a = lib.sharp) === null || _a === void 0 ? void 0 : _a.default) === 'function') {
|
|
134
118
|
const img = lib.sharp.default(bufferOrFilePath);
|
|
135
|
-
const dimensions =
|
|
136
|
-
const buffer =
|
|
119
|
+
const dimensions = await img.metadata();
|
|
120
|
+
const buffer = await img
|
|
137
121
|
.resize(width)
|
|
138
122
|
.jpeg({ quality: 50 })
|
|
139
123
|
.toBuffer();
|
|
@@ -147,12 +131,12 @@ const extractImageThumb = (bufferOrFilePath_1, ...args_1) => __awaiter(void 0, [
|
|
|
147
131
|
}
|
|
148
132
|
else if ('jimp' in lib && typeof ((_b = lib.jimp) === null || _b === void 0 ? void 0 : _b.read) === 'function') {
|
|
149
133
|
const { read, MIME_JPEG, RESIZE_BILINEAR, AUTO } = lib.jimp;
|
|
150
|
-
const jimp =
|
|
134
|
+
const jimp = await read(bufferOrFilePath);
|
|
151
135
|
const dimensions = {
|
|
152
136
|
width: jimp.getWidth(),
|
|
153
137
|
height: jimp.getHeight()
|
|
154
138
|
};
|
|
155
|
-
const buffer =
|
|
139
|
+
const buffer = await jimp
|
|
156
140
|
.quality(50)
|
|
157
141
|
.resize(width, AUTO, RESIZE_BILINEAR)
|
|
158
142
|
.getBufferAsync(MIME_JPEG);
|
|
@@ -164,52 +148,33 @@ const extractImageThumb = (bufferOrFilePath_1, ...args_1) => __awaiter(void 0, [
|
|
|
164
148
|
else {
|
|
165
149
|
throw new boom_1.Boom('No image processing library available');
|
|
166
150
|
}
|
|
167
|
-
}
|
|
151
|
+
};
|
|
168
152
|
exports.extractImageThumb = extractImageThumb;
|
|
169
153
|
const encodeBase64EncodedStringForUpload = (b64) => (encodeURIComponent(b64
|
|
170
154
|
.replace(/\+/g, '-')
|
|
171
155
|
.replace(/\//g, '_')
|
|
172
156
|
.replace(/\=+$/, '')));
|
|
173
157
|
exports.encodeBase64EncodedStringForUpload = encodeBase64EncodedStringForUpload;
|
|
174
|
-
const generateProfilePicture = (mediaUpload) =>
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
else if ('url' in mediaUpload) {
|
|
181
|
-
bufferOrFilePath = mediaUpload.url.toString();
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
bufferOrFilePath = yield (0, exports.toBuffer)(mediaUpload.stream);
|
|
185
|
-
}
|
|
186
|
-
const lib = yield getImageProcessingLibrary();
|
|
158
|
+
const generateProfilePicture = async (mediaUpload) => {
|
|
159
|
+
const bufferOrFilePath = Buffer.isBuffer(mediaUpload)
|
|
160
|
+
? mediaUpload
|
|
161
|
+
: typeof mediaUpload === 'object' && 'url' in mediaUpload
|
|
162
|
+
? mediaUpload.url.toString()
|
|
163
|
+
: await (0, exports.toBuffer)(mediaUpload.stream);
|
|
187
164
|
let img;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const { read, MIME_JPEG, RESIZE_BILINEAR } = lib.jimp;
|
|
198
|
-
const jimp = yield read(bufferOrFilePath);
|
|
199
|
-
const min = Math.min(jimp.getWidth(), jimp.getHeight());
|
|
200
|
-
const cropped = jimp.crop(0, 0, min, min);
|
|
201
|
-
img = cropped
|
|
202
|
-
.quality(50)
|
|
203
|
-
.resize(640, 640, RESIZE_BILINEAR)
|
|
204
|
-
.getBufferAsync(MIME_JPEG);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
throw new boom_1.Boom('No image processing library available');
|
|
208
|
-
}
|
|
165
|
+
const { read, MIME_JPEG, AUTO } = require('jimp');
|
|
166
|
+
const jimp = await read(bufferOrFilePath);
|
|
167
|
+
const min = jimp.getWidth();
|
|
168
|
+
const max = jimp.getHeight();
|
|
169
|
+
const cropped = jimp.crop(0, 0, min, max);
|
|
170
|
+
img = cropped
|
|
171
|
+
.quality(100)
|
|
172
|
+
.scaleToFit(720, 720, AUTO)
|
|
173
|
+
.getBufferAsync(MIME_JPEG);
|
|
209
174
|
return {
|
|
210
|
-
img:
|
|
175
|
+
img: await img
|
|
211
176
|
};
|
|
212
|
-
}
|
|
177
|
+
};
|
|
213
178
|
exports.generateProfilePicture = generateProfilePicture;
|
|
214
179
|
/** gets the SHA256 of the given media message */
|
|
215
180
|
const mediaMessageSHA256B64 = (message) => {
|
|
@@ -217,70 +182,66 @@ const mediaMessageSHA256B64 = (message) => {
|
|
|
217
182
|
return (media === null || media === void 0 ? void 0 : media.fileSha256) && Buffer.from(media.fileSha256).toString('base64');
|
|
218
183
|
};
|
|
219
184
|
exports.mediaMessageSHA256B64 = mediaMessageSHA256B64;
|
|
220
|
-
function getAudioDuration(buffer) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
185
|
+
async function getAudioDuration(buffer) {
|
|
186
|
+
const musicMetadata = await import('music-metadata');
|
|
187
|
+
let metadata;
|
|
188
|
+
if (Buffer.isBuffer(buffer)) {
|
|
189
|
+
metadata = await musicMetadata.parseBuffer(buffer, undefined, { duration: true });
|
|
190
|
+
}
|
|
191
|
+
else if (typeof buffer === 'string') {
|
|
192
|
+
const rStream = (0, fs_1.createReadStream)(buffer);
|
|
193
|
+
try {
|
|
194
|
+
metadata = await musicMetadata.parseStream(rStream, undefined, { duration: true });
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
rStream.destroy();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
metadata = await musicMetadata.parseStream(buffer, undefined, { duration: true });
|
|
202
|
+
}
|
|
203
|
+
return metadata.format.duration;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
|
207
|
+
*/
|
|
208
|
+
async function getAudioWaveform(buffer, logger) {
|
|
209
|
+
try {
|
|
210
|
+
const audioDecode = (buffer) => import('audio-decode').then(({ default: audioDecode }) => audioDecode(buffer));
|
|
211
|
+
let audioData;
|
|
224
212
|
if (Buffer.isBuffer(buffer)) {
|
|
225
|
-
|
|
213
|
+
audioData = buffer;
|
|
226
214
|
}
|
|
227
215
|
else if (typeof buffer === 'string') {
|
|
228
216
|
const rStream = (0, fs_1.createReadStream)(buffer);
|
|
229
|
-
|
|
230
|
-
metadata = yield musicMetadata.parseStream(rStream, undefined, { duration: true });
|
|
231
|
-
}
|
|
232
|
-
finally {
|
|
233
|
-
rStream.destroy();
|
|
234
|
-
}
|
|
217
|
+
audioData = await (0, exports.toBuffer)(rStream);
|
|
235
218
|
}
|
|
236
219
|
else {
|
|
237
|
-
|
|
220
|
+
audioData = await (0, exports.toBuffer)(buffer);
|
|
238
221
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
let audioData;
|
|
250
|
-
if (Buffer.isBuffer(buffer)) {
|
|
251
|
-
audioData = buffer;
|
|
252
|
-
}
|
|
253
|
-
else if (typeof buffer === 'string') {
|
|
254
|
-
const rStream = (0, fs_1.createReadStream)(buffer);
|
|
255
|
-
audioData = yield (0, exports.toBuffer)(rStream);
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
audioData = yield (0, exports.toBuffer)(buffer);
|
|
222
|
+
const audioBuffer = await audioDecode(audioData);
|
|
223
|
+
const rawData = audioBuffer.getChannelData(0); // We only need to work with one channel of data
|
|
224
|
+
const samples = 64; // Number of samples we want to have in our final data set
|
|
225
|
+
const blockSize = Math.floor(rawData.length / samples); // the number of samples in each subdivision
|
|
226
|
+
const filteredData = [];
|
|
227
|
+
for (let i = 0; i < samples; i++) {
|
|
228
|
+
const blockStart = blockSize * i; // the location of the first sample in the block
|
|
229
|
+
let sum = 0;
|
|
230
|
+
for (let j = 0; j < blockSize; j++) {
|
|
231
|
+
sum = sum + Math.abs(rawData[blockStart + j]); // find the sum of all the samples in the block
|
|
259
232
|
}
|
|
260
|
-
|
|
261
|
-
const rawData = audioBuffer.getChannelData(0); // We only need to work with one channel of data
|
|
262
|
-
const samples = 64; // Number of samples we want to have in our final data set
|
|
263
|
-
const blockSize = Math.floor(rawData.length / samples); // the number of samples in each subdivision
|
|
264
|
-
const filteredData = [];
|
|
265
|
-
for (let i = 0; i < samples; i++) {
|
|
266
|
-
const blockStart = blockSize * i; // the location of the first sample in the block
|
|
267
|
-
let sum = 0;
|
|
268
|
-
for (let j = 0; j < blockSize; j++) {
|
|
269
|
-
sum = sum + Math.abs(rawData[blockStart + j]); // find the sum of all the samples in the block
|
|
270
|
-
}
|
|
271
|
-
filteredData.push(sum / blockSize); // divide the sum by the block size to get the average
|
|
272
|
-
}
|
|
273
|
-
// This guarantees that the largest data point will be set to 1, and the rest of the data will scale proportionally.
|
|
274
|
-
const multiplier = Math.pow(Math.max(...filteredData), -1);
|
|
275
|
-
const normalizedData = filteredData.map((n) => n * multiplier);
|
|
276
|
-
// Generate waveform like WhatsApp
|
|
277
|
-
const waveform = new Uint8Array(normalizedData.map((n) => Math.floor(100 * n)));
|
|
278
|
-
return waveform;
|
|
233
|
+
filteredData.push(sum / blockSize); // divide the sum by the block size to get the average
|
|
279
234
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
235
|
+
// This guarantees that the largest data point will be set to 1, and the rest of the data will scale proportionally.
|
|
236
|
+
const multiplier = Math.pow(Math.max(...filteredData), -1);
|
|
237
|
+
const normalizedData = filteredData.map((n) => n * multiplier);
|
|
238
|
+
// Generate waveform like WhatsApp
|
|
239
|
+
const waveform = new Uint8Array(normalizedData.map((n) => Math.floor(100 * n)));
|
|
240
|
+
return waveform;
|
|
241
|
+
}
|
|
242
|
+
catch (e) {
|
|
243
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('Failed to generate waveform: ' + e);
|
|
244
|
+
}
|
|
284
245
|
}
|
|
285
246
|
const toReadable = (buffer) => {
|
|
286
247
|
const readable = new stream_1.Readable({ read: () => { } });
|
|
@@ -289,30 +250,16 @@ const toReadable = (buffer) => {
|
|
|
289
250
|
return readable;
|
|
290
251
|
};
|
|
291
252
|
exports.toReadable = toReadable;
|
|
292
|
-
const toBuffer = (stream) =>
|
|
293
|
-
var _a, stream_2, stream_2_1;
|
|
294
|
-
var _b, e_1, _c, _d;
|
|
253
|
+
const toBuffer = async (stream) => {
|
|
295
254
|
const chunks = [];
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
_d = stream_2_1.value;
|
|
299
|
-
_a = false;
|
|
300
|
-
const chunk = _d;
|
|
301
|
-
chunks.push(chunk);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
305
|
-
finally {
|
|
306
|
-
try {
|
|
307
|
-
if (!_a && !_b && (_c = stream_2.return)) yield _c.call(stream_2);
|
|
308
|
-
}
|
|
309
|
-
finally { if (e_1) throw e_1.error; }
|
|
255
|
+
for await (const chunk of stream) {
|
|
256
|
+
chunks.push(chunk);
|
|
310
257
|
}
|
|
311
258
|
stream.destroy();
|
|
312
259
|
return Buffer.concat(chunks);
|
|
313
|
-
}
|
|
260
|
+
};
|
|
314
261
|
exports.toBuffer = toBuffer;
|
|
315
|
-
const getStream = (item, opts) =>
|
|
262
|
+
const getStream = async (item, opts) => {
|
|
316
263
|
if (Buffer.isBuffer(item)) {
|
|
317
264
|
return { stream: (0, exports.toReadable)(item), type: 'buffer' };
|
|
318
265
|
}
|
|
@@ -320,58 +267,56 @@ const getStream = (item, opts) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
320
267
|
return { stream: item.stream, type: 'readable' };
|
|
321
268
|
}
|
|
322
269
|
if (item.url.toString().startsWith('http://') || item.url.toString().startsWith('https://')) {
|
|
323
|
-
return { stream:
|
|
270
|
+
return { stream: await (0, exports.getHttpStream)(item.url, opts), type: 'remote' };
|
|
324
271
|
}
|
|
325
272
|
return { stream: (0, fs_1.createReadStream)(item.url), type: 'file' };
|
|
326
|
-
}
|
|
273
|
+
};
|
|
327
274
|
exports.getStream = getStream;
|
|
328
275
|
/** generates a thumbnail for a given media, if required */
|
|
329
|
-
function generateThumbnail(file, mediaType, options) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
};
|
|
342
|
-
}
|
|
276
|
+
async function generateThumbnail(file, mediaType, options) {
|
|
277
|
+
var _a;
|
|
278
|
+
let thumbnail;
|
|
279
|
+
let originalImageDimensions;
|
|
280
|
+
if (mediaType === 'image') {
|
|
281
|
+
const { buffer, original } = await (0, exports.extractImageThumb)(file);
|
|
282
|
+
thumbnail = buffer.toString('base64');
|
|
283
|
+
if (original.width && original.height) {
|
|
284
|
+
originalImageDimensions = {
|
|
285
|
+
width: original.width,
|
|
286
|
+
height: original.height,
|
|
287
|
+
};
|
|
343
288
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
catch (err) {
|
|
353
|
-
(_a = options.logger) === null || _a === void 0 ? void 0 : _a.debug('could not generate video thumb: ' + err);
|
|
354
|
-
}
|
|
289
|
+
}
|
|
290
|
+
else if (mediaType === 'video') {
|
|
291
|
+
const imgFilename = (0, path_1.join)(getTmpFilesDirectory(), (0, generics_1.generateMessageID)() + '.jpg');
|
|
292
|
+
try {
|
|
293
|
+
await extractVideoThumb(file, imgFilename, '00:00:00', { width: 32, height: 32 });
|
|
294
|
+
const buff = await fs_1.promises.readFile(imgFilename);
|
|
295
|
+
thumbnail = buff.toString('base64');
|
|
296
|
+
await fs_1.promises.unlink(imgFilename);
|
|
355
297
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
298
|
+
catch (err) {
|
|
299
|
+
(_a = options.logger) === null || _a === void 0 ? void 0 : _a.debug('could not generate video thumb: ' + err);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
thumbnail,
|
|
304
|
+
originalImageDimensions
|
|
305
|
+
};
|
|
361
306
|
}
|
|
362
|
-
const getHttpStream =
|
|
363
|
-
const { default: axios } =
|
|
364
|
-
const fetched =
|
|
307
|
+
const getHttpStream = async (url, options = {}) => {
|
|
308
|
+
const { default: axios } = await import('axios');
|
|
309
|
+
const fetched = await axios.get(url.toString(), { ...options, responseType: 'stream' });
|
|
365
310
|
return fetched.data;
|
|
366
|
-
}
|
|
311
|
+
};
|
|
367
312
|
exports.getHttpStream = getHttpStream;
|
|
368
|
-
const prepareStream =
|
|
369
|
-
const { stream, type } =
|
|
313
|
+
const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
|
314
|
+
const { stream, type } = await (0, exports.getStream)(media, opts);
|
|
370
315
|
logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
|
|
371
316
|
let bodyPath;
|
|
372
317
|
let didSaveToTmpPath = false;
|
|
373
318
|
try {
|
|
374
|
-
const buffer =
|
|
319
|
+
const buffer = await (0, exports.toBuffer)(stream);
|
|
375
320
|
if (type === 'file') {
|
|
376
321
|
bodyPath = media.url;
|
|
377
322
|
}
|
|
@@ -399,7 +344,7 @@ const prepareStream = (media_1, mediaType_1, ...args_1) => __awaiter(void 0, [me
|
|
|
399
344
|
stream.destroy();
|
|
400
345
|
if (didSaveToTmpPath) {
|
|
401
346
|
try {
|
|
402
|
-
|
|
347
|
+
await fs_1.promises.unlink(bodyPath);
|
|
403
348
|
}
|
|
404
349
|
catch (err) {
|
|
405
350
|
logger === null || logger === void 0 ? void 0 : logger.error({ err }, 'failed to save to tmp path');
|
|
@@ -407,11 +352,10 @@ const prepareStream = (media_1, mediaType_1, ...args_1) => __awaiter(void 0, [me
|
|
|
407
352
|
}
|
|
408
353
|
throw error;
|
|
409
354
|
}
|
|
410
|
-
}
|
|
355
|
+
};
|
|
411
356
|
exports.prepareStream = prepareStream;
|
|
412
|
-
const encryptedStream =
|
|
413
|
-
|
|
414
|
-
const { stream, type } = yield (0, exports.getStream)(media, opts);
|
|
357
|
+
const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
|
358
|
+
const { stream, type } = await (0, exports.getStream)(media, opts);
|
|
415
359
|
logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
|
|
416
360
|
const mediaKey = Crypto.randomBytes(32);
|
|
417
361
|
const { cipherKey, iv, macKey } = getMediaKeys(mediaKey, mediaType);
|
|
@@ -433,34 +377,22 @@ const encryptedStream = (media_1, mediaType_1, ...args_1) => __awaiter(void 0, [
|
|
|
433
377
|
let sha256Plain = Crypto.createHash('sha256');
|
|
434
378
|
let sha256Enc = Crypto.createHash('sha256');
|
|
435
379
|
try {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
&& fileLength + data.length > opts.maxContentLength) {
|
|
445
|
-
throw new boom_1.Boom(`content length exceeded when encrypting "${type}"`, {
|
|
446
|
-
data: { media, type }
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
sha256Plain = sha256Plain.update(data);
|
|
450
|
-
if (writeStream) {
|
|
451
|
-
if (!writeStream.write(data)) {
|
|
452
|
-
yield (0, events_1.once)(writeStream, 'drain');
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
onChunk(aes.update(data));
|
|
380
|
+
for await (const data of stream) {
|
|
381
|
+
fileLength += data.length;
|
|
382
|
+
if (type === 'remote'
|
|
383
|
+
&& (opts === null || opts === void 0 ? void 0 : opts.maxContentLength)
|
|
384
|
+
&& fileLength + data.length > opts.maxContentLength) {
|
|
385
|
+
throw new boom_1.Boom(`content length exceeded when encrypting "${type}"`, {
|
|
386
|
+
data: { media, type }
|
|
387
|
+
});
|
|
456
388
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
389
|
+
sha256Plain = sha256Plain.update(data);
|
|
390
|
+
if (writeStream) {
|
|
391
|
+
if (!writeStream.write(data)) {
|
|
392
|
+
await (0, events_1.once)(writeStream, 'drain');
|
|
393
|
+
}
|
|
462
394
|
}
|
|
463
|
-
|
|
395
|
+
onChunk(aes.update(data));
|
|
464
396
|
}
|
|
465
397
|
onChunk(aes.final());
|
|
466
398
|
const mac = hmac.digest().slice(0, 10);
|
|
@@ -494,7 +426,7 @@ const encryptedStream = (media_1, mediaType_1, ...args_1) => __awaiter(void 0, [
|
|
|
494
426
|
stream.destroy();
|
|
495
427
|
if (didSaveToTmpPath) {
|
|
496
428
|
try {
|
|
497
|
-
|
|
429
|
+
await fs_1.promises.unlink(bodyPath);
|
|
498
430
|
}
|
|
499
431
|
catch (err) {
|
|
500
432
|
logger === null || logger === void 0 ? void 0 : logger.error({ err }, 'failed to save to tmp path');
|
|
@@ -507,7 +439,7 @@ const encryptedStream = (media_1, mediaType_1, ...args_1) => __awaiter(void 0, [
|
|
|
507
439
|
hmac = hmac.update(buff);
|
|
508
440
|
encWriteStream.push(buff);
|
|
509
441
|
}
|
|
510
|
-
}
|
|
442
|
+
};
|
|
511
443
|
exports.encryptedStream = encryptedStream;
|
|
512
444
|
const DEF_HOST = 'mmg.whatsapp.net';
|
|
513
445
|
const AES_CHUNK_SIZE = 16;
|
|
@@ -526,7 +458,7 @@ exports.downloadContentFromMessage = downloadContentFromMessage;
|
|
|
526
458
|
* Decrypts and downloads an AES256-CBC encrypted file given the keys.
|
|
527
459
|
* Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
|
|
528
460
|
* */
|
|
529
|
-
const downloadEncryptedContent =
|
|
461
|
+
const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, { startByte, endByte, options } = {}) => {
|
|
530
462
|
let bytesFetched = 0;
|
|
531
463
|
let startChunk = 0;
|
|
532
464
|
let firstBlockIsIV = false;
|
|
@@ -540,7 +472,10 @@ const downloadEncryptedContent = (downloadUrl_1, _a, ...args_1) => __awaiter(voi
|
|
|
540
472
|
}
|
|
541
473
|
}
|
|
542
474
|
const endChunk = endByte ? toSmallestChunkSize(endByte || 0) + AES_CHUNK_SIZE : undefined;
|
|
543
|
-
const headers =
|
|
475
|
+
const headers = {
|
|
476
|
+
...(options === null || options === void 0 ? void 0 : options.headers) || {},
|
|
477
|
+
Origin: Defaults_1.DEFAULT_ORIGIN,
|
|
478
|
+
};
|
|
544
479
|
if (startChunk || endChunk) {
|
|
545
480
|
headers.Range = `bytes=${startChunk}-`;
|
|
546
481
|
if (endChunk) {
|
|
@@ -548,7 +483,12 @@ const downloadEncryptedContent = (downloadUrl_1, _a, ...args_1) => __awaiter(voi
|
|
|
548
483
|
}
|
|
549
484
|
}
|
|
550
485
|
// download the message
|
|
551
|
-
const fetched =
|
|
486
|
+
const fetched = await (0, exports.getHttpStream)(downloadUrl, {
|
|
487
|
+
...options || {},
|
|
488
|
+
headers,
|
|
489
|
+
maxBodyLength: Infinity,
|
|
490
|
+
maxContentLength: Infinity,
|
|
491
|
+
});
|
|
552
492
|
let remainingBytes = Buffer.from([]);
|
|
553
493
|
let aes;
|
|
554
494
|
const pushBytes = (bytes, push) => {
|
|
@@ -600,7 +540,7 @@ const downloadEncryptedContent = (downloadUrl_1, _a, ...args_1) => __awaiter(voi
|
|
|
600
540
|
},
|
|
601
541
|
});
|
|
602
542
|
return fetched.pipe(output, { end: true });
|
|
603
|
-
}
|
|
543
|
+
};
|
|
604
544
|
exports.downloadEncryptedContent = downloadEncryptedContent;
|
|
605
545
|
function extensionForMediaMessage(message) {
|
|
606
546
|
const getExtension = (mimetype) => mimetype.split(';')[0].split('/')[1];
|
|
@@ -618,31 +558,17 @@ function extensionForMediaMessage(message) {
|
|
|
618
558
|
return extension;
|
|
619
559
|
}
|
|
620
560
|
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
621
|
-
return
|
|
622
|
-
var
|
|
623
|
-
|
|
624
|
-
var _f, _g;
|
|
625
|
-
const { default: axios } = yield Promise.resolve().then(() => __importStar(require('axios')));
|
|
561
|
+
return async (stream, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
|
|
562
|
+
var _a, _b;
|
|
563
|
+
const { default: axios } = await import('axios');
|
|
626
564
|
// send a query JSON to obtain the url & auth token to upload our media
|
|
627
|
-
let uploadInfo =
|
|
565
|
+
let uploadInfo = await refreshMediaConn(false);
|
|
628
566
|
let urls;
|
|
629
567
|
const hosts = [...customUploadHosts, ...uploadInfo.hosts];
|
|
630
568
|
const chunks = [];
|
|
631
569
|
if (!Buffer.isBuffer(stream)) {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
_e = stream_5_1.value;
|
|
635
|
-
_b = false;
|
|
636
|
-
const chunk = _e;
|
|
637
|
-
chunks.push(chunk);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
641
|
-
finally {
|
|
642
|
-
try {
|
|
643
|
-
if (!_b && !_c && (_d = stream_5.return)) yield _d.call(stream_5);
|
|
644
|
-
}
|
|
645
|
-
finally { if (e_3) throw e_3.error; }
|
|
570
|
+
for await (const chunk of stream) {
|
|
571
|
+
chunks.push(chunk);
|
|
646
572
|
}
|
|
647
573
|
}
|
|
648
574
|
const reqBody = Buffer.isBuffer(stream) ? stream : Buffer.concat(chunks);
|
|
@@ -660,7 +586,19 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
660
586
|
if (maxContentLengthBytes && reqBody.length > maxContentLengthBytes) {
|
|
661
587
|
throw new boom_1.Boom(`Body too large for "${hostname}"`, { statusCode: 413 });
|
|
662
588
|
}
|
|
663
|
-
const body =
|
|
589
|
+
const body = await axios.post(url, reqBody, {
|
|
590
|
+
...options,
|
|
591
|
+
headers: {
|
|
592
|
+
...options.headers || {},
|
|
593
|
+
'Content-Type': 'application/octet-stream',
|
|
594
|
+
'Origin': Defaults_1.DEFAULT_ORIGIN
|
|
595
|
+
},
|
|
596
|
+
httpsAgent: fetchAgent,
|
|
597
|
+
timeout: timeoutMs,
|
|
598
|
+
responseType: 'json',
|
|
599
|
+
maxBodyLength: Infinity,
|
|
600
|
+
maxContentLength: Infinity,
|
|
601
|
+
});
|
|
664
602
|
result = body.data;
|
|
665
603
|
if ((result === null || result === void 0 ? void 0 : result.url) || (result === null || result === void 0 ? void 0 : result.directPath)) {
|
|
666
604
|
urls = {
|
|
@@ -671,15 +609,15 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
671
609
|
break;
|
|
672
610
|
}
|
|
673
611
|
else {
|
|
674
|
-
uploadInfo =
|
|
612
|
+
uploadInfo = await refreshMediaConn(true);
|
|
675
613
|
throw new Error(`upload failed, reason: ${JSON.stringify(result)}`);
|
|
676
614
|
}
|
|
677
615
|
}
|
|
678
616
|
catch (error) {
|
|
679
617
|
if (axios.isAxiosError(error)) {
|
|
680
|
-
result = (
|
|
618
|
+
result = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
681
619
|
}
|
|
682
|
-
const isLast = hostname === ((
|
|
620
|
+
const isLast = hostname === ((_b = hosts[uploadInfo.hosts.length - 1]) === null || _b === void 0 ? void 0 : _b.hostname);
|
|
683
621
|
logger.warn({ trace: error.stack, uploadResult: result }, `Error in uploading to ${hostname} ${isLast ? '' : ', retrying...'}`);
|
|
684
622
|
}
|
|
685
623
|
}
|
|
@@ -687,7 +625,7 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
687
625
|
throw new boom_1.Boom('Media upload failed on all hosts', { statusCode: 500 });
|
|
688
626
|
}
|
|
689
627
|
return urls;
|
|
690
|
-
}
|
|
628
|
+
};
|
|
691
629
|
};
|
|
692
630
|
exports.getWAUploadToServer = getWAUploadToServer;
|
|
693
631
|
const getMediaRetryKey = (mediaKey) => {
|