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:
arthur simas
2024-05-15 12:34:06 -03:00
committed by GitHub
parent 17ce9df557
commit 2ae664c655
2 changed files with 22 additions and 18 deletions

View File

@@ -27,6 +27,9 @@
"selector": "TSEnumDeclaration",
"message": "Don't declare enums, use literals instead"
}
],
"keyword-spacing": [
"warn"
]
}
}

View File

@@ -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,16 +869,14 @@ 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) {
.catch(async(error) => {
if(ctx) {
if(axios.isAxiosError(error)) {
// check if the message requires a reupload
@@ -892,7 +891,9 @@ export const downloadMediaMessage = async(
}
throw error
}
})
return result as Type extends 'buffer' ? Buffer : Transform
async function downloadMsg() {
const mContent = extractMessageContent(message.message)