mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
@@ -4,7 +4,7 @@ import { ILogger } from './logger'
|
|||||||
import { prepareWAMessageMedia } from './messages'
|
import { prepareWAMessageMedia } from './messages'
|
||||||
import { extractImageThumb, getHttpStream } from './messages-media'
|
import { extractImageThumb, getHttpStream } from './messages-media'
|
||||||
|
|
||||||
const THUMBNAIL_WIDTH_PX = 192
|
const THUMBNAIL_WIDTH_PX = 1024
|
||||||
|
|
||||||
/** Fetches an image and generates a thumbnail for it */
|
/** Fetches an image and generates a thumbnail for it */
|
||||||
const getCompressedJpegThumbnail = async (url: string, { thumbnailWidth, fetchOpts }: URLGenerationOptions) => {
|
const getCompressedJpegThumbnail = async (url: string, { thumbnailWidth, fetchOpts }: URLGenerationOptions) => {
|
||||||
@@ -70,7 +70,9 @@ export const getUrlInfo = async (
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
headers: opts.fetchOpts as {}
|
headers: {
|
||||||
|
'User-Agent': 'Twitterbot',
|
||||||
|
}
|
||||||
})
|
})
|
||||||
if (info && 'title' in info && info.title) {
|
if (info && 'title' in info && info.title) {
|
||||||
const [image] = info.images
|
const [image] = info.images
|
||||||
@@ -83,22 +85,24 @@ export const getUrlInfo = async (
|
|||||||
originalThumbnailUrl: image
|
originalThumbnailUrl: image
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.uploadImage) {
|
if (image) {
|
||||||
const { imageMessage } = await prepareWAMessageMedia(
|
if (opts.uploadImage) {
|
||||||
{ image: { url: image } },
|
const { imageMessage } = await prepareWAMessageMedia(
|
||||||
{
|
{ image: { url: image } },
|
||||||
upload: opts.uploadImage,
|
{
|
||||||
mediaTypeOverride: 'thumbnail-link',
|
upload: opts.uploadImage,
|
||||||
options: opts.fetchOpts
|
mediaTypeOverride: 'thumbnail-link',
|
||||||
|
options: opts.fetchOpts
|
||||||
|
}
|
||||||
|
)
|
||||||
|
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined
|
||||||
|
urlInfo.highQualityThumbnail = imageMessage || undefined
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
urlInfo.jpegThumbnail = (await getCompressedJpegThumbnail(image, opts)).buffer
|
||||||
|
} catch (error) {
|
||||||
|
opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail')
|
||||||
}
|
}
|
||||||
)
|
|
||||||
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined
|
|
||||||
urlInfo.highQualityThumbnail = imageMessage || undefined
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined
|
|
||||||
} catch (error) {
|
|
||||||
opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,4 +113,4 @@ export const getUrlInfo = async (
|
|||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user