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", "selector": "TSEnumDeclaration",
"message": "Don't declare enums, use literals instead" "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 { randomBytes } from 'crypto'
import { promises as fs } from 'fs' import { promises as fs } from 'fs'
import { Logger } from 'pino' import { Logger } from 'pino'
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'
import { 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 * 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, message: WAMessage,
type: 'buffer' | 'stream', type: Type,
options: MediaDownloadOptions, options: MediaDownloadOptions,
ctx?: DownloadMediaMessageContext ctx?: DownloadMediaMessageContext
) => { ) => {
try {
const result = await downloadMsg() const result = await downloadMsg()
return result .catch(async(error) => {
} catch(error) {
if(ctx) { if(ctx) {
if(axios.isAxiosError(error)) { if(axios.isAxiosError(error)) {
// check if the message requires a reupload // check if the message requires a reupload
@@ -892,7 +891,9 @@ export const downloadMediaMessage = async(
} }
throw error throw error
} })
return result as Type extends 'buffer' ? Buffer : Transform
async function downloadMsg() { async function downloadMsg() {
const mContent = extractMessageContent(message.message) const mContent = extractMessageContent(message.message)