refactor: replace axios with fetch API and update related types (#1666)

This commit is contained in:
João Lucas de Oliveira Lopes
2025-09-27 23:52:43 -03:00
committed by GitHub
parent cfe7a2b2b3
commit fb12f6d9d3
13 changed files with 97 additions and 124 deletions
+4 -5
View File
@@ -1,5 +1,4 @@
import { Boom } from '@hapi/boom'
import type { AxiosRequestConfig } from 'axios'
import { proto } from '../../WAProto/index.js'
import type {
BaileysEventEmitter,
@@ -303,7 +302,7 @@ export const decodeSyncdPatch = async (
return result
}
export const extractSyncdPatches = async (result: BinaryNode, options: AxiosRequestConfig<{}>) => {
export const extractSyncdPatches = async (result: BinaryNode, options: RequestInit) => {
const syncNode = getBinaryNodeChild(result, 'sync')
const collectionNodes = getBinaryNodeChildren(syncNode, 'collection')
@@ -355,7 +354,7 @@ export const extractSyncdPatches = async (result: BinaryNode, options: AxiosRequ
return final
}
export const downloadExternalBlob = async (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => {
export const downloadExternalBlob = async (blob: proto.IExternalBlobReference, options: RequestInit) => {
const stream = await downloadContentFromMessage(blob, 'md-app-state', { options })
const bufferArray: Buffer[] = []
for await (const chunk of stream) {
@@ -365,7 +364,7 @@ export const downloadExternalBlob = async (blob: proto.IExternalBlobReference, o
return Buffer.concat(bufferArray)
}
export const downloadExternalPatch = async (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => {
export const downloadExternalPatch = async (blob: proto.IExternalBlobReference, options: RequestInit) => {
const buffer = await downloadExternalBlob(blob, options)
const syncData = decodeAndHydrate(proto.SyncdMutations, buffer)
return syncData
@@ -424,7 +423,7 @@ export const decodePatches = async (
syncds: proto.ISyncdPatch[],
initial: LTHashState,
getAppStateSyncKey: FetchAppStateSyncKey,
options: AxiosRequestConfig<{}>,
options: RequestInit,
minimumVersionNumber?: number,
logger?: ILogger,
validateMacs = true