From 17479dc55be3f97a87959eac34d5a78ebd5401ff Mon Sep 17 00:00:00 2001 From: termtek Date: Mon, 13 Apr 2026 21:42:09 +0800 Subject: [PATCH] fix(whatsapp): make Baileys media upload compatible with generic agents --- .../@whiskeysockets__baileys@7.0.0-rc.9.patch | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/patches/@whiskeysockets__baileys@7.0.0-rc.9.patch b/patches/@whiskeysockets__baileys@7.0.0-rc.9.patch index c3e95ad54c9..e4ed4eeae52 100644 --- a/patches/@whiskeysockets__baileys@7.0.0-rc.9.patch +++ b/patches/@whiskeysockets__baileys@7.0.0-rc.9.patch @@ -1,8 +1,8 @@ diff --git a/lib/Utils/messages-media.js b/lib/Utils/messages-media.js -index 0d32dfb4882dfe029ba8804772d7d89404b08e76..4eb2b214b48ef3af48f707237cd19c05e11632a6 100644 +index 0d32dfb4882dfe029ba8804772d7d89404b08e76..73809fcd1d52362aef0c35cb7416c29d86482df0 100644 --- a/lib/Utils/messages-media.js +++ b/lib/Utils/messages-media.js -@@ -353,9 +353,17 @@ export const encryptedStream = async (media, mediaType, { logger, saveOriginalFi +@@ -353,9 +353,17 @@ const fileSha256 = sha256Plain.digest(); const fileEncSha256 = sha256Enc.digest(); encFileWriteStream.write(mac); @@ -20,3 +20,29 @@ index 0d32dfb4882dfe029ba8804772d7d89404b08e76..4eb2b214b48ef3af48f707237cd19c05 logger?.debug('encrypted data successfully'); return { mediaKey, +@@ -520,11 +528,10 @@ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let result; + try { +- const stream = createReadStream(filePath); ++ const body = await fs.readFile(filePath); + const response = await fetch(url, { +- dispatcher: fetchAgent, + method: 'POST', +- body: stream, ++ body, + headers: { + ...(() => { + const hdrs = options?.headers; +@@ -535,6 +542,11 @@ + 'Content-Type': 'application/octet-stream', + Origin: DEFAULT_ORIGIN + }, ++ // Baileys passes a generic agent here in some runtimes. Undici's ++ // `dispatcher` only works with Dispatcher-compatible implementations, ++ // so only wire it through when the object actually implements ++ // `dispatch`. ++ ...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}), + duplex: 'half', + // Note: custom agents/proxy require undici Agent; omitted here. + signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined