fix(whatsapp): make Baileys media upload compatible with generic agents

This commit is contained in:
termtek
2026-04-13 21:42:09 +08:00
committed by Frank Yang
parent 6c41ff7d22
commit 17479dc55b

View File

@@ -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