refactor: replace axios with fetch API and update related types (#1666)
This commit is contained in:
committed by
GitHub
parent
cfe7a2b2b3
commit
fb12f6d9d3
@@ -1,5 +1,4 @@
|
||||
import { Boom } from '@hapi/boom'
|
||||
import axios from 'axios'
|
||||
import { randomBytes } from 'crypto'
|
||||
import { promises as fs } from 'fs'
|
||||
import { type Transform } from 'stream'
|
||||
@@ -455,9 +454,10 @@ export const generateWAMessageContent = async (
|
||||
if (options.getProfilePicUrl) {
|
||||
const pfpUrl = await options.getProfilePicUrl(message.groupInvite.jid, 'preview')
|
||||
if (pfpUrl) {
|
||||
const resp = await axios.get(pfpUrl, { responseType: 'arraybuffer' })
|
||||
if (resp.status === 200) {
|
||||
m.groupInviteMessage.jpegThumbnail = resp.data
|
||||
const resp = await fetch(pfpUrl, { method: 'GET', dispatcher: options?.options?.dispatcher })
|
||||
if (resp.ok) {
|
||||
const buf = Buffer.from(await resp.arrayBuffer())
|
||||
m.groupInviteMessage.jpegThumbnail = buf
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -933,8 +933,8 @@ export const downloadMediaMessage = async <Type extends 'buffer' | 'stream'>(
|
||||
const result = await downloadMsg().catch(async error => {
|
||||
if (
|
||||
ctx &&
|
||||
axios.isAxiosError(error) && // check if the message requires a reupload
|
||||
REUPLOAD_REQUIRED_STATUS.includes(error.response?.status!)
|
||||
typeof error?.status === 'number' && // treat errors with status as HTTP failures requiring reupload
|
||||
REUPLOAD_REQUIRED_STATUS.includes(error.status as number)
|
||||
) {
|
||||
ctx.logger.info({ key: message.key }, 'sending reupload media request...')
|
||||
// request reupload
|
||||
|
||||
Reference in New Issue
Block a user