fix(app/utils): don't die on undefined file type buffer (relates #1431) [skip ci]

This commit is contained in:
Simon Lecoq
2023-08-24 22:12:15 -04:00
parent 693ba354e1
commit ac9e0f445f

View File

@@ -450,14 +450,15 @@ export async function imgb64(image, {width, height, fallback = true} = {}) {
try {
if (image.startsWith("http://") || image.startsWith("https://")) {
const buffer = Buffer.from(await fetch(image).then(response => response.arrayBuffer()))
ext = (await fileTypeFromBuffer(buffer)).ext ?? ext
ext = (await fileTypeFromBuffer(buffer))?.ext ?? ext
image = sharp(buffer)
}
else {
image = sharp(image)
}
}
catch {
catch (error) {
console.debug(`metrics/imgb64 > error > ${error}${fallback ? " (using fallback image instead)" : ""}`)
return imgb64(null, {fallback})
}
//Resize image