Skip to content

Commit c66485e

Browse files
Merge pull request #1748 from coreh/fix-url-corruption-querystring
Avoid corrupting media URLs with query strings
2 parents 4a25cd1 + 96d3ec2 commit c66485e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,7 +2558,9 @@ export class BaileysStartupService extends ChannelStartupService {
25582558
imageBuffer = Buffer.from(base64Data, 'base64');
25592559
} else {
25602560
const timestamp = new Date().getTime();
2561-
const url = `${image}?timestamp=${timestamp}`;
2561+
const parsedURL = new URL(image);
2562+
parsedURL.searchParams.set('timestamp', timestamp.toString());
2563+
const url = parsedURL.toString();
25622564

25632565
let config: any = { responseType: 'arraybuffer' };
25642566

@@ -2779,7 +2781,9 @@ export class BaileysStartupService extends ChannelStartupService {
27792781

27802782
if (isURL(audio)) {
27812783
const timestamp = new Date().getTime();
2782-
const url = `${audio}?timestamp=${timestamp}`;
2784+
const parsedURL = new URL(audio);
2785+
parsedURL.searchParams.set('timestamp', timestamp.toString());
2786+
const url = parsedURL.toString();
27832787

27842788
const config: any = { responseType: 'stream' };
27852789

@@ -3705,7 +3709,9 @@ export class BaileysStartupService extends ChannelStartupService {
37053709
let pic: WAMediaUpload;
37063710
if (isURL(picture)) {
37073711
const timestamp = new Date().getTime();
3708-
const url = `${picture}?timestamp=${timestamp}`;
3712+
const parsedURL = new URL(picture);
3713+
parsedURL.searchParams.set('timestamp', timestamp.toString());
3714+
const url = parsedURL.toString();
37093715

37103716
let config: any = { responseType: 'arraybuffer' };
37113717

@@ -3987,7 +3993,9 @@ export class BaileysStartupService extends ChannelStartupService {
39873993
let pic: WAMediaUpload;
39883994
if (isURL(picture.image)) {
39893995
const timestamp = new Date().getTime();
3990-
const url = `${picture.image}?timestamp=${timestamp}`;
3996+
const parsedURL = new URL(picture.image);
3997+
parsedURL.searchParams.set('timestamp', timestamp.toString());
3998+
const url = parsedURL.toString();
39913999

39924000
let config: any = { responseType: 'arraybuffer' };
39934001

0 commit comments

Comments
 (0)