From 96d3ec20178fd20152b061be7d82f4c71a46660a Mon Sep 17 00:00:00 2001 From: Marco Buono Date: Wed, 23 Jul 2025 16:06:14 -0300 Subject: [PATCH] fix: avoid corrupting URLs with query strings --- .../channel/whatsapp/whatsapp.baileys.service.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index de31b503..03870285 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -2504,7 +2504,9 @@ export class BaileysStartupService extends ChannelStartupService { imageBuffer = Buffer.from(base64Data, 'base64'); } else { const timestamp = new Date().getTime(); - const url = `${image}?timestamp=${timestamp}`; + const parsedURL = new URL(image); + parsedURL.searchParams.set('timestamp', timestamp.toString()); + const url = parsedURL.toString(); let config: any = { responseType: 'arraybuffer' }; @@ -2725,7 +2727,9 @@ export class BaileysStartupService extends ChannelStartupService { if (isURL(audio)) { const timestamp = new Date().getTime(); - const url = `${audio}?timestamp=${timestamp}`; + const parsedURL = new URL(audio); + parsedURL.searchParams.set('timestamp', timestamp.toString()); + const url = parsedURL.toString(); const config: any = { responseType: 'stream' }; @@ -3591,7 +3595,9 @@ export class BaileysStartupService extends ChannelStartupService { let pic: WAMediaUpload; if (isURL(picture)) { const timestamp = new Date().getTime(); - const url = `${picture}?timestamp=${timestamp}`; + const parsedURL = new URL(picture); + parsedURL.searchParams.set('timestamp', timestamp.toString()); + const url = parsedURL.toString(); let config: any = { responseType: 'arraybuffer' }; @@ -3873,7 +3879,9 @@ export class BaileysStartupService extends ChannelStartupService { let pic: WAMediaUpload; if (isURL(picture.image)) { const timestamp = new Date().getTime(); - const url = `${picture.image}?timestamp=${timestamp}`; + const parsedURL = new URL(picture.image); + parsedURL.searchParams.set('timestamp', timestamp.toString()); + const url = parsedURL.toString(); let config: any = { responseType: 'arraybuffer' };