added force media_conn option

This commit is contained in:
Adhiraj
2020-09-23 15:36:45 +05:30
parent 253e4e1dd1
commit d86cde2805
2 changed files with 8 additions and 3 deletions

View File

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

View File

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