mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-14 10:05:46 +01:00
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
1 changed files with 23 additions and 5 deletions
|
@ -160,7 +160,18 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const img = sharp(path);
|
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 metadata = await img.metadata();
|
||||||
const isAnimated = metadata.pages && metadata.pages > 1;
|
const isAnimated = metadata.pages && metadata.pages > 1;
|
||||||
|
|
||||||
|
@ -171,6 +182,13 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
|
||||||
thumbnail: null
|
thumbnail: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.warn(`sharp failed: ${e}`);
|
||||||
|
return {
|
||||||
|
webpublic: null,
|
||||||
|
thumbnail: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// #region webpublic
|
// #region webpublic
|
||||||
let webpublic: IImage | null = null;
|
let webpublic: IImage | null = null;
|
||||||
|
|
Loading…
Reference in a new issue