mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
chore: update axios
This commit is contained in:
@@ -34,7 +34,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hapi/boom": "^9.1.3",
|
"@hapi/boom": "^9.1.3",
|
||||||
"axios": "^0.24.0",
|
"axios": "^1.3.3",
|
||||||
"futoin-hkdf": "^1.5.1",
|
"futoin-hkdf": "^1.5.1",
|
||||||
"libsignal": "git+https://github.com/adiwajshing/libsignal-node",
|
"libsignal": "git+https://github.com/adiwajshing/libsignal-node",
|
||||||
"music-metadata": "^7.12.3",
|
"music-metadata": "^7.12.3",
|
||||||
|
|||||||
@@ -53,7 +53,10 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
const mediaConnNode = getBinaryNodeChild(result, 'media_conn')
|
const mediaConnNode = getBinaryNodeChild(result, 'media_conn')
|
||||||
const node: MediaConnInfo = {
|
const node: MediaConnInfo = {
|
||||||
hosts: getBinaryNodeChildren(mediaConnNode, 'host').map(
|
hosts: getBinaryNodeChildren(mediaConnNode, 'host').map(
|
||||||
item => item.attrs as any
|
({ attrs }) => ({
|
||||||
|
hostname: attrs.hostname,
|
||||||
|
maxContentLengthBytes: +attrs.maxContentLengthBytes,
|
||||||
|
})
|
||||||
),
|
),
|
||||||
auth: mediaConnNode!.attrs.auth,
|
auth: mediaConnNode!.attrs.auth,
|
||||||
ttl: +mediaConnNode!.attrs.ttl,
|
ttl: +mediaConnNode!.attrs.ttl,
|
||||||
@@ -319,7 +322,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
// only send to the specific device that asked for a retry
|
// only send to the specific device that asked for a retry
|
||||||
// otherwise the message is sent out to every device that should be a recipient
|
// otherwise the message is sent out to every device that should be a recipient
|
||||||
if(!isGroup) {
|
if(!isGroup) {
|
||||||
additionalAttributes = { ...additionalAttributes, device_fanout: 'false' }
|
additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' }
|
||||||
}
|
}
|
||||||
|
|
||||||
const { user, device } = jidDecode(participant.jid)!
|
const { user, device } = jidDecode(participant.jid)!
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export const makeSocket = ({
|
|||||||
}: SocketConfig) => {
|
}: SocketConfig) => {
|
||||||
const ws = new WebSocket(waWebSocketUrl, undefined, {
|
const ws = new WebSocket(waWebSocketUrl, undefined, {
|
||||||
origin: DEFAULT_ORIGIN,
|
origin: DEFAULT_ORIGIN,
|
||||||
headers: options.headers,
|
headers: options.headers as {},
|
||||||
handshakeTimeout: connectTimeoutMs,
|
handshakeTimeout: connectTimeoutMs,
|
||||||
timeout: connectTimeoutMs,
|
timeout: connectTimeoutMs,
|
||||||
agent
|
agent
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { AxiosRequestConfig } from 'axios'
|
||||||
import { Logger } from 'pino'
|
import { Logger } from 'pino'
|
||||||
import { WAMediaUploadFunction, WAUrlInfo } from '../Types'
|
import { WAMediaUploadFunction, WAUrlInfo } from '../Types'
|
||||||
import { prepareWAMessageMedia } from './messages'
|
import { prepareWAMessageMedia } from './messages'
|
||||||
@@ -21,7 +22,7 @@ export type URLGenerationOptions = {
|
|||||||
/** Timeout in ms */
|
/** Timeout in ms */
|
||||||
timeout: number
|
timeout: number
|
||||||
proxyUrl?: string
|
proxyUrl?: string
|
||||||
headers?: { [key: string]: string }
|
headers?: AxiosRequestConfig<{}>['headers']
|
||||||
}
|
}
|
||||||
uploadImage?: WAMediaUploadFunction
|
uploadImage?: WAMediaUploadFunction
|
||||||
logger?: Logger
|
logger?: Logger
|
||||||
@@ -47,7 +48,10 @@ export const getUrlInfo = async(
|
|||||||
previewLink = 'https://' + previewLink
|
previewLink = 'https://' + previewLink
|
||||||
}
|
}
|
||||||
|
|
||||||
const info = await getLinkPreview(previewLink, opts.fetchOpts)
|
const info = await getLinkPreview(previewLink, {
|
||||||
|
...opts.fetchOpts,
|
||||||
|
headers: opts.fetchOpts as {}
|
||||||
|
})
|
||||||
if(info && 'title' in info && info.title) {
|
if(info && 'title' in info && info.title) {
|
||||||
const [image] = info.images
|
const [image] = info.images
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ 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 type { Logger } from 'pino'
|
||||||
import { Readable, Transform } from 'stream'
|
import { PassThrough, Readable, Transform } from 'stream'
|
||||||
import { URL } from 'url'
|
import { URL } from 'url'
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { DEFAULT_ORIGIN, MEDIA_HKDF_KEY_MAPPING, MEDIA_PATH_MAP } from '../Defaults'
|
import { DEFAULT_ORIGIN, MEDIA_HKDF_KEY_MAPPING, MEDIA_PATH_MAP } from '../Defaults'
|
||||||
@@ -192,8 +192,11 @@ export async function getAudioDuration(buffer: Buffer | string | Readable) {
|
|||||||
metadata = await musicMetadata.parseBuffer(buffer, undefined, { duration: true })
|
metadata = await musicMetadata.parseBuffer(buffer, undefined, { duration: true })
|
||||||
} else if(typeof buffer === 'string') {
|
} else if(typeof buffer === 'string') {
|
||||||
const rStream = createReadStream(buffer)
|
const rStream = createReadStream(buffer)
|
||||||
metadata = await musicMetadata.parseStream(rStream, undefined, { duration: true })
|
try {
|
||||||
rStream.close()
|
metadata = await musicMetadata.parseStream(rStream, undefined, { duration: true })
|
||||||
|
} finally {
|
||||||
|
rStream.destroy()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
metadata = await musicMetadata.parseStream(buffer, undefined, { duration: true })
|
metadata = await musicMetadata.parseStream(buffer, undefined, { duration: true })
|
||||||
}
|
}
|
||||||
@@ -209,29 +212,29 @@ export const toReadable = (buffer: Buffer) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const toBuffer = async(stream: Readable) => {
|
export const toBuffer = async(stream: Readable) => {
|
||||||
let buff = Buffer.alloc(0)
|
const chunks: Buffer[] = []
|
||||||
for await (const chunk of stream) {
|
for await (const chunk of stream) {
|
||||||
buff = Buffer.concat([ buff, chunk ])
|
chunks.push(chunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.destroy()
|
stream.destroy()
|
||||||
return buff
|
return Buffer.concat(chunks)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getStream = async(item: WAMediaUpload) => {
|
export const getStream = async(item: WAMediaUpload) => {
|
||||||
if(Buffer.isBuffer(item)) {
|
if(Buffer.isBuffer(item)) {
|
||||||
return { stream: toReadable(item), type: 'buffer' }
|
return { stream: toReadable(item), type: 'buffer' } as const
|
||||||
}
|
}
|
||||||
|
|
||||||
if('stream' in item) {
|
if('stream' in item) {
|
||||||
return { stream: item.stream, type: 'readable' }
|
return { stream: item.stream, type: 'readable' } as const
|
||||||
}
|
}
|
||||||
|
|
||||||
if(item.url.toString().startsWith('http://') || item.url.toString().startsWith('https://')) {
|
if(item.url.toString().startsWith('http://') || item.url.toString().startsWith('https://')) {
|
||||||
return { stream: await getHttpStream(item.url), type: 'remote' }
|
return { stream: await getHttpStream(item.url), type: 'remote' } as const
|
||||||
}
|
}
|
||||||
|
|
||||||
return { stream: createReadStream(item.url), type: 'file' }
|
return { stream: createReadStream(item.url), type: 'file' } as const
|
||||||
}
|
}
|
||||||
|
|
||||||
/** generates a thumbnail for a given media, if required */
|
/** generates a thumbnail for a given media, if required */
|
||||||
@@ -243,7 +246,7 @@ export async function generateThumbnail(
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
let thumbnail: string | undefined
|
let thumbnail: string | undefined
|
||||||
let originalImageDimensions: { width: number; height: number } | undefined
|
let originalImageDimensions: { width: number, height: number } | undefined
|
||||||
if(mediaType === 'image') {
|
if(mediaType === 'image') {
|
||||||
const { buffer, original } = await extractImageThumb(file)
|
const { buffer, original } = await extractImageThumb(file)
|
||||||
thumbnail = buffer.toString('base64')
|
thumbnail = buffer.toString('base64')
|
||||||
@@ -290,9 +293,6 @@ export const encryptedStream = async(
|
|||||||
|
|
||||||
const mediaKey = Crypto.randomBytes(32)
|
const mediaKey = Crypto.randomBytes(32)
|
||||||
const { cipherKey, iv, macKey } = getMediaKeys(mediaKey, mediaType)
|
const { cipherKey, iv, macKey } = getMediaKeys(mediaKey, mediaType)
|
||||||
// random name
|
|
||||||
//const encBodyPath = join(getTmpFilesDirectory(), mediaType + generateMessageID() + '.enc')
|
|
||||||
// const encWriteStream = createWriteStream(encBodyPath)
|
|
||||||
const encWriteStream = new Readable({ read: () => {} })
|
const encWriteStream = new Readable({ read: () => {} })
|
||||||
|
|
||||||
let bodyPath: string | undefined
|
let bodyPath: string | undefined
|
||||||
@@ -312,12 +312,6 @@ export const encryptedStream = async(
|
|||||||
let sha256Plain = Crypto.createHash('sha256')
|
let sha256Plain = Crypto.createHash('sha256')
|
||||||
let sha256Enc = Crypto.createHash('sha256')
|
let sha256Enc = Crypto.createHash('sha256')
|
||||||
|
|
||||||
const onChunk = (buff: Buffer) => {
|
|
||||||
sha256Enc = sha256Enc.update(buff)
|
|
||||||
hmac = hmac.update(buff)
|
|
||||||
encWriteStream.push(buff)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for await (const data of stream) {
|
for await (const data of stream) {
|
||||||
fileLength += data.length
|
fileLength += data.length
|
||||||
@@ -342,7 +336,7 @@ export const encryptedStream = async(
|
|||||||
encWriteStream.push(mac)
|
encWriteStream.push(mac)
|
||||||
encWriteStream.push(null)
|
encWriteStream.push(null)
|
||||||
|
|
||||||
writeStream && writeStream.end()
|
writeStream?.end()
|
||||||
stream.destroy()
|
stream.destroy()
|
||||||
|
|
||||||
logger?.debug('encrypted data successfully')
|
logger?.debug('encrypted data successfully')
|
||||||
@@ -368,6 +362,12 @@ export const encryptedStream = async(
|
|||||||
|
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onChunk(buff: Buffer) {
|
||||||
|
sha256Enc = sha256Enc.update(buff)
|
||||||
|
hmac = hmac.update(buff)
|
||||||
|
encWriteStream.push(buff)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEF_HOST = 'mmg.whatsapp.net'
|
const DEF_HOST = 'mmg.whatsapp.net'
|
||||||
@@ -421,14 +421,14 @@ export const downloadEncryptedContent = async(
|
|||||||
|
|
||||||
const endChunk = endByte ? toSmallestChunkSize(endByte || 0) + AES_CHUNK_SIZE : undefined
|
const endChunk = endByte ? toSmallestChunkSize(endByte || 0) + AES_CHUNK_SIZE : undefined
|
||||||
|
|
||||||
const headers: { [_: string]: string } = {
|
const headers: AxiosRequestConfig['headers'] = {
|
||||||
...options?.headers || { },
|
...options?.headers || { },
|
||||||
Origin: DEFAULT_ORIGIN,
|
Origin: DEFAULT_ORIGIN,
|
||||||
}
|
}
|
||||||
if(startChunk || endChunk) {
|
if(startChunk || endChunk) {
|
||||||
headers.Range = `bytes=${startChunk}-`
|
headers!.Range = `bytes=${startChunk}-`
|
||||||
if(endChunk) {
|
if(endChunk) {
|
||||||
headers.Range += endChunk
|
headers!.Range += endChunk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user