mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
added force media_conn option
This commit is contained in:
@@ -113,7 +113,7 @@ export class WAConnection extends Base {
|
|||||||
await generateThumbnail(buffer, mediaType, options)
|
await generateThumbnail(buffer, mediaType, options)
|
||||||
|
|
||||||
// send a query JSON to obtain the url & auth token to upload our media
|
// 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
|
let mediaUrl: string
|
||||||
for (let host of json.hosts) {
|
for (let host of json.hosts) {
|
||||||
@@ -273,10 +273,13 @@ export class WAConnection extends Base {
|
|||||||
@Mutex ()
|
@Mutex ()
|
||||||
protected async refreshMediaConn (forceGet = false) {
|
protected async refreshMediaConn (forceGet = false) {
|
||||||
if (!this.mediaConn || forceGet || (new Date().getTime()-this.mediaConn.fetchDate.getTime()) > this.mediaConn.ttl*1000) {
|
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 = await this.getNewMediaConn()
|
||||||
this.mediaConn = result.media_conn
|
|
||||||
this.mediaConn.fetchDate = new Date()
|
this.mediaConn.fetchDate = new Date()
|
||||||
}
|
}
|
||||||
return this.mediaConn
|
return this.mediaConn
|
||||||
}
|
}
|
||||||
|
protected async getNewMediaConn () {
|
||||||
|
const result = await this.query({json: ['query', 'mediaConn']})
|
||||||
|
return result.media_conn
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -329,6 +329,8 @@ export interface MessageOptions {
|
|||||||
uploadAgent?: Agent
|
uploadAgent?: Agent
|
||||||
/** If set to true (default), automatically detects if you're sending a link & attaches the preview*/
|
/** If set to true (default), automatically detects if you're sending a link & attaches the preview*/
|
||||||
detectLinks?: boolean
|
detectLinks?: boolean
|
||||||
|
/** Fetches new media options for every media file */
|
||||||
|
forceNewMediaOptions?: boolean
|
||||||
}
|
}
|
||||||
export interface WABroadcastListInfo {
|
export interface WABroadcastListInfo {
|
||||||
status: number
|
status: number
|
||||||
|
|||||||
Reference in New Issue
Block a user