fix(app/utils): don't die on undefined file type buffer (relates #1431) [skip ci]
This commit is contained in:
@@ -450,14 +450,15 @@ export async function imgb64(image, {width, height, fallback = true} = {}) {
|
|||||||
try {
|
try {
|
||||||
if (image.startsWith("http://") || image.startsWith("https://")) {
|
if (image.startsWith("http://") || image.startsWith("https://")) {
|
||||||
const buffer = Buffer.from(await fetch(image).then(response => response.arrayBuffer()))
|
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)
|
image = sharp(buffer)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
image = sharp(image)
|
image = sharp(image)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch (error) {
|
||||||
|
console.debug(`metrics/imgb64 > error > ${error}${fallback ? " (using fallback image instead)" : ""}`)
|
||||||
return imgb64(null, {fallback})
|
return imgb64(null, {fallback})
|
||||||
}
|
}
|
||||||
//Resize image
|
//Resize image
|
||||||
|
|||||||
Reference in New Issue
Block a user