mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: pass axios config to all axios instances
This commit is contained in:
@@ -385,7 +385,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const decoded = await extractSyncdPatches(result) // extract from binary node
|
const decoded = await extractSyncdPatches(result, config?.options) // extract from binary node
|
||||||
for(const key in decoded) {
|
for(const key in decoded) {
|
||||||
const name = key as WAPatchName
|
const name = key as WAPatchName
|
||||||
const { patches, hasMorePatches, snapshot } = decoded[name]
|
const { patches, hasMorePatches, snapshot } = decoded[name]
|
||||||
@@ -403,7 +403,15 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
// only process if there are syncd patches
|
// only process if there are syncd patches
|
||||||
if(patches.length) {
|
if(patches.length) {
|
||||||
const { newMutations, state: newState } = await decodePatches(name, patches, states[name], getAppStateSyncKey, onMutation, initialVersionMap[name])
|
const { newMutations, state: newState } = await decodePatches(
|
||||||
|
name,
|
||||||
|
patches,
|
||||||
|
states[name],
|
||||||
|
getAppStateSyncKey,
|
||||||
|
onMutation,
|
||||||
|
config.options,
|
||||||
|
initialVersionMap[name]
|
||||||
|
)
|
||||||
|
|
||||||
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } })
|
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } })
|
||||||
|
|
||||||
@@ -624,6 +632,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
initial!,
|
initial!,
|
||||||
getAppStateSyncKey,
|
getAppStateSyncKey,
|
||||||
onMutation,
|
onMutation,
|
||||||
|
config.options,
|
||||||
undefined,
|
undefined,
|
||||||
logger,
|
logger,
|
||||||
)
|
)
|
||||||
@@ -733,6 +742,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
creds: authState.creds,
|
creds: authState.creds,
|
||||||
keyStore: authState.keys,
|
keyStore: authState.keys,
|
||||||
logger,
|
logger,
|
||||||
|
options: config.options,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ type TestVector = {
|
|||||||
const TEST_VECTORS: TestVector[] = [
|
const TEST_VECTORS: TestVector[] = [
|
||||||
{
|
{
|
||||||
type: 'image',
|
type: 'image',
|
||||||
message: proto.ImageMessage.decode(
|
message: proto.Message.ImageMessage.decode(
|
||||||
Buffer.from(
|
Buffer.from(
|
||||||
'Ck1odHRwczovL21tZy53aGF0c2FwcC5uZXQvZC9mL0FwaHR4WG9fWXZZcDZlUVNSa0tjOHE5d2ozVUpleWdoY3poM3ExX3I0ektnLmVuYxIKaW1hZ2UvanBlZyIgKTuVFyxDc6mTm4GXPlO3Z911Wd8RBeTrPLSWAEdqW8MomcUBQiB7wH5a4nXMKyLOT0A2nFgnnM/DUH8YjQf8QtkCIekaSkogTB+BXKCWDFrmNzozY0DCPn0L4VKd7yG1ZbZwbgRhzVc=',
|
'Ck1odHRwczovL21tZy53aGF0c2FwcC5uZXQvZC9mL0FwaHR4WG9fWXZZcDZlUVNSa0tjOHE5d2ozVUpleWdoY3poM3ExX3I0ektnLmVuYxIKaW1hZ2UvanBlZyIgKTuVFyxDc6mTm4GXPlO3Z911Wd8RBeTrPLSWAEdqW8MomcUBQiB7wH5a4nXMKyLOT0A2nFgnnM/DUH8YjQf8QtkCIekaSkogTB+BXKCWDFrmNzozY0DCPn0L4VKd7yG1ZbZwbgRhzVc=',
|
||||||
'base64'
|
'base64'
|
||||||
@@ -24,7 +24,7 @@ const TEST_VECTORS: TestVector[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'image',
|
type: 'image',
|
||||||
message: proto.ImageMessage.decode(
|
message: proto.Message.ImageMessage.decode(
|
||||||
Buffer.from(
|
Buffer.from(
|
||||||
'Ck1odHRwczovL21tZy53aGF0c2FwcC5uZXQvZC9mL0Ftb2tnWkphNWF6QWZxa3dVRzc0eUNUdTlGeWpjMmd5akpqcXNmMUFpZEU5LmVuYxIKaW1hZ2UvanBlZyIg8IS5TQzdzcuvcR7F8HMhWnXmlsV+GOo9JE1/t2k+o9Yoz6o6QiA7kDk8j5KOEQC0kDFE1qW7lBBDYhm5z06N3SirfUj3CUog/CjYF8e670D5wUJwWv2B2mKzDEo8IJLStDv76YmtPfs=',
|
'Ck1odHRwczovL21tZy53aGF0c2FwcC5uZXQvZC9mL0Ftb2tnWkphNWF6QWZxa3dVRzc0eUNUdTlGeWpjMmd5akpqcXNmMUFpZEU5LmVuYxIKaW1hZ2UvanBlZyIg8IS5TQzdzcuvcR7F8HMhWnXmlsV+GOo9JE1/t2k+o9Yoz6o6QiA7kDk8j5KOEQC0kDFE1qW7lBBDYhm5z06N3SirfUj3CUog/CjYF8e670D5wUJwWv2B2mKzDEo8IJLStDv76YmtPfs=',
|
||||||
'base64'
|
'base64'
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Boom } from '@hapi/boom'
|
import { Boom } from '@hapi/boom'
|
||||||
|
import { AxiosRequestConfig } from 'axios'
|
||||||
import type { Logger } from 'pino'
|
import type { Logger } from 'pino'
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { BaileysEventEmitter, ChatModification, ChatMutation, Contact, InitialAppStateSyncOptions, LastMessageList, LTHashState, WAPatchCreate, WAPatchName } from '../Types'
|
import { BaileysEventEmitter, ChatModification, ChatMutation, Contact, InitialAppStateSyncOptions, LastMessageList, LTHashState, WAPatchCreate, WAPatchName } from '../Types'
|
||||||
@@ -273,7 +274,10 @@ export const decodeSyncdPatch = async(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export const extractSyncdPatches = async(result: BinaryNode) => {
|
export const extractSyncdPatches = async(
|
||||||
|
result: BinaryNode,
|
||||||
|
options: AxiosRequestConfig<any>
|
||||||
|
) => {
|
||||||
const syncNode = getBinaryNodeChild(result, 'sync')
|
const syncNode = getBinaryNodeChild(result, 'sync')
|
||||||
const collectionNodes = getBinaryNodeChildren(syncNode, 'collection')
|
const collectionNodes = getBinaryNodeChildren(syncNode, 'collection')
|
||||||
|
|
||||||
@@ -300,7 +304,7 @@ export const extractSyncdPatches = async(result: BinaryNode) => {
|
|||||||
const blobRef = proto.ExternalBlobReference.decode(
|
const blobRef = proto.ExternalBlobReference.decode(
|
||||||
snapshotNode.content! as Buffer
|
snapshotNode.content! as Buffer
|
||||||
)
|
)
|
||||||
const data = await downloadExternalBlob(blobRef)
|
const data = await downloadExternalBlob(blobRef, options)
|
||||||
snapshot = proto.SyncdSnapshot.decode(data)
|
snapshot = proto.SyncdSnapshot.decode(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,8 +332,11 @@ export const extractSyncdPatches = async(result: BinaryNode) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const downloadExternalBlob = async(blob: proto.IExternalBlobReference) => {
|
export const downloadExternalBlob = async(
|
||||||
const stream = await downloadContentFromMessage(blob, 'md-app-state')
|
blob: proto.IExternalBlobReference,
|
||||||
|
options: AxiosRequestConfig<any>
|
||||||
|
) => {
|
||||||
|
const stream = await downloadContentFromMessage(blob, 'md-app-state', { options })
|
||||||
const bufferArray: Buffer[] = []
|
const bufferArray: Buffer[] = []
|
||||||
for await (const chunk of stream) {
|
for await (const chunk of stream) {
|
||||||
bufferArray.push(chunk)
|
bufferArray.push(chunk)
|
||||||
@@ -338,8 +345,11 @@ export const downloadExternalBlob = async(blob: proto.IExternalBlobReference) =>
|
|||||||
return Buffer.concat(bufferArray)
|
return Buffer.concat(bufferArray)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const downloadExternalPatch = async(blob: proto.IExternalBlobReference) => {
|
export const downloadExternalPatch = async(
|
||||||
const buffer = await downloadExternalBlob(blob)
|
blob: proto.IExternalBlobReference,
|
||||||
|
options: AxiosRequestConfig<any>
|
||||||
|
) => {
|
||||||
|
const buffer = await downloadExternalBlob(blob, options)
|
||||||
const syncData = proto.SyncdMutations.decode(buffer)
|
const syncData = proto.SyncdMutations.decode(buffer)
|
||||||
return syncData
|
return syncData
|
||||||
}
|
}
|
||||||
@@ -399,6 +409,7 @@ export const decodePatches = async(
|
|||||||
initial: LTHashState,
|
initial: LTHashState,
|
||||||
getAppStateSyncKey: FetchAppStateSyncKey,
|
getAppStateSyncKey: FetchAppStateSyncKey,
|
||||||
onMutation: (mut: ChatMutation) => void,
|
onMutation: (mut: ChatMutation) => void,
|
||||||
|
options: AxiosRequestConfig<any>,
|
||||||
minimumVersionNumber?: number,
|
minimumVersionNumber?: number,
|
||||||
logger?: Logger,
|
logger?: Logger,
|
||||||
validateMacs: boolean = true
|
validateMacs: boolean = true
|
||||||
@@ -416,7 +427,7 @@ export const decodePatches = async(
|
|||||||
const { version, keyId, snapshotMac } = syncd
|
const { version, keyId, snapshotMac } = syncd
|
||||||
if(syncd.externalMutations) {
|
if(syncd.externalMutations) {
|
||||||
logger?.trace({ name, version }, 'downloading external patch')
|
logger?.trace({ name, version }, 'downloading external patch')
|
||||||
const ref = await downloadExternalPatch(syncd.externalMutations)
|
const ref = await downloadExternalPatch(syncd.externalMutations, options)
|
||||||
logger?.debug({ name, version, mutations: ref.mutations.length }, 'downloaded external patch')
|
logger?.debug({ name, version, mutations: ref.mutations.length }, 'downloaded external patch')
|
||||||
syncd.mutations?.push(...ref.mutations)
|
syncd.mutations?.push(...ref.mutations)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { AxiosRequestConfig } from 'axios'
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
import { inflate } from 'zlib'
|
import { inflate } from 'zlib'
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
@@ -9,8 +10,11 @@ import { downloadContentFromMessage } from './messages-media'
|
|||||||
|
|
||||||
const inflatePromise = promisify(inflate)
|
const inflatePromise = promisify(inflate)
|
||||||
|
|
||||||
export const downloadHistory = async(msg: proto.Message.IHistorySyncNotification) => {
|
export const downloadHistory = async(
|
||||||
const stream = await downloadContentFromMessage(msg, 'md-msg-hist')
|
msg: proto.Message.IHistorySyncNotification,
|
||||||
|
options: AxiosRequestConfig<any>
|
||||||
|
) => {
|
||||||
|
const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options })
|
||||||
const bufferArray: Buffer[] = []
|
const bufferArray: Buffer[] = []
|
||||||
for await (const chunk of stream) {
|
for await (const chunk of stream) {
|
||||||
bufferArray.push(chunk)
|
bufferArray.push(chunk)
|
||||||
@@ -112,9 +116,10 @@ export const processHistoryMessage = (
|
|||||||
export const downloadAndProcessHistorySyncNotification = async(
|
export const downloadAndProcessHistorySyncNotification = async(
|
||||||
msg: proto.Message.IHistorySyncNotification,
|
msg: proto.Message.IHistorySyncNotification,
|
||||||
historyCache: Set<string>,
|
historyCache: Set<string>,
|
||||||
recvChats: InitialReceivedChatsState
|
recvChats: InitialReceivedChatsState,
|
||||||
|
options: AxiosRequestConfig<any>
|
||||||
) => {
|
) => {
|
||||||
const historyMsg = await downloadHistory(msg)
|
const historyMsg = await downloadHistory(msg, options)
|
||||||
return processHistoryMessage(historyMsg, historyCache, recvChats)
|
return processHistoryMessage(historyMsg, historyCache, recvChats)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { AxiosRequestConfig } from 'axios'
|
||||||
import type { Logger } from 'pino'
|
import type { Logger } from 'pino'
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { AuthenticationCreds, BaileysEventEmitter, Chat, GroupMetadata, InitialReceivedChatsState, ParticipantAction, SignalKeyStoreWithTransaction, WAMessageStubType } from '../Types'
|
import { AuthenticationCreds, BaileysEventEmitter, Chat, GroupMetadata, InitialReceivedChatsState, ParticipantAction, SignalKeyStoreWithTransaction, WAMessageStubType } from '../Types'
|
||||||
@@ -12,6 +13,7 @@ type ProcessMessageContext = {
|
|||||||
keyStore: SignalKeyStoreWithTransaction
|
keyStore: SignalKeyStoreWithTransaction
|
||||||
ev: BaileysEventEmitter
|
ev: BaileysEventEmitter
|
||||||
logger?: Logger
|
logger?: Logger
|
||||||
|
options: AxiosRequestConfig<any>
|
||||||
}
|
}
|
||||||
|
|
||||||
const MSG_MISSED_CALL_TYPES = new Set([
|
const MSG_MISSED_CALL_TYPES = new Set([
|
||||||
@@ -64,7 +66,7 @@ export const shouldIncrementChatUnread = (message: proto.IWebMessageInfo) => (
|
|||||||
|
|
||||||
const processMessage = async(
|
const processMessage = async(
|
||||||
message: proto.IWebMessageInfo,
|
message: proto.IWebMessageInfo,
|
||||||
{ downloadHistory, ev, historyCache, recvChats, creds, keyStore, logger }: ProcessMessageContext
|
{ downloadHistory, ev, historyCache, recvChats, creds, keyStore, logger, options }: ProcessMessageContext
|
||||||
) => {
|
) => {
|
||||||
const meId = creds.me!.id
|
const meId = creds.me!.id
|
||||||
const { accountSettings } = creds
|
const { accountSettings } = creds
|
||||||
@@ -95,7 +97,12 @@ const processMessage = async(
|
|||||||
|
|
||||||
if(downloadHistory) {
|
if(downloadHistory) {
|
||||||
const isLatest = !creds.processedHistoryMessages?.length
|
const isLatest = !creds.processedHistoryMessages?.length
|
||||||
const { chats, contacts, messages, didProcess } = await downloadAndProcessHistorySyncNotification(histNotification, historyCache, recvChats)
|
const { chats, contacts, messages, didProcess } = await downloadAndProcessHistorySyncNotification(
|
||||||
|
histNotification,
|
||||||
|
historyCache,
|
||||||
|
recvChats,
|
||||||
|
options
|
||||||
|
)
|
||||||
|
|
||||||
if(chats.length) {
|
if(chats.length) {
|
||||||
ev.emit('chats.set', { chats, isLatest })
|
ev.emit('chats.set', { chats, isLatest })
|
||||||
|
|||||||
Reference in New Issue
Block a user