diff options
| author | coord_e <me@coord-e.com> | 2020-08-22 04:25:25 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-22 04:25:25 +0900 |
| commit | aa55acedc9b138234fd1454f06d9e49b8fbfe7ef (patch) | |
| tree | 80079a14cc577be199c4e0c8400346e85779ff68 /src/services | |
| parent | Fix a slow query on channel timeline (#6663) (diff) | |
| download | sharkey-aa55acedc9b138234fd1454f06d9e49b8fbfe7ef.tar.gz sharkey-aa55acedc9b138234fd1454f06d9e49b8fbfe7ef.tar.bz2 sharkey-aa55acedc9b138234fd1454f06d9e49b8fbfe7ef.zip | |
Fix not to reject non-image file uploads (#6664)
* fix not to reject non-image file uploads
* handle an error from sharp
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/drive/add-file.ts | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts index fbd2f76ddc..8d32d06d2e 100644 --- a/src/services/drive/add-file.ts +++ b/src/services/drive/add-file.ts @@ -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 |