mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: downloadMediaMessage return type matched parameter (#757)
* fix: downloadMediaMessage return type matched parameter * chore: keyword-spacing eslint rule warn instead of error * chore: linting aaaaaaaaaaaaaaaaaaaa
This commit is contained in:
@@ -27,6 +27,9 @@
|
||||
"selector": "TSEnumDeclaration",
|
||||
"message": "Don't declare enums, use literals instead"
|
||||
}
|
||||
],
|
||||
"keyword-spacing": [
|
||||
"warn"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import axios from 'axios'
|
||||
import { randomBytes } from 'crypto'
|
||||
import { promises as fs } from 'fs'
|
||||
import { Logger } from 'pino'
|
||||
import { type Transform } from 'stream'
|
||||
import { proto } from '../../WAProto'
|
||||
import { MEDIA_KEYS, URL_REGEX, WA_DEFAULT_EPHEMERAL } from '../Defaults'
|
||||
import {
|
||||
@@ -868,31 +869,31 @@ const REUPLOAD_REQUIRED_STATUS = [410, 404]
|
||||
/**
|
||||
* Downloads the given message. Throws an error if it's not a media message
|
||||
*/
|
||||
export const downloadMediaMessage = async(
|
||||
export const downloadMediaMessage = async<Type extends 'buffer' | 'stream'>(
|
||||
message: WAMessage,
|
||||
type: 'buffer' | 'stream',
|
||||
type: Type,
|
||||
options: MediaDownloadOptions,
|
||||
ctx?: DownloadMediaMessageContext
|
||||
) => {
|
||||
try {
|
||||
const result = await downloadMsg()
|
||||
return result
|
||||
} catch(error) {
|
||||
if(ctx) {
|
||||
if(axios.isAxiosError(error)) {
|
||||
// check if the message requires a reupload
|
||||
if(REUPLOAD_REQUIRED_STATUS.includes(error.response?.status!)) {
|
||||
ctx.logger.info({ key: message.key }, 'sending reupload media request...')
|
||||
// request reupload
|
||||
message = await ctx.reuploadRequest(message)
|
||||
const result = await downloadMsg()
|
||||
return result
|
||||
const result = await downloadMsg()
|
||||
.catch(async(error) => {
|
||||
if(ctx) {
|
||||
if(axios.isAxiosError(error)) {
|
||||
// check if the message requires a reupload
|
||||
if(REUPLOAD_REQUIRED_STATUS.includes(error.response?.status!)) {
|
||||
ctx.logger.info({ key: message.key }, 'sending reupload media request...')
|
||||
// request reupload
|
||||
message = await ctx.reuploadRequest(message)
|
||||
const result = await downloadMsg()
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw error
|
||||
}
|
||||
throw error
|
||||
})
|
||||
|
||||
return result as Type extends 'buffer' ? Buffer : Transform
|
||||
|
||||
async function downloadMsg() {
|
||||
const mContent = extractMessageContent(message.message)
|
||||
|
||||
Reference in New Issue
Block a user