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,6 +85,7 @@ export const getUrlInfo = async (
|
|||||||
originalThumbnailUrl: image
|
originalThumbnailUrl: image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (image) {
|
||||||
if (opts.uploadImage) {
|
if (opts.uploadImage) {
|
||||||
const { imageMessage } = await prepareWAMessageMedia(
|
const { imageMessage } = await prepareWAMessageMedia(
|
||||||
{ image: { url: image } },
|
{ image: { url: image } },
|
||||||
@@ -96,11 +99,12 @@ export const getUrlInfo = async (
|
|||||||
urlInfo.highQualityThumbnail = imageMessage || undefined
|
urlInfo.highQualityThumbnail = imageMessage || undefined
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined
|
urlInfo.jpegThumbnail = (await getCompressedJpegThumbnail(image, opts)).buffer
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail')
|
opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return urlInfo
|
return urlInfo
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user