mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Merge branch 'master' into invalid-qr-patch
This commit is contained in:
@@ -485,7 +485,10 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
logger,
|
logger,
|
||||||
userJid,
|
userJid,
|
||||||
// multi-device does not have this yet
|
// multi-device does not have this yet
|
||||||
getUrlInfo: text => getUrlInfo(text, { thumbnailWidth: linkPreviewImageThumbnailWidth }),
|
getUrlInfo: text => getUrlInfo(
|
||||||
|
text,
|
||||||
|
{ thumbnailWidth: linkPreviewImageThumbnailWidth, timeoutMs: 3_000 }
|
||||||
|
),
|
||||||
upload: waUploadToServer,
|
upload: waUploadToServer,
|
||||||
mediaCache: config.mediaCache,
|
mediaCache: config.mediaCache,
|
||||||
...options,
|
...options,
|
||||||
|
|||||||
@@ -4,14 +4,15 @@ import { extractImageThumb, getHttpStream } from './messages-media'
|
|||||||
const THUMBNAIL_WIDTH_PX = 192
|
const THUMBNAIL_WIDTH_PX = 192
|
||||||
|
|
||||||
/** Fetches an image and generates a thumbnail for it */
|
/** Fetches an image and generates a thumbnail for it */
|
||||||
const getCompressedJpegThumbnail = async(url: string, thumbnailWidth: number) => {
|
const getCompressedJpegThumbnail = async(url: string, { thumbnailWidth, timeoutMs }: URLGenerationOptions) => {
|
||||||
const stream = await getHttpStream(url)
|
const stream = await getHttpStream(url, { timeout: timeoutMs })
|
||||||
const result = await extractImageThumb(stream, thumbnailWidth)
|
const result = await extractImageThumb(stream, thumbnailWidth)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export type URLGenerationOptions = {
|
export type URLGenerationOptions = {
|
||||||
thumbnailWidth: number
|
thumbnailWidth: number
|
||||||
|
timeoutMs: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,17 +23,17 @@ export type URLGenerationOptions = {
|
|||||||
*/
|
*/
|
||||||
export const getUrlInfo = async(
|
export const getUrlInfo = async(
|
||||||
text: string,
|
text: string,
|
||||||
opts: URLGenerationOptions = { thumbnailWidth: THUMBNAIL_WIDTH_PX }
|
opts: URLGenerationOptions = { thumbnailWidth: THUMBNAIL_WIDTH_PX, timeoutMs: 3000 }
|
||||||
): Promise<WAUrlInfo | undefined> => {
|
): Promise<WAUrlInfo | undefined> => {
|
||||||
try {
|
try {
|
||||||
const { getLinkPreview } = await import('link-preview-js')
|
const { getLinkPreview } = await import('link-preview-js')
|
||||||
|
|
||||||
const info = await getLinkPreview(text)
|
const info = await getLinkPreview(text, { timeout: opts.timeoutMs })
|
||||||
if(info && 'title' in info) {
|
if(info && 'title' in info) {
|
||||||
const [image] = info.images
|
const [image] = info.images
|
||||||
|
|
||||||
const jpegThumbnail = image
|
const jpegThumbnail = image
|
||||||
? await getCompressedJpegThumbnail(image, opts.thumbnailWidth)
|
? await getCompressedJpegThumbnail(image, opts)
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user