feat: generate high quality thumbs on link preview

This commit is contained in:
Adhiraj Singh
2022-09-15 18:40:22 +05:30
parent 864a01f9a5
commit f0bdb12e56
8 changed files with 95 additions and 21 deletions

View File

@@ -238,9 +238,16 @@ export async function generateThumbnail(
}
) {
let thumbnail: string | undefined
let originalImageDimensions: { width: number; height: number } | undefined
if(mediaType === 'image') {
const { buffer } = await extractImageThumb(file)
const { buffer, original } = await extractImageThumb(file)
thumbnail = buffer.toString('base64')
if(original.width && original.height) {
originalImageDimensions = {
width: original.width,
height: original.height,
}
}
} else if(mediaType === 'video') {
const imgFilename = join(getTmpFilesDirectory(), generateMessageID() + '.jpg')
try {
@@ -254,7 +261,10 @@ export async function generateThumbnail(
}
}
return thumbnail
return {
thumbnail,
originalImageDimensions
}
}
export const getHttpStream = async(url: string | URL, options: AxiosRequestConfig & { isStream?: true } = {}) => {