mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
chore: pass axios options to downloading remote media
This commit is contained in:
@@ -639,6 +639,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
),
|
||||
upload: waUploadToServer,
|
||||
mediaCache: config.mediaCache,
|
||||
options: config.options,
|
||||
...options,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { AxiosRequestConfig } from 'axios'
|
||||
import type NodeCache from 'node-cache'
|
||||
import type { Logger } from 'pino'
|
||||
import type { Readable } from 'stream'
|
||||
@@ -204,6 +205,8 @@ export type MediaGenerationOptions = {
|
||||
mediaCache?: NodeCache
|
||||
|
||||
mediaUploadTimeoutMs?: number
|
||||
|
||||
options?: AxiosRequestConfig
|
||||
}
|
||||
export type MessageContentGenerationOptions = MediaGenerationOptions & {
|
||||
getUrlInfo?: (text: string) => Promise<WAUrlInfo | undefined>
|
||||
|
||||
@@ -66,7 +66,11 @@ export const getUrlInfo = async(
|
||||
if(opts.uploadImage) {
|
||||
const { imageMessage } = await prepareWAMessageMedia(
|
||||
{ image: { url: image } },
|
||||
{ upload: opts.uploadImage, mediaTypeOverride: 'thumbnail-link' }
|
||||
{
|
||||
upload: opts.uploadImage,
|
||||
mediaTypeOverride: 'thumbnail-link',
|
||||
options: opts.fetchOpts
|
||||
}
|
||||
)
|
||||
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail
|
||||
? Buffer.from(imageMessage.jpegThumbnail)
|
||||
|
||||
@@ -221,7 +221,7 @@ export const toBuffer = async(stream: Readable) => {
|
||||
return Buffer.concat(chunks)
|
||||
}
|
||||
|
||||
export const getStream = async(item: WAMediaUpload) => {
|
||||
export const getStream = async(item: WAMediaUpload, opts?: AxiosRequestConfig) => {
|
||||
if(Buffer.isBuffer(item)) {
|
||||
return { stream: toReadable(item), type: 'buffer' } as const
|
||||
}
|
||||
@@ -231,7 +231,7 @@ export const getStream = async(item: WAMediaUpload) => {
|
||||
}
|
||||
|
||||
if(item.url.toString().startsWith('http://') || item.url.toString().startsWith('https://')) {
|
||||
return { stream: await getHttpStream(item.url), type: 'remote' } as const
|
||||
return { stream: await getHttpStream(item.url, opts), type: 'remote' } as const
|
||||
}
|
||||
|
||||
return { stream: createReadStream(item.url), type: 'file' } as const
|
||||
@@ -281,13 +281,18 @@ export const getHttpStream = async(url: string | URL, options: AxiosRequestConfi
|
||||
return fetched.data as Readable
|
||||
}
|
||||
|
||||
type EncryptedStreamOptions = {
|
||||
saveOriginalFileIfRequired?: boolean
|
||||
logger?: Logger
|
||||
opts?: AxiosRequestConfig
|
||||
}
|
||||
|
||||
export const encryptedStream = async(
|
||||
media: WAMediaUpload,
|
||||
mediaType: MediaType,
|
||||
saveOriginalFileIfRequired = true,
|
||||
logger?: Logger
|
||||
{ logger, saveOriginalFileIfRequired, opts }: EncryptedStreamOptions = {}
|
||||
) => {
|
||||
const { stream, type } = await getStream(media)
|
||||
const { stream, type } = await getStream(media, opts)
|
||||
|
||||
logger?.debug('fetched media stream')
|
||||
|
||||
|
||||
@@ -149,7 +149,11 @@ export const prepareWAMessageMedia = async(
|
||||
} = await encryptedStream(
|
||||
uploadData.media,
|
||||
options.mediaTypeOverride || mediaType,
|
||||
requiresOriginalForSomeProcessing
|
||||
{
|
||||
logger,
|
||||
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
||||
opts: options.options
|
||||
}
|
||||
)
|
||||
// url safe Base64 encode the SHA256 hash of the body
|
||||
const fileEncSha256B64 = fileEncSha256.toString('base64')
|
||||
|
||||
Reference in New Issue
Block a user