Fix not to reject non-image file uploads (#6664)
* fix not to reject non-image file uploads * handle an error from sharp
This commit is contained in:
parent
eb70d6f226
commit
aa55acedc9
|
@ -160,12 +160,30 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const img = sharp(path);
|
if (!['image/jpeg', 'image/png', 'image/webp'].includes(type)) {
|
||||||
const metadata = await img.metadata();
|
logger.debug(`web image and thumbnail not created (not an required file)`);
|
||||||
const isAnimated = metadata.pages && metadata.pages > 1;
|
return {
|
||||||
|
webpublic: null,
|
||||||
|
thumbnail: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// skip animated
|
let img: sharp.Sharp | null = null;
|
||||||
if (isAnimated) {
|
|
||||||
|
try {
|
||||||
|
img = sharp(path);
|
||||||
|
const metadata = await img.metadata();
|
||||||
|
const isAnimated = metadata.pages && metadata.pages > 1;
|
||||||
|
|
||||||
|
// skip animated
|
||||||
|
if (isAnimated) {
|
||||||
|
return {
|
||||||
|
webpublic: null,
|
||||||
|
thumbnail: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.warn(`sharp failed: ${e}`);
|
||||||
return {
|
return {
|
||||||
webpublic: null,
|
webpublic: null,
|
||||||
thumbnail: null
|
thumbnail: null
|
||||||
|
|
Loading…
Reference in New Issue