mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Dependency Inversion for Logger (#1153)
* feat: interface "ILogger" created feat: interface "ILogger" used instead of pino logger feat: "PinoLoggerAdapter" created to implement "ILogger" interface * feat: PinoLoggerAdapter removed feat: ILogger mapping the features we're using from pino * fix: sort imports --------- Co-authored-by: Mateus Franchini de Freitas <contato.mateusfr@outlook.com> Co-authored-by: Mateus Franchini de Freitas <mfranchini@domtec.com.br> Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
This commit is contained in:
committed by
GitHub
parent
447e648958
commit
21f8431e61
@@ -866,7 +866,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(placeholderResendCache.get(messageKey?.id!)) {
|
if(placeholderResendCache.get(messageKey?.id!)) {
|
||||||
logger.debug('already requested resend', { messageKey })
|
logger.debug({ messageKey }, 'already requested resend')
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
placeholderResendCache.set(messageKey?.id!, true)
|
placeholderResendCache.set(messageKey?.id!, true)
|
||||||
@@ -875,7 +875,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
await delay(5000)
|
await delay(5000)
|
||||||
|
|
||||||
if(!placeholderResendCache.get(messageKey?.id!)) {
|
if(!placeholderResendCache.get(messageKey?.id!)) {
|
||||||
logger.debug('message received while resend requested', { messageKey })
|
logger.debug({ messageKey }, 'message received while resend requested')
|
||||||
return 'RESOLVED'
|
return 'RESOLVED'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -888,7 +888,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if(placeholderResendCache.get(messageKey?.id!)) {
|
if(placeholderResendCache.get(messageKey?.id!)) {
|
||||||
logger.debug('PDO message without response after 15 seconds. Phone possibly offline', { messageKey })
|
logger.debug({ messageKey }, 'PDO message without response after 15 seconds. Phone possibly offline')
|
||||||
placeholderResendCache.del(messageKey?.id!)
|
placeholderResendCache.del(messageKey?.id!)
|
||||||
}
|
}
|
||||||
}, 15_000)
|
}, 15_000)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import type KeyedDB from '@adiwajshing/keyed-db'
|
import type KeyedDB from '@adiwajshing/keyed-db'
|
||||||
import type { Comparable } from '@adiwajshing/keyed-db/lib/Types'
|
import type { Comparable } from '@adiwajshing/keyed-db/lib/Types'
|
||||||
import type { Logger } from 'pino'
|
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { DEFAULT_CONNECTION_CONFIG } from '../Defaults'
|
import { DEFAULT_CONNECTION_CONFIG } from '../Defaults'
|
||||||
import type makeMDSocket from '../Socket'
|
import type makeMDSocket from '../Socket'
|
||||||
@@ -8,6 +7,7 @@ import type { BaileysEventEmitter, Chat, ConnectionState, Contact, GroupMetadata
|
|||||||
import { Label } from '../Types/Label'
|
import { Label } from '../Types/Label'
|
||||||
import { LabelAssociation, LabelAssociationType, MessageLabelAssociation } from '../Types/LabelAssociation'
|
import { LabelAssociation, LabelAssociationType, MessageLabelAssociation } from '../Types/LabelAssociation'
|
||||||
import { md5, toNumber, updateMessageWithReaction, updateMessageWithReceipt } from '../Utils'
|
import { md5, toNumber, updateMessageWithReaction, updateMessageWithReceipt } from '../Utils'
|
||||||
|
import { ILogger } from '../Utils/logger'
|
||||||
import { jidDecode, jidNormalizedUser } from '../WABinary'
|
import { jidDecode, jidNormalizedUser } from '../WABinary'
|
||||||
import makeOrderedDictionary from './make-ordered-dictionary'
|
import makeOrderedDictionary from './make-ordered-dictionary'
|
||||||
import { ObjectRepository } from './object-repository'
|
import { ObjectRepository } from './object-repository'
|
||||||
@@ -29,7 +29,7 @@ export const waLabelAssociationKey: Comparable<LabelAssociation, string> = {
|
|||||||
export type BaileysInMemoryStoreConfig = {
|
export type BaileysInMemoryStoreConfig = {
|
||||||
chatKey?: Comparable<Chat, string>
|
chatKey?: Comparable<Chat, string>
|
||||||
labelAssociationKey?: Comparable<LabelAssociation, string>
|
labelAssociationKey?: Comparable<LabelAssociation, string>
|
||||||
logger?: Logger
|
logger?: ILogger
|
||||||
socket?: WASocket
|
socket?: WASocket
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ export default (config: BaileysInMemoryStoreConfig) => {
|
|||||||
const socket = config.socket
|
const socket = config.socket
|
||||||
const chatKey = config.chatKey || waChatKey(true)
|
const chatKey = config.chatKey || waChatKey(true)
|
||||||
const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey
|
const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey
|
||||||
const logger: Logger = config.logger || DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' })
|
const logger: ILogger = config.logger || DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' })
|
||||||
const KeyedDB = require('@adiwajshing/keyed-db').default
|
const KeyedDB = require('@adiwajshing/keyed-db').default
|
||||||
|
|
||||||
const chats = new KeyedDB(chatKey, c => c.id) as KeyedDB<Chat, string>
|
const chats = new KeyedDB(chatKey, c => c.id) as KeyedDB<Chat, string>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { AxiosRequestConfig } from 'axios'
|
import { AxiosRequestConfig } from 'axios'
|
||||||
import type { Logger } from 'pino'
|
|
||||||
import type { Readable } from 'stream'
|
import type { Readable } from 'stream'
|
||||||
import type { URL } from 'url'
|
import type { URL } from 'url'
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
@@ -23,6 +22,7 @@ export type WAGenericMediaMessage = proto.Message.IVideoMessage | proto.Message.
|
|||||||
export import WAMessageStubType = proto.WebMessageInfo.StubType
|
export import WAMessageStubType = proto.WebMessageInfo.StubType
|
||||||
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
||||||
export import WAMessageStatus = proto.WebMessageInfo.Status
|
export import WAMessageStatus = proto.WebMessageInfo.Status
|
||||||
|
import { ILogger } from '../Utils/logger'
|
||||||
export type WAMediaPayloadURL = { url: URL | string }
|
export type WAMediaPayloadURL = { url: URL | string }
|
||||||
export type WAMediaPayloadStream = { stream: Readable }
|
export type WAMediaPayloadStream = { stream: Readable }
|
||||||
export type WAMediaUpload = Buffer | WAMediaPayloadStream | WAMediaPayloadURL
|
export type WAMediaUpload = Buffer | WAMediaPayloadStream | WAMediaPayloadURL
|
||||||
@@ -241,7 +241,7 @@ export type MessageGenerationOptionsFromContent = MiscMessageGenerationOptions &
|
|||||||
export type WAMediaUploadFunction = (readStream: Readable, opts: { fileEncSha256B64: string, mediaType: MediaType, timeoutMs?: number }) => Promise<{ mediaUrl: string, directPath: string }>
|
export type WAMediaUploadFunction = (readStream: Readable, opts: { fileEncSha256B64: string, mediaType: MediaType, timeoutMs?: number }) => Promise<{ mediaUrl: string, directPath: string }>
|
||||||
|
|
||||||
export type MediaGenerationOptions = {
|
export type MediaGenerationOptions = {
|
||||||
logger?: Logger
|
logger?: ILogger
|
||||||
mediaTypeOverride?: MediaType
|
mediaTypeOverride?: MediaType
|
||||||
upload: WAMediaUploadFunction
|
upload: WAMediaUploadFunction
|
||||||
/** cache media so it does not have to be uploaded again */
|
/** cache media so it does not have to be uploaded again */
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
import { AxiosRequestConfig } from 'axios'
|
import { AxiosRequestConfig } from 'axios'
|
||||||
import type { Agent } from 'https'
|
import type { Agent } from 'https'
|
||||||
import type { Logger } from 'pino'
|
|
||||||
import type { URL } from 'url'
|
import type { URL } from 'url'
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
|
import { ILogger } from '../Utils/logger'
|
||||||
import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth'
|
import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth'
|
||||||
import { GroupMetadata } from './GroupMetadata'
|
import { GroupMetadata } from './GroupMetadata'
|
||||||
import { MediaConnInfo } from './Message'
|
import { MediaConnInfo } from './Message'
|
||||||
@@ -38,8 +38,8 @@ export type SocketConfig = {
|
|||||||
mobile?: boolean
|
mobile?: boolean
|
||||||
/** proxy agent */
|
/** proxy agent */
|
||||||
agent?: Agent
|
agent?: Agent
|
||||||
/** pino logger */
|
/** logger */
|
||||||
logger: Logger
|
logger: ILogger
|
||||||
/** version to connect with */
|
/** version to connect with */
|
||||||
version: WAVersion
|
version: WAVersion
|
||||||
/** override browser config */
|
/** override browser config */
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { DEFAULT_CACHE_TTLS } from '../Defaults'
|
|||||||
import type { AuthenticationCreds, CacheStore, SignalDataSet, SignalDataTypeMap, SignalKeyStore, SignalKeyStoreWithTransaction, TransactionCapabilityOptions } from '../Types'
|
import type { AuthenticationCreds, CacheStore, SignalDataSet, SignalDataTypeMap, SignalKeyStore, SignalKeyStoreWithTransaction, TransactionCapabilityOptions } from '../Types'
|
||||||
import { Curve, signedKeyPair } from './crypto'
|
import { Curve, signedKeyPair } from './crypto'
|
||||||
import { delay, generateRegistrationId } from './generics'
|
import { delay, generateRegistrationId } from './generics'
|
||||||
|
import { ILogger } from './logger'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds caching capability to a SignalKeyStore
|
* Adds caching capability to a SignalKeyStore
|
||||||
@@ -14,7 +15,7 @@ import { delay, generateRegistrationId } from './generics'
|
|||||||
*/
|
*/
|
||||||
export function makeCacheableSignalKeyStore(
|
export function makeCacheableSignalKeyStore(
|
||||||
store: SignalKeyStore,
|
store: SignalKeyStore,
|
||||||
logger: Logger,
|
logger: ILogger,
|
||||||
_cache?: CacheStore
|
_cache?: CacheStore
|
||||||
): SignalKeyStore {
|
): SignalKeyStore {
|
||||||
const cache = _cache || new NodeCache({
|
const cache = _cache || new NodeCache({
|
||||||
@@ -83,7 +84,7 @@ export function makeCacheableSignalKeyStore(
|
|||||||
*/
|
*/
|
||||||
export const addTransactionCapability = (
|
export const addTransactionCapability = (
|
||||||
state: SignalKeyStore,
|
state: SignalKeyStore,
|
||||||
logger: Logger,
|
logger: ILogger,
|
||||||
{ maxCommitRetries, delayBetweenTriesMs }: TransactionCapabilityOptions
|
{ maxCommitRetries, delayBetweenTriesMs }: TransactionCapabilityOptions
|
||||||
): SignalKeyStoreWithTransaction => {
|
): SignalKeyStoreWithTransaction => {
|
||||||
// number of queries made to the DB during the transaction
|
// number of queries made to the DB during the transaction
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Boom } from '@hapi/boom'
|
import { Boom } from '@hapi/boom'
|
||||||
import { AxiosRequestConfig } from 'axios'
|
import { AxiosRequestConfig } from 'axios'
|
||||||
import type { Logger } from 'pino'
|
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { BaileysEventEmitter, Chat, ChatModification, ChatMutation, ChatUpdate, Contact, InitialAppStateSyncOptions, LastMessageList, LTHashState, WAPatchCreate, WAPatchName } from '../Types'
|
import { BaileysEventEmitter, Chat, ChatModification, ChatMutation, ChatUpdate, Contact, InitialAppStateSyncOptions, LastMessageList, LTHashState, WAPatchCreate, WAPatchName } from '../Types'
|
||||||
import { ChatLabelAssociation, LabelAssociationType, MessageLabelAssociation } from '../Types/LabelAssociation'
|
import { ChatLabelAssociation, LabelAssociationType, MessageLabelAssociation } from '../Types/LabelAssociation'
|
||||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, jidNormalizedUser } from '../WABinary'
|
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, jidNormalizedUser } from '../WABinary'
|
||||||
import { aesDecrypt, aesEncrypt, hkdf, hmacSign } from './crypto'
|
import { aesDecrypt, aesEncrypt, hkdf, hmacSign } from './crypto'
|
||||||
import { toNumber } from './generics'
|
import { toNumber } from './generics'
|
||||||
|
import { ILogger } from './logger'
|
||||||
import { LT_HASH_ANTI_TAMPERING } from './lt-hash'
|
import { LT_HASH_ANTI_TAMPERING } from './lt-hash'
|
||||||
import { downloadContentFromMessage, } from './messages-media'
|
import { downloadContentFromMessage, } from './messages-media'
|
||||||
|
|
||||||
@@ -410,7 +410,7 @@ export const decodePatches = async(
|
|||||||
getAppStateSyncKey: FetchAppStateSyncKey,
|
getAppStateSyncKey: FetchAppStateSyncKey,
|
||||||
options: AxiosRequestConfig<{}>,
|
options: AxiosRequestConfig<{}>,
|
||||||
minimumVersionNumber?: number,
|
minimumVersionNumber?: number,
|
||||||
logger?: Logger,
|
logger?: ILogger,
|
||||||
validateMacs = true
|
validateMacs = true
|
||||||
) => {
|
) => {
|
||||||
const newState: LTHashState = {
|
const newState: LTHashState = {
|
||||||
@@ -716,7 +716,7 @@ export const processSyncAction = (
|
|||||||
ev: BaileysEventEmitter,
|
ev: BaileysEventEmitter,
|
||||||
me: Contact,
|
me: Contact,
|
||||||
initialSyncOpts?: InitialAppStateSyncOptions,
|
initialSyncOpts?: InitialAppStateSyncOptions,
|
||||||
logger?: Logger,
|
logger?: ILogger,
|
||||||
) => {
|
) => {
|
||||||
const isInitialSync = !!initialSyncOpts
|
const isInitialSync = !!initialSyncOpts
|
||||||
const accountSettings = initialSyncOpts?.accountSettings
|
const accountSettings = initialSyncOpts?.accountSettings
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { Boom } from '@hapi/boom'
|
import { Boom } from '@hapi/boom'
|
||||||
import { Logger } from 'pino'
|
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { SignalRepository, WAMessageKey } from '../Types'
|
import { SignalRepository, WAMessageKey } from '../Types'
|
||||||
import { areJidsSameUser, BinaryNode, isJidBroadcast, isJidGroup, isJidNewsletter, isJidStatusBroadcast, isJidUser, isLidUser } from '../WABinary'
|
import { areJidsSameUser, BinaryNode, isJidBroadcast, isJidGroup, isJidNewsletter, isJidStatusBroadcast, isJidUser, isLidUser } from '../WABinary'
|
||||||
import { unpadRandomMax16 } from './generics'
|
import { unpadRandomMax16 } from './generics'
|
||||||
|
import { ILogger } from './logger'
|
||||||
|
|
||||||
export const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node'
|
export const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node'
|
||||||
export const MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled'
|
export const MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled'
|
||||||
@@ -136,7 +136,7 @@ export const decryptMessageNode = (
|
|||||||
meId: string,
|
meId: string,
|
||||||
meLid: string,
|
meLid: string,
|
||||||
repository: SignalRepository,
|
repository: SignalRepository,
|
||||||
logger: Logger
|
logger: ILogger
|
||||||
) => {
|
) => {
|
||||||
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid)
|
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid)
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import EventEmitter from 'events'
|
import EventEmitter from 'events'
|
||||||
import { Logger } from 'pino'
|
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { BaileysEvent, BaileysEventEmitter, BaileysEventMap, BufferedEventData, Chat, ChatUpdate, Contact, WAMessage, WAMessageStatus } from '../Types'
|
import { BaileysEvent, BaileysEventEmitter, BaileysEventMap, BufferedEventData, Chat, ChatUpdate, Contact, WAMessage, WAMessageStatus } from '../Types'
|
||||||
import { trimUndefined } from './generics'
|
import { trimUndefined } from './generics'
|
||||||
|
import { ILogger } from './logger'
|
||||||
import { updateMessageWithReaction, updateMessageWithReceipt } from './messages'
|
import { updateMessageWithReaction, updateMessageWithReceipt } from './messages'
|
||||||
import { isRealMessage, shouldIncrementChatUnread } from './process-message'
|
import { isRealMessage, shouldIncrementChatUnread } from './process-message'
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ type BaileysBufferableEventEmitter = BaileysEventEmitter & {
|
|||||||
* making the data processing more efficient.
|
* making the data processing more efficient.
|
||||||
* @param ev the baileys event emitter
|
* @param ev the baileys event emitter
|
||||||
*/
|
*/
|
||||||
export const makeEventBuffer = (logger: Logger): BaileysBufferableEventEmitter => {
|
export const makeEventBuffer = (logger: ILogger): BaileysBufferableEventEmitter => {
|
||||||
const ev = new EventEmitter()
|
const ev = new EventEmitter()
|
||||||
const historyCache = new Set<string>()
|
const historyCache = new Set<string>()
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ function append<E extends BufferableEvent>(
|
|||||||
event: E,
|
event: E,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
eventData: any,
|
eventData: any,
|
||||||
logger: Logger
|
logger: ILogger
|
||||||
) {
|
) {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case 'messaging-history.set':
|
case 'messaging-history.set':
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ import { Boom } from '@hapi/boom'
|
|||||||
import axios, { AxiosRequestConfig } from 'axios'
|
import axios, { AxiosRequestConfig } from 'axios'
|
||||||
import { createHash, randomBytes } from 'crypto'
|
import { createHash, randomBytes } from 'crypto'
|
||||||
import { platform, release } from 'os'
|
import { platform, release } from 'os'
|
||||||
import { Logger } from 'pino'
|
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { version as baileysVersion } from '../Defaults/baileys-version.json'
|
import { version as baileysVersion } from '../Defaults/baileys-version.json'
|
||||||
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, DisconnectReason, WACallUpdateType, WAVersion } from '../Types'
|
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, DisconnectReason, WACallUpdateType, WAVersion } from '../Types'
|
||||||
import { BinaryNode, getAllBinaryNodeChildren, jidDecode } from '../WABinary'
|
import { BinaryNode, getAllBinaryNodeChildren, jidDecode } from '../WABinary'
|
||||||
|
import { ILogger } from './logger'
|
||||||
|
|
||||||
const PLATFORM_MAP = {
|
const PLATFORM_MAP = {
|
||||||
'aix': 'AIX',
|
'aix': 'AIX',
|
||||||
@@ -242,7 +242,7 @@ export function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEve
|
|||||||
|
|
||||||
export const bindWaitForConnectionUpdate = (ev: BaileysEventEmitter) => bindWaitForEvent(ev, 'connection.update')
|
export const bindWaitForConnectionUpdate = (ev: BaileysEventEmitter) => bindWaitForEvent(ev, 'connection.update')
|
||||||
|
|
||||||
export const printQRIfNecessaryListener = (ev: BaileysEventEmitter, logger: Logger) => {
|
export const printQRIfNecessaryListener = (ev: BaileysEventEmitter, logger: ILogger) => {
|
||||||
ev.on('connection.update', async({ qr }) => {
|
ev.on('connection.update', async({ qr }) => {
|
||||||
if(qr) {
|
if(qr) {
|
||||||
const QR = await import('qrcode-terminal')
|
const QR = await import('qrcode-terminal')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { AxiosRequestConfig } from 'axios'
|
import { AxiosRequestConfig } from 'axios'
|
||||||
import { Logger } from 'pino'
|
|
||||||
import { WAMediaUploadFunction, WAUrlInfo } from '../Types'
|
import { WAMediaUploadFunction, WAUrlInfo } from '../Types'
|
||||||
|
import { ILogger } from './logger'
|
||||||
import { prepareWAMessageMedia } from './messages'
|
import { prepareWAMessageMedia } from './messages'
|
||||||
import { extractImageThumb, getHttpStream } from './messages-media'
|
import { extractImageThumb, getHttpStream } from './messages-media'
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ export type URLGenerationOptions = {
|
|||||||
headers?: AxiosRequestConfig<{}>['headers']
|
headers?: AxiosRequestConfig<{}>['headers']
|
||||||
}
|
}
|
||||||
uploadImage?: WAMediaUploadFunction
|
uploadImage?: WAMediaUploadFunction
|
||||||
logger?: Logger
|
logger?: ILogger
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,3 +1,13 @@
|
|||||||
import P from 'pino'
|
import P from 'pino'
|
||||||
|
|
||||||
|
export interface ILogger {
|
||||||
|
level: string
|
||||||
|
child(obj: Record<string, unknown>): ILogger
|
||||||
|
trace(obj: unknown, msg?: string)
|
||||||
|
debug(obj: unknown, msg?: string)
|
||||||
|
info(obj: unknown, msg?: string)
|
||||||
|
warn(obj: unknown, msg?: string)
|
||||||
|
error(obj: unknown, msg?: string)
|
||||||
|
}
|
||||||
|
|
||||||
export default P({ timestamp: () => `,"time":"${new Date().toJSON()}"` })
|
export default P({ timestamp: () => `,"time":"${new Date().toJSON()}"` })
|
||||||
@@ -7,7 +7,6 @@ import { createReadStream, createWriteStream, promises as fs, WriteStream } from
|
|||||||
import type { IAudioMetadata } from 'music-metadata'
|
import type { IAudioMetadata } from 'music-metadata'
|
||||||
import { tmpdir } from 'os'
|
import { tmpdir } from 'os'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import type { Logger } from 'pino'
|
|
||||||
import { Readable, Transform } from 'stream'
|
import { Readable, Transform } from 'stream'
|
||||||
import { URL } from 'url'
|
import { URL } from 'url'
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
@@ -16,6 +15,7 @@ import { BaileysEventMap, DownloadableMessage, MediaConnInfo, MediaDecryptionKey
|
|||||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildBuffer, jidNormalizedUser } from '../WABinary'
|
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildBuffer, jidNormalizedUser } from '../WABinary'
|
||||||
import { aesDecryptGCM, aesEncryptGCM, hkdf } from './crypto'
|
import { aesDecryptGCM, aesEncryptGCM, hkdf } from './crypto'
|
||||||
import { generateMessageID } from './generics'
|
import { generateMessageID } from './generics'
|
||||||
|
import { ILogger } from './logger'
|
||||||
|
|
||||||
const getTmpFilesDirectory = () => tmpdir()
|
const getTmpFilesDirectory = () => tmpdir()
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ export async function getAudioDuration(buffer: Buffer | string | Readable) {
|
|||||||
/**
|
/**
|
||||||
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
||||||
*/
|
*/
|
||||||
export async function getAudioWaveform(buffer: Buffer | string | Readable, logger?: Logger) {
|
export async function getAudioWaveform(buffer: Buffer | string | Readable, logger?: ILogger) {
|
||||||
try {
|
try {
|
||||||
const { default: decoder } = await eval('import(\'audio-decode\')')
|
const { default: decoder } = await eval('import(\'audio-decode\')')
|
||||||
let audioData: Buffer
|
let audioData: Buffer
|
||||||
@@ -290,7 +290,7 @@ export async function generateThumbnail(
|
|||||||
file: string,
|
file: string,
|
||||||
mediaType: 'video' | 'image',
|
mediaType: 'video' | 'image',
|
||||||
options: {
|
options: {
|
||||||
logger?: Logger
|
logger?: ILogger
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
let thumbnail: string | undefined
|
let thumbnail: string | undefined
|
||||||
@@ -330,7 +330,7 @@ export const getHttpStream = async(url: string | URL, options: AxiosRequestConfi
|
|||||||
|
|
||||||
type EncryptedStreamOptions = {
|
type EncryptedStreamOptions = {
|
||||||
saveOriginalFileIfRequired?: boolean
|
saveOriginalFileIfRequired?: boolean
|
||||||
logger?: Logger
|
logger?: ILogger
|
||||||
opts?: AxiosRequestConfig
|
opts?: AxiosRequestConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { Boom } from '@hapi/boom'
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { randomBytes } from 'crypto'
|
import { randomBytes } from 'crypto'
|
||||||
import { promises as fs } from 'fs'
|
import { promises as fs } from 'fs'
|
||||||
import { Logger } from 'pino'
|
|
||||||
import { type Transform } from 'stream'
|
import { type Transform } from 'stream'
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { MEDIA_KEYS, URL_REGEX, WA_DEFAULT_EPHEMERAL } from '../Defaults'
|
import { MEDIA_KEYS, URL_REGEX, WA_DEFAULT_EPHEMERAL } from '../Defaults'
|
||||||
@@ -27,6 +26,7 @@ import {
|
|||||||
import { isJidGroup, isJidStatusBroadcast, jidNormalizedUser } from '../WABinary'
|
import { isJidGroup, isJidStatusBroadcast, jidNormalizedUser } from '../WABinary'
|
||||||
import { sha256 } from './crypto'
|
import { sha256 } from './crypto'
|
||||||
import { generateMessageID, getKeyAuthor, unixTimestampSeconds } from './generics'
|
import { generateMessageID, getKeyAuthor, unixTimestampSeconds } from './generics'
|
||||||
|
import { ILogger } from './logger'
|
||||||
import { downloadContentFromMessage, encryptedStream, generateThumbnail, getAudioDuration, getAudioWaveform, MediaDownloadOptions } from './messages-media'
|
import { downloadContentFromMessage, encryptedStream, generateThumbnail, getAudioDuration, getAudioWaveform, MediaDownloadOptions } from './messages-media'
|
||||||
|
|
||||||
type MediaUploadData = {
|
type MediaUploadData = {
|
||||||
@@ -847,7 +847,7 @@ export const aggregateMessageKeysNotFromMe = (keys: proto.IMessageKey[]) => {
|
|||||||
|
|
||||||
type DownloadMediaMessageContext = {
|
type DownloadMediaMessageContext = {
|
||||||
reuploadRequest: (msg: WAMessage) => Promise<WAMessage>
|
reuploadRequest: (msg: WAMessage) => Promise<WAMessage>
|
||||||
logger: Logger
|
logger: ILogger
|
||||||
}
|
}
|
||||||
|
|
||||||
const REUPLOAD_REQUIRED_STATUS = [410, 404]
|
const REUPLOAD_REQUIRED_STATUS = [410, 404]
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { Boom } from '@hapi/boom'
|
import { Boom } from '@hapi/boom'
|
||||||
import { Logger } from 'pino'
|
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { NOISE_MODE, WA_CERT_DETAILS } from '../Defaults'
|
import { NOISE_MODE, WA_CERT_DETAILS } from '../Defaults'
|
||||||
import { KeyPair } from '../Types'
|
import { KeyPair } from '../Types'
|
||||||
import { BinaryNode, decodeBinaryNode } from '../WABinary'
|
import { BinaryNode, decodeBinaryNode } from '../WABinary'
|
||||||
import { aesDecryptGCM, aesEncryptGCM, Curve, hkdf, sha256 } from './crypto'
|
import { aesDecryptGCM, aesEncryptGCM, Curve, hkdf, sha256 } from './crypto'
|
||||||
|
import { ILogger } from './logger'
|
||||||
|
|
||||||
const generateIV = (counter: number) => {
|
const generateIV = (counter: number) => {
|
||||||
const iv = new ArrayBuffer(12)
|
const iv = new ArrayBuffer(12)
|
||||||
@@ -21,7 +21,7 @@ export const makeNoiseHandler = ({
|
|||||||
}: {
|
}: {
|
||||||
keyPair: KeyPair
|
keyPair: KeyPair
|
||||||
NOISE_HEADER: Uint8Array
|
NOISE_HEADER: Uint8Array
|
||||||
logger: Logger
|
logger: ILogger
|
||||||
routingInfo?: Buffer | undefined
|
routingInfo?: Buffer | undefined
|
||||||
}) => {
|
}) => {
|
||||||
logger = logger.child({ class: 'ns' })
|
logger = logger.child({ class: 'ns' })
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { AxiosRequestConfig } from 'axios'
|
import { AxiosRequestConfig } from 'axios'
|
||||||
import type { Logger } from 'pino'
|
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { AuthenticationCreds, BaileysEventEmitter, CacheStore, Chat, GroupMetadata, ParticipantAction, RequestJoinAction, RequestJoinMethod, SignalKeyStoreWithTransaction, SocketConfig, WAMessageStubType } from '../Types'
|
import { AuthenticationCreds, BaileysEventEmitter, CacheStore, Chat, GroupMetadata, ParticipantAction, RequestJoinAction, RequestJoinMethod, SignalKeyStoreWithTransaction, SocketConfig, WAMessageStubType } from '../Types'
|
||||||
import { getContentType, normalizeMessageContent } from '../Utils/messages'
|
import { getContentType, normalizeMessageContent } from '../Utils/messages'
|
||||||
@@ -7,6 +6,7 @@ import { areJidsSameUser, isJidBroadcast, isJidStatusBroadcast, jidNormalizedUse
|
|||||||
import { aesDecryptGCM, hmacSign } from './crypto'
|
import { aesDecryptGCM, hmacSign } from './crypto'
|
||||||
import { getKeyAuthor, toNumber } from './generics'
|
import { getKeyAuthor, toNumber } from './generics'
|
||||||
import { downloadAndProcessHistorySyncNotification } from './history'
|
import { downloadAndProcessHistorySyncNotification } from './history'
|
||||||
|
import { ILogger } from './logger'
|
||||||
|
|
||||||
type ProcessMessageContext = {
|
type ProcessMessageContext = {
|
||||||
shouldProcessHistoryMsg: boolean
|
shouldProcessHistoryMsg: boolean
|
||||||
@@ -15,7 +15,7 @@ type ProcessMessageContext = {
|
|||||||
keyStore: SignalKeyStoreWithTransaction
|
keyStore: SignalKeyStoreWithTransaction
|
||||||
ev: BaileysEventEmitter
|
ev: BaileysEventEmitter
|
||||||
getMessage: SocketConfig['getMessage']
|
getMessage: SocketConfig['getMessage']
|
||||||
logger?: Logger
|
logger?: ILogger
|
||||||
options: AxiosRequestConfig<{}>
|
options: AxiosRequestConfig<{}>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user