Skip to content
Snippets Groups Projects
Unverified Commit aa55aced authored by coord_e's avatar coord_e Committed by GitHub
Browse files

Fix not to reject non-image file uploads (#6664)

* fix not to reject non-image file uploads

* handle an error from sharp
parent eb70d6f2
No related branches found
No related tags found
No related merge requests found
......@@ -160,12 +160,30 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
}
}
const img = sharp(path);
const metadata = await img.metadata();
const isAnimated = metadata.pages && metadata.pages > 1;
if (!['image/jpeg', 'image/png', 'image/webp'].includes(type)) {
logger.debug(`web image and thumbnail not created (not an required file)`);
return {
webpublic: null,
thumbnail: null
};
}
let img: sharp.Sharp | null = null;
try {
img = sharp(path);
const metadata = await img.metadata();
const isAnimated = metadata.pages && metadata.pages > 1;
// skip animated
if (isAnimated) {
// skip animated
if (isAnimated) {
return {
webpublic: null,
thumbnail: null
};
}
} catch (e) {
logger.warn(`sharp failed: ${e}`);
return {
webpublic: null,
thumbnail: null
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment