@queenanya/baileys 7.4.10 → 7.4.14
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 +26 -26
- package/WAProto/index.js +97194 -67957
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +231 -1
- package/lib/Defaults/index.js +23 -11
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +2 -2
- package/lib/Socket/business.d.ts +28 -31
- package/lib/Socket/chats.d.ts +9 -17
- package/lib/Socket/chats.js +116 -115
- package/lib/Socket/groups.d.ts +10 -23
- package/lib/Socket/groups.js +1 -12
- package/lib/Socket/index.d.ts +38 -69
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +28 -30
- package/lib/Socket/messages-recv.js +180 -291
- package/lib/Socket/messages-send.d.ts +19 -25
- package/lib/Socket/messages-send.js +76 -110
- package/lib/Socket/newsletter.d.ts +13 -19
- package/lib/Socket/newsletter.js +54 -67
- package/lib/Socket/{communities.d.ts → registration.d.ts} +145 -94
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +1 -3
- package/lib/Socket/socket.js +17 -15
- package/lib/Store/make-cache-manager-store.d.ts +1 -2
- package/lib/Store/make-in-memory-store.js +11 -13
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +6 -1
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -15
- package/lib/Types/Contact.d.ts +1 -6
- package/lib/Types/Events.d.ts +2 -44
- package/lib/Types/GroupMetadata.d.ts +1 -3
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Message.d.ts +30 -37
- package/lib/Types/Newsletter.d.ts +13 -0
- package/lib/Types/Newsletter.js +15 -1
- package/lib/Types/Socket.d.ts +3 -10
- package/lib/Types/index.d.ts +0 -8
- package/lib/Utils/auth-utils.js +7 -1
- package/lib/Utils/chat-utils.d.ts +4 -5
- package/lib/Utils/chat-utils.js +20 -52
- package/lib/Utils/crypto.d.ts +1 -2
- package/lib/Utils/crypto.js +2 -4
- package/lib/Utils/decode-wa-message.d.ts +0 -1
- package/lib/Utils/decode-wa-message.js +14 -34
- package/lib/Utils/event-buffer.js +8 -14
- package/lib/Utils/generics.d.ts +13 -37
- package/lib/Utils/generics.js +18 -103
- package/lib/Utils/history.d.ts +2 -6
- package/lib/Utils/history.js +0 -3
- package/lib/Utils/index.d.ts +0 -1
- package/lib/Utils/index.js +0 -1
- package/lib/Utils/link-preview.js +1 -24
- package/lib/Utils/logger.d.ts +3 -1
- package/lib/Utils/make-mutex.js +0 -1
- package/lib/Utils/messages-media.d.ts +2 -3
- package/lib/Utils/messages-media.js +32 -17
- package/lib/Utils/messages.d.ts +0 -1
- package/lib/Utils/messages.js +72 -67
- package/lib/Utils/noise-handler.d.ts +3 -3
- package/lib/Utils/noise-handler.js +12 -7
- package/lib/Utils/process-message.d.ts +2 -3
- package/lib/Utils/process-message.js +21 -55
- package/lib/Utils/signal.js +16 -23
- package/lib/Utils/use-multi-file-auth-state.js +3 -17
- package/lib/Utils/validate-connection.d.ts +1 -0
- package/lib/Utils/validate-connection.js +44 -10
- package/lib/WABinary/constants.js +5 -5
- package/lib/WABinary/decode.d.ts +2 -3
- package/lib/WABinary/decode.js +4 -6
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +6 -8
- package/lib/WABinary/generic-utils.d.ts +0 -1
- package/lib/WABinary/jid-utils.d.ts +3 -3
- package/lib/WABinary/jid-utils.js +5 -5
- package/lib/WAM/BinaryInfo.d.ts +2 -3
- package/lib/WAM/constants.d.ts +2 -3
- package/lib/WAM/encode.d.ts +0 -1
- package/lib/WAM/encode.js +2 -2
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/package.json +36 -38
- package/lib/Socket/communities.js +0 -354
- package/lib/Socket/usync.d.ts +0 -38
- package/lib/Socket/usync.js +0 -70
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/USync.js +0 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/Protocols/index.js +0 -20
- package/lib/WAUSync/USyncQuery.d.ts +0 -26
- package/lib/WAUSync/USyncQuery.js +0 -79
- package/lib/WAUSync/USyncUser.d.ts +0 -10
- package/lib/WAUSync/USyncUser.js +0 -22
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/WAUSync/index.js +0 -19
- /package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +0 -0
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
|
@@ -138,9 +138,7 @@ const makeBufferData = () => {
|
|
|
138
138
|
groupUpdates: {}
|
|
139
139
|
};
|
|
140
140
|
};
|
|
141
|
-
function append(data, historyCache, event,
|
|
142
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
143
|
-
eventData, logger) {
|
|
141
|
+
function append(data, historyCache, event, eventData, logger) {
|
|
144
142
|
var _a, _b, _c;
|
|
145
143
|
switch (event) {
|
|
146
144
|
case 'messaging-history.set':
|
|
@@ -178,9 +176,6 @@ eventData, logger) {
|
|
|
178
176
|
}
|
|
179
177
|
}
|
|
180
178
|
data.historySets.empty = false;
|
|
181
|
-
data.historySets.syncType = eventData.syncType;
|
|
182
|
-
data.historySets.progress = eventData.progress;
|
|
183
|
-
data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
|
|
184
179
|
data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
|
|
185
180
|
break;
|
|
186
181
|
case 'chats.upsert':
|
|
@@ -447,10 +442,7 @@ function consolidateEvents(data) {
|
|
|
447
442
|
chats: Object.values(data.historySets.chats),
|
|
448
443
|
messages: Object.values(data.historySets.messages),
|
|
449
444
|
contacts: Object.values(data.historySets.contacts),
|
|
450
|
-
|
|
451
|
-
progress: data.historySets.progress,
|
|
452
|
-
isLatest: data.historySets.isLatest,
|
|
453
|
-
peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
|
|
445
|
+
isLatest: data.historySets.isLatest
|
|
454
446
|
};
|
|
455
447
|
}
|
|
456
448
|
const chatUpsertList = Object.values(data.chatUpserts);
|
|
@@ -504,10 +496,12 @@ function consolidateEvents(data) {
|
|
|
504
496
|
return map;
|
|
505
497
|
}
|
|
506
498
|
function concatChats(a, b) {
|
|
507
|
-
if (b.unreadCount === null
|
|
508
|
-
|
|
509
|
-
a.unreadCount
|
|
510
|
-
|
|
499
|
+
if (b.unreadCount === null) {
|
|
500
|
+
// neutralize unread counter
|
|
501
|
+
if (a.unreadCount < 0) {
|
|
502
|
+
a.unreadCount = undefined;
|
|
503
|
+
b.unreadCount = undefined;
|
|
504
|
+
}
|
|
511
505
|
}
|
|
512
506
|
if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
|
|
513
507
|
b = { ...b };
|
package/lib/Utils/generics.d.ts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
import { AxiosRequestConfig } from 'axios';
|
|
4
3
|
import { Logger } from 'pino';
|
|
5
4
|
import { proto } from '../../WAProto';
|
|
6
|
-
import { BaileysEventEmitter, BaileysEventMap,
|
|
5
|
+
import { BaileysEventEmitter, BaileysEventMap, WACallUpdateType, WAVersion } from '../Types';
|
|
7
6
|
import { BinaryNode } from '../WABinary';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
*/
|
|
17
|
-
export declare const Browsers: BrowsersMap;
|
|
18
|
-
/** Other Browser Support for Paircode */
|
|
19
|
-
export declare const getPlatformId: (browser: string) => any;
|
|
7
|
+
export declare const Browsers: {
|
|
8
|
+
ubuntu: (browser: any) => [string, string, string];
|
|
9
|
+
macOS: (browser: any) => [string, string, string];
|
|
10
|
+
baileys: (browser: any) => [string, string, string];
|
|
11
|
+
windows: (browser: any) => [string, string, string];
|
|
12
|
+
/** The appropriate browser based on your OS & release */
|
|
13
|
+
appropriate: (browser: any) => [string, string, string];
|
|
14
|
+
};
|
|
20
15
|
export declare const BufferJSON: {
|
|
21
16
|
replacer: (k: any, value: any) => any;
|
|
22
17
|
reviver: (_: any, value: any) => any;
|
|
@@ -25,7 +20,6 @@ export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, m
|
|
|
25
20
|
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
|
|
26
21
|
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
|
|
27
22
|
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer;
|
|
28
|
-
export declare const encodeNewsletterMessage: (message: proto.IMessage) => Uint8Array;
|
|
29
23
|
export declare const generateRegistrationId: () => number;
|
|
30
24
|
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
|
|
31
25
|
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
|
@@ -45,29 +39,15 @@ export declare const delayCancellable: (ms: number) => {
|
|
|
45
39
|
};
|
|
46
40
|
export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
|
|
47
41
|
export declare const generateMessageIDV2: (userId?: string) => string;
|
|
48
|
-
export declare const generateMessageIDV3: (userId?: string) => string;
|
|
49
42
|
export declare const generateMessageID: () => string;
|
|
50
43
|
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
51
|
-
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
44
|
+
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
52
45
|
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
|
|
53
|
-
/**
|
|
54
|
-
* utility that fetches latest baileys version from the main branch.
|
|
55
|
-
* Use to ensure your WA connection is always on the latest version
|
|
56
|
-
*/
|
|
57
|
-
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
|
|
58
|
-
version: number[];
|
|
59
|
-
isLatest: boolean;
|
|
60
|
-
error?: undefined;
|
|
61
|
-
} | {
|
|
62
|
-
version: WAVersion;
|
|
63
|
-
isLatest: boolean;
|
|
64
|
-
error: any;
|
|
65
|
-
}>;
|
|
66
46
|
/**
|
|
67
47
|
* utility that fetches latest baileys version from the master branch.
|
|
68
48
|
* Use to ensure your WA connection is always on the latest version
|
|
69
49
|
*/
|
|
70
|
-
export declare const
|
|
50
|
+
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
|
|
71
51
|
version: WAVersion;
|
|
72
52
|
isLatest: boolean;
|
|
73
53
|
error?: undefined;
|
|
@@ -80,7 +60,7 @@ export declare const fetchLatestBaileysVersion2: (options?: AxiosRequestConfig<a
|
|
|
80
60
|
* A utility that fetches the latest web version of whatsapp.
|
|
81
61
|
* Use to ensure your WA connection is always on the latest version
|
|
82
62
|
*/
|
|
83
|
-
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<
|
|
63
|
+
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<any>) => Promise<{
|
|
84
64
|
version: WAVersion;
|
|
85
65
|
isLatest: boolean;
|
|
86
66
|
error?: undefined;
|
|
@@ -111,9 +91,5 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
|
111
91
|
* @param platform AuthenticationCreds.platform
|
|
112
92
|
*/
|
|
113
93
|
export declare const isWABusinessPlatform: (platform: string) => boolean;
|
|
114
|
-
export declare function trimUndefined(obj:
|
|
115
|
-
[_: string]: any;
|
|
116
|
-
}): {
|
|
117
|
-
[_: string]: any;
|
|
118
|
-
};
|
|
94
|
+
export declare function trimUndefined(obj: any): any;
|
|
119
95
|
export declare function bytesToCrockford(buffer: Buffer): string;
|
package/lib/Utils/generics.js
CHANGED
|
@@ -1,32 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.
|
|
6
|
+
exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.Browsers = void 0;
|
|
30
7
|
const boom_1 = require("@hapi/boom");
|
|
31
8
|
const axios_1 = __importDefault(require("axios"));
|
|
32
9
|
const crypto_1 = require("crypto");
|
|
@@ -35,49 +12,27 @@ const WAProto_1 = require("../../WAProto");
|
|
|
35
12
|
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
36
13
|
const Types_1 = require("../Types");
|
|
37
14
|
const WABinary_1 = require("../WABinary");
|
|
38
|
-
/** Added Extra Browsers or Platforms*/
|
|
39
15
|
const PLATFORM_MAP = {
|
|
40
16
|
'aix': 'AIX',
|
|
41
17
|
'darwin': 'Mac OS',
|
|
42
18
|
'win32': 'Windows',
|
|
43
|
-
'android': 'Android'
|
|
44
|
-
'freebsd': 'FreeBSD',
|
|
45
|
-
'openbsd': 'OpenBSD',
|
|
46
|
-
'sunos': 'Solaris'
|
|
19
|
+
'android': 'Android'
|
|
47
20
|
};
|
|
48
|
-
/**
|
|
49
|
-
const COMPANION_PLATFORM_MAP = {
|
|
50
|
-
'Chrome': '49',
|
|
51
|
-
'Edge': '50',
|
|
52
|
-
'Firefox': '51',
|
|
53
|
-
'Opera': '53',
|
|
54
|
-
'Safari': '54'
|
|
55
|
-
}
|
|
56
|
-
*/
|
|
57
21
|
exports.Browsers = {
|
|
58
|
-
ubuntu:
|
|
59
|
-
macOS:
|
|
60
|
-
baileys:
|
|
61
|
-
windows:
|
|
62
|
-
// iOS: (browser) => ['iOS', browser, '18.1'],
|
|
22
|
+
ubuntu: browser => ['Ubuntu', browser, '20.0.04'],
|
|
23
|
+
macOS: browser => ['Mac OS', browser, '10.15.7'],
|
|
24
|
+
baileys: browser => ['Baileys', browser, '4.0.0'],
|
|
25
|
+
windows: browser => ['Windows', browser, '10.0.22621'],
|
|
63
26
|
/** The appropriate browser based on your OS & release */
|
|
64
|
-
appropriate:
|
|
27
|
+
appropriate: browser => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
65
28
|
};
|
|
66
|
-
/** Other Browser Support for Paircode */
|
|
67
|
-
const getPlatformId = (browser) => {
|
|
68
|
-
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
69
|
-
return platformType ? platformType.toString().charCodeAt(0).toString() : '51'; // Firefox
|
|
70
|
-
};
|
|
71
|
-
exports.getPlatformId = getPlatformId;
|
|
72
29
|
exports.BufferJSON = {
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
30
|
replacer: (k, value) => {
|
|
75
31
|
if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
|
|
76
32
|
return { type: 'Buffer', data: Buffer.from((value === null || value === void 0 ? void 0 : value.data) || value).toString('base64') };
|
|
77
33
|
}
|
|
78
34
|
return value;
|
|
79
35
|
},
|
|
80
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
36
|
reviver: (_, value) => {
|
|
82
37
|
if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
|
|
83
38
|
const val = value.data || value.value;
|
|
@@ -111,8 +66,6 @@ const unpadRandomMax16 = (e) => {
|
|
|
111
66
|
exports.unpadRandomMax16 = unpadRandomMax16;
|
|
112
67
|
const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
|
|
113
68
|
exports.encodeWAMessage = encodeWAMessage;
|
|
114
|
-
const encodeNewsletterMessage = (message) => (WAProto_1.proto.Message.encode(message).finish());
|
|
115
|
-
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
116
69
|
const generateRegistrationId = () => {
|
|
117
70
|
return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
|
|
118
71
|
};
|
|
@@ -127,7 +80,7 @@ const encodeBigEndian = (e, t = 4) => {
|
|
|
127
80
|
return a;
|
|
128
81
|
};
|
|
129
82
|
exports.encodeBigEndian = encodeBigEndian;
|
|
130
|
-
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t
|
|
83
|
+
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
|
|
131
84
|
exports.toNumber = toNumber;
|
|
132
85
|
/** unix timestamp of a date in seconds */
|
|
133
86
|
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
@@ -194,7 +147,6 @@ async function promiseTimeout(ms, promise) {
|
|
|
194
147
|
return p;
|
|
195
148
|
}
|
|
196
149
|
exports.promiseTimeout = promiseTimeout;
|
|
197
|
-
//Useless but still keep this to avoid unexpected errors and bugs
|
|
198
150
|
const generateMessageIDV2 = (userId) => {
|
|
199
151
|
const data = Buffer.alloc(8 + 20 + 16);
|
|
200
152
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
@@ -208,19 +160,11 @@ const generateMessageIDV2 = (userId) => {
|
|
|
208
160
|
const random = (0, crypto_1.randomBytes)(16);
|
|
209
161
|
random.copy(data, 28);
|
|
210
162
|
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
|
211
|
-
return '
|
|
163
|
+
return '_OLD_USER_' + hash.toString('hex').toUpperCase().substring(0, 18);
|
|
212
164
|
};
|
|
213
165
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
214
|
-
//Message ID function for Anya_Baileyz
|
|
215
|
-
//This V3 is RollBack Update Of Old Message ID
|
|
216
|
-
const generateMessageIDV3 = (userId) => {
|
|
217
|
-
let swebfix = 'ANYAWEB';
|
|
218
|
-
let swebRandom = (0, crypto_1.randomBytes)(5).toString('hex').toUpperCase().substring(0, 10);
|
|
219
|
-
return swebfix + swebRandom;
|
|
220
|
-
};
|
|
221
|
-
exports.generateMessageIDV3 = generateMessageIDV3;
|
|
222
166
|
// generate a random ID to attach to a message
|
|
223
|
-
const generateMessageID = () => '
|
|
167
|
+
const generateMessageID = () => 'FELZ' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
224
168
|
exports.generateMessageID = generateMessageID;
|
|
225
169
|
function bindWaitForEvent(ev, event) {
|
|
226
170
|
return async (check, timeoutMs) => {
|
|
@@ -253,7 +197,8 @@ exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
|
253
197
|
const printQRIfNecessaryListener = (ev, logger) => {
|
|
254
198
|
ev.on('connection.update', async ({ qr }) => {
|
|
255
199
|
if (qr) {
|
|
256
|
-
const QR = await
|
|
200
|
+
const QR = await import('qrcode-terminal')
|
|
201
|
+
.then(m => m.default || m)
|
|
257
202
|
.catch(() => {
|
|
258
203
|
logger.error('QR code terminal not added as dependency');
|
|
259
204
|
});
|
|
@@ -262,37 +207,11 @@ const printQRIfNecessaryListener = (ev, logger) => {
|
|
|
262
207
|
});
|
|
263
208
|
};
|
|
264
209
|
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
265
|
-
/**
|
|
266
|
-
* utility that fetches latest baileys version from the main branch.
|
|
267
|
-
* Use to ensure your WA connection is always on the latest version
|
|
268
|
-
*/
|
|
269
|
-
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
270
|
-
try {
|
|
271
|
-
const result = await axios_1.default.get('https://raw.githubusercontent.com/wppconnect-team/wa-version/main/versions.json', {
|
|
272
|
-
...options,
|
|
273
|
-
responseType: 'json'
|
|
274
|
-
});
|
|
275
|
-
const version = result.data.currentVersion.split('.');
|
|
276
|
-
const version2 = version[2].replace('-alpha', '');
|
|
277
|
-
return {
|
|
278
|
-
version: [+version[0], +version[1], +version2],
|
|
279
|
-
isLatest: true
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
catch (error) {
|
|
283
|
-
return {
|
|
284
|
-
version: baileys_version_json_1.version,
|
|
285
|
-
isLatest: false,
|
|
286
|
-
error
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
291
210
|
/**
|
|
292
211
|
* utility that fetches latest baileys version from the master branch.
|
|
293
212
|
* Use to ensure your WA connection is always on the latest version
|
|
294
213
|
*/
|
|
295
|
-
const
|
|
214
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
296
215
|
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json';
|
|
297
216
|
try {
|
|
298
217
|
const result = await axios_1.default.get(URL, {
|
|
@@ -312,7 +231,7 @@ const fetchLatestBaileysVersion2 = async (options = {}) => {
|
|
|
312
231
|
};
|
|
313
232
|
}
|
|
314
233
|
};
|
|
315
|
-
exports.
|
|
234
|
+
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
316
235
|
/**
|
|
317
236
|
* A utility that fetches the latest web version of whatsapp.
|
|
318
237
|
* Use to ensure your WA connection is always on the latest version
|
|
@@ -393,8 +312,7 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
393
312
|
status = 'timeout';
|
|
394
313
|
}
|
|
395
314
|
else {
|
|
396
|
-
|
|
397
|
-
status = 'terminate';
|
|
315
|
+
status = 'reject';
|
|
398
316
|
}
|
|
399
317
|
break;
|
|
400
318
|
case 'reject':
|
|
@@ -420,9 +338,7 @@ const getCodeFromWSError = (error) => {
|
|
|
420
338
|
statusCode = code;
|
|
421
339
|
}
|
|
422
340
|
}
|
|
423
|
-
else if (
|
|
424
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
425
|
-
((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
|
|
341
|
+
else if (((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
|
|
426
342
|
|| ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
|
|
427
343
|
statusCode = 408;
|
|
428
344
|
}
|
|
@@ -437,7 +353,6 @@ const isWABusinessPlatform = (platform) => {
|
|
|
437
353
|
return platform === 'smbi' || platform === 'smba';
|
|
438
354
|
};
|
|
439
355
|
exports.isWABusinessPlatform = isWABusinessPlatform;
|
|
440
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
441
356
|
function trimUndefined(obj) {
|
|
442
357
|
for (const key in obj) {
|
|
443
358
|
if (typeof obj[key] === 'undefined') {
|
|
@@ -452,8 +367,8 @@ function bytesToCrockford(buffer) {
|
|
|
452
367
|
let value = 0;
|
|
453
368
|
let bitCount = 0;
|
|
454
369
|
const crockford = [];
|
|
455
|
-
for (
|
|
456
|
-
value = (value << 8) | (
|
|
370
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
371
|
+
value = (value << 8) | (buffer[i] & 0xff);
|
|
457
372
|
bitCount += 8;
|
|
458
373
|
while (bitCount >= 5) {
|
|
459
374
|
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
package/lib/Utils/history.d.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { proto } from '../../WAProto';
|
|
3
3
|
import { Chat, Contact } from '../Types';
|
|
4
|
-
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
|
4
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
|
|
5
5
|
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
6
6
|
chats: Chat[];
|
|
7
7
|
contacts: Contact[];
|
|
8
8
|
messages: proto.IWebMessageInfo[];
|
|
9
|
-
syncType: proto.HistorySync.HistorySyncType;
|
|
10
|
-
progress: number | null | undefined;
|
|
11
9
|
};
|
|
12
|
-
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
|
10
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
|
|
13
11
|
chats: Chat[];
|
|
14
12
|
contacts: Contact[];
|
|
15
13
|
messages: proto.IWebMessageInfo[];
|
|
16
|
-
syncType: proto.HistorySync.HistorySyncType;
|
|
17
|
-
progress: number | null | undefined;
|
|
18
14
|
}>;
|
|
19
15
|
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|
package/lib/Utils/history.js
CHANGED
|
@@ -32,7 +32,6 @@ const processHistoryMessage = (item) => {
|
|
|
32
32
|
case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
33
33
|
case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
|
|
34
34
|
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
|
35
|
-
case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
36
35
|
for (const chat of item.conversations) {
|
|
37
36
|
contacts.push({ id: chat.id, name: chat.name || undefined });
|
|
38
37
|
const msgs = chat.messages || [];
|
|
@@ -75,8 +74,6 @@ const processHistoryMessage = (item) => {
|
|
|
75
74
|
chats,
|
|
76
75
|
contacts,
|
|
77
76
|
messages,
|
|
78
|
-
syncType: item.syncType,
|
|
79
|
-
progress: item.progress
|
|
80
77
|
};
|
|
81
78
|
};
|
|
82
79
|
exports.processHistoryMessage = processHistoryMessage;
|
package/lib/Utils/index.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ export * from './chat-utils';
|
|
|
11
11
|
export * from './lt-hash';
|
|
12
12
|
export * from './auth-utils';
|
|
13
13
|
export * from './baileys-event-stream';
|
|
14
|
-
export * from './use-single-file-auth-state';
|
|
15
14
|
export * from './use-multi-file-auth-state';
|
|
16
15
|
export * from './link-preview';
|
|
17
16
|
export * from './event-buffer';
|
package/lib/Utils/index.js
CHANGED
|
@@ -27,7 +27,6 @@ __exportStar(require("./chat-utils"), exports);
|
|
|
27
27
|
__exportStar(require("./lt-hash"), exports);
|
|
28
28
|
__exportStar(require("./auth-utils"), exports);
|
|
29
29
|
__exportStar(require("./baileys-event-stream"), exports);
|
|
30
|
-
__exportStar(require("./use-single-file-auth-state"), exports);
|
|
31
30
|
__exportStar(require("./use-multi-file-auth-state"), exports);
|
|
32
31
|
__exportStar(require("./link-preview"), exports);
|
|
33
32
|
__exportStar(require("./event-buffer"), exports);
|
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.getUrlInfo = void 0;
|
|
27
4
|
const messages_1 = require("./messages");
|
|
@@ -48,7 +25,7 @@ const getUrlInfo = async (text, opts = {
|
|
|
48
25
|
// retries
|
|
49
26
|
const retries = 0;
|
|
50
27
|
const maxRetry = 5;
|
|
51
|
-
const { getLinkPreview } = await
|
|
28
|
+
const { getLinkPreview } = await import('link-preview-js');
|
|
52
29
|
let previewLink = text;
|
|
53
30
|
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
54
31
|
previewLink = 'https://' + previewLink;
|
package/lib/Utils/logger.d.ts
CHANGED
package/lib/Utils/make-mutex.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeKeyedMutex = exports.makeMutex = void 0;
|
|
4
4
|
const makeMutex = () => {
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
5
|
let task = Promise.resolve();
|
|
7
6
|
let taskTimeout;
|
|
8
7
|
return {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
-
/// <reference types="node" />
|
|
5
4
|
import { Boom } from '@hapi/boom';
|
|
6
5
|
import { AxiosRequestConfig } from 'axios';
|
|
7
6
|
import type { Logger } from 'pino';
|
|
@@ -100,7 +99,7 @@ export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaTyp
|
|
|
100
99
|
export type MediaDownloadOptions = {
|
|
101
100
|
startByte?: number;
|
|
102
101
|
endByte?: number;
|
|
103
|
-
options?: AxiosRequestConfig<
|
|
102
|
+
options?: AxiosRequestConfig<any>;
|
|
104
103
|
};
|
|
105
104
|
export declare const getUrlFromDirectPath: (directPath: string) => string;
|
|
106
105
|
export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
|
|
@@ -116,7 +115,7 @@ export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logg
|
|
|
116
115
|
*/
|
|
117
116
|
export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
|
|
118
117
|
export declare const decodeMediaRetryNode: (node: BinaryNode) => {
|
|
119
|
-
key:
|
|
118
|
+
key: proto.IMessageKey;
|
|
120
119
|
media?: {
|
|
121
120
|
ciphertext: Uint8Array;
|
|
122
121
|
iv: Uint8Array;
|
|
@@ -22,13 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
26
|
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.extensionForMediaMessage = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.prepareStream = exports.getHttpStream = exports.generateThumbnail = exports.getStream = exports.toBuffer = exports.toReadable = exports.getAudioWaveform = exports.getAudioDuration = exports.mediaMessageSHA256B64 = exports.changeprofileFull = exports.generatePP = exports.generateProfilePictureFP = exports.generateProfilePictureFull = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.getMediaKeys = exports.hkdfInfoKey = void 0;
|
|
30
27
|
const boom_1 = require("@hapi/boom");
|
|
31
|
-
const axios_1 = __importDefault(require("axios"));
|
|
32
28
|
const child_process_1 = require("child_process");
|
|
33
29
|
const Crypto = __importStar(require("crypto"));
|
|
34
30
|
const events_1 = require("events");
|
|
@@ -45,11 +41,13 @@ const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
|
|
|
45
41
|
const getImageProcessingLibrary = async () => {
|
|
46
42
|
const [_jimp, sharp] = await Promise.all([
|
|
47
43
|
(async () => {
|
|
48
|
-
const jimp = await (
|
|
44
|
+
const jimp = await (import('jimp')
|
|
45
|
+
.catch(() => { }));
|
|
49
46
|
return jimp;
|
|
50
47
|
})(),
|
|
51
48
|
(async () => {
|
|
52
|
-
const sharp = await (
|
|
49
|
+
const sharp = await (import('sharp')
|
|
50
|
+
.catch(() => { }));
|
|
53
51
|
return sharp;
|
|
54
52
|
})()
|
|
55
53
|
]);
|
|
@@ -260,7 +258,7 @@ const mediaMessageSHA256B64 = (message) => {
|
|
|
260
258
|
};
|
|
261
259
|
exports.mediaMessageSHA256B64 = mediaMessageSHA256B64;
|
|
262
260
|
async function getAudioDuration(buffer) {
|
|
263
|
-
const musicMetadata = await
|
|
261
|
+
const musicMetadata = await import('music-metadata');
|
|
264
262
|
let metadata;
|
|
265
263
|
if (Buffer.isBuffer(buffer)) {
|
|
266
264
|
metadata = await musicMetadata.parseBuffer(buffer, undefined, { duration: true });
|
|
@@ -285,7 +283,7 @@ exports.getAudioDuration = getAudioDuration;
|
|
|
285
283
|
*/
|
|
286
284
|
async function getAudioWaveform(buffer, logger) {
|
|
287
285
|
try {
|
|
288
|
-
const audioDecode = (buffer) =>
|
|
286
|
+
const audioDecode = (buffer) => import('audio-decode').then(({ default: audioDecode }) => audioDecode(buffer));
|
|
289
287
|
let audioData;
|
|
290
288
|
if (Buffer.isBuffer(buffer)) {
|
|
291
289
|
audioData = buffer;
|
|
@@ -385,7 +383,8 @@ async function generateThumbnail(file, mediaType, options) {
|
|
|
385
383
|
}
|
|
386
384
|
exports.generateThumbnail = generateThumbnail;
|
|
387
385
|
const getHttpStream = async (url, options = {}) => {
|
|
388
|
-
const
|
|
386
|
+
const { default: axios } = await import('axios');
|
|
387
|
+
const fetched = await axios.get(url.toString(), { ...options, responseType: 'stream' });
|
|
389
388
|
return fetched.data;
|
|
390
389
|
};
|
|
391
390
|
exports.getHttpStream = getHttpStream;
|
|
@@ -443,7 +442,7 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
|
|
|
443
442
|
let writeStream;
|
|
444
443
|
let didSaveToTmpPath = false;
|
|
445
444
|
if (type === 'file') {
|
|
446
|
-
bodyPath = media.url
|
|
445
|
+
bodyPath = media.url;
|
|
447
446
|
}
|
|
448
447
|
else if (saveOriginalFileIfRequired) {
|
|
449
448
|
bodyPath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageID)());
|
|
@@ -466,8 +465,10 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
|
|
|
466
465
|
});
|
|
467
466
|
}
|
|
468
467
|
sha256Plain = sha256Plain.update(data);
|
|
469
|
-
if (writeStream
|
|
470
|
-
|
|
468
|
+
if (writeStream) {
|
|
469
|
+
if (!writeStream.write(data)) {
|
|
470
|
+
await (0, events_1.once)(writeStream, 'drain');
|
|
471
|
+
}
|
|
471
472
|
}
|
|
472
473
|
onChunk(aes.update(data));
|
|
473
474
|
}
|
|
@@ -638,23 +639,33 @@ exports.extensionForMediaMessage = extensionForMediaMessage;
|
|
|
638
639
|
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
639
640
|
return async (stream, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
|
|
640
641
|
var _a, _b;
|
|
642
|
+
const { default: axios } = await import('axios');
|
|
641
643
|
// send a query JSON to obtain the url & auth token to upload our media
|
|
642
644
|
let uploadInfo = await refreshMediaConn(false);
|
|
643
645
|
let urls;
|
|
644
646
|
const hosts = [...customUploadHosts, ...uploadInfo.hosts];
|
|
647
|
+
const chunks = [];
|
|
648
|
+
if (!Buffer.isBuffer(stream)) {
|
|
649
|
+
for await (const chunk of stream) {
|
|
650
|
+
chunks.push(chunk);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
const reqBody = Buffer.isBuffer(stream) ? stream : Buffer.concat(chunks);
|
|
645
654
|
fileEncSha256B64 = (0, exports.encodeBase64EncodedStringForUpload)(fileEncSha256B64);
|
|
646
655
|
let media = Defaults_1.MEDIA_PATH_MAP[mediaType];
|
|
647
656
|
if (newsletter) {
|
|
648
657
|
media = media === null || media === void 0 ? void 0 : media.replace('/mms/', '/newsletter/newsletter-');
|
|
649
658
|
}
|
|
650
|
-
for (const { hostname } of hosts) {
|
|
659
|
+
for (const { hostname, maxContentLengthBytes } of hosts) {
|
|
651
660
|
logger.debug(`uploading to "${hostname}"`);
|
|
652
661
|
const auth = encodeURIComponent(uploadInfo.auth); // the auth token
|
|
653
|
-
const url = `https://${hostname}${
|
|
654
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
662
|
+
const url = `https://${hostname}${media}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
|
|
655
663
|
let result;
|
|
656
664
|
try {
|
|
657
|
-
|
|
665
|
+
if (maxContentLengthBytes && reqBody.length > maxContentLengthBytes) {
|
|
666
|
+
throw new boom_1.Boom(`Body too large for "${hostname}"`, { statusCode: 413 });
|
|
667
|
+
}
|
|
668
|
+
const body = await axios.post(url, reqBody, {
|
|
658
669
|
...options,
|
|
659
670
|
headers: {
|
|
660
671
|
...options.headers || {},
|
|
@@ -682,7 +693,7 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
682
693
|
}
|
|
683
694
|
}
|
|
684
695
|
catch (error) {
|
|
685
|
-
if (
|
|
696
|
+
if (axios.isAxiosError(error)) {
|
|
686
697
|
result = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
687
698
|
}
|
|
688
699
|
const isLast = hostname === ((_b = hosts[uploadInfo.hosts.length - 1]) === null || _b === void 0 ? void 0 : _b.hostname);
|
|
@@ -784,3 +795,7 @@ const MEDIA_RETRY_STATUS_MAP = {
|
|
|
784
795
|
[WAProto_1.proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
|
|
785
796
|
[WAProto_1.proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418,
|
|
786
797
|
};
|
|
798
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
799
|
+
function __importStar(arg0) {
|
|
800
|
+
throw new Error('Function not implemented.');
|
|
801
|
+
}
|