From d86cde28055d8f61a1c97ef680c8d18a8320ab7b Mon Sep 17 00:00:00 2001 From: Adhiraj Date: Wed, 23 Sep 2020 15:36:45 +0530 Subject: [PATCH] added force media_conn option --- src/WAConnection/6.MessagesSend.ts | 9 ++++++--- src/WAConnection/Constants.ts | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/WAConnection/6.MessagesSend.ts b/src/WAConnection/6.MessagesSend.ts index 2ce4ed0..ab18287 100644 --- a/src/WAConnection/6.MessagesSend.ts +++ b/src/WAConnection/6.MessagesSend.ts @@ -113,7 +113,7 @@ export class WAConnection extends Base { await generateThumbnail(buffer, mediaType, options) // send a query JSON to obtain the url & auth token to upload our media - let json = await this.refreshMediaConn () + let json = await this.refreshMediaConn (options.forceNewMediaOptions) let mediaUrl: string for (let host of json.hosts) { @@ -273,10 +273,13 @@ export class WAConnection extends Base { @Mutex () protected async refreshMediaConn (forceGet = false) { if (!this.mediaConn || forceGet || (new Date().getTime()-this.mediaConn.fetchDate.getTime()) > this.mediaConn.ttl*1000) { - const result = await this.query({json: ['query', 'mediaConn']}) - this.mediaConn = result.media_conn + this.mediaConn = await this.getNewMediaConn() this.mediaConn.fetchDate = new Date() } return this.mediaConn } + protected async getNewMediaConn () { + const result = await this.query({json: ['query', 'mediaConn']}) + return result.media_conn + } } diff --git a/src/WAConnection/Constants.ts b/src/WAConnection/Constants.ts index e8604e2..5bbbab3 100644 --- a/src/WAConnection/Constants.ts +++ b/src/WAConnection/Constants.ts @@ -329,6 +329,8 @@ export interface MessageOptions { uploadAgent?: Agent /** If set to true (default), automatically detects if you're sending a link & attaches the preview*/ detectLinks?: boolean + /** Fetches new media options for every media file */ + forceNewMediaOptions?: boolean } export interface WABroadcastListInfo { status: number