From 0496a65f9c88e9703250daad1ecd4a7496ed4968 Mon Sep 17 00:00:00 2001 From: viktorstrate Date: Sat, 10 Aug 2019 16:42:27 +0200 Subject: [PATCH] Only scan web compatiable image formats --- api/src/scanner/utils.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api/src/scanner/utils.js b/api/src/scanner/utils.js index f9733e9e..950056cd 100644 --- a/api/src/scanner/utils.js +++ b/api/src/scanner/utils.js @@ -5,6 +5,9 @@ import { promisify } from 'util' import path from 'path' import config from '../config' +const rawTypes = ['cr2', 'arw', 'crw', 'dng'] +const imageTypes = [...rawTypes, 'jpg', 'png', 'gif', 'bmp'] + export const isImage = async path => { if ((await fs.stat(path)).isDirectory()) { return false @@ -13,7 +16,8 @@ export const isImage = async path => { try { const buffer = await readChunk(path, 0, 12) const type = imageType(buffer) - return type != null + + return type && imageTypes.includes(type.ext) } catch (e) { throw new Error(`isImage error at ${path}: ${JSON.stringify(e)}`) } @@ -24,8 +28,6 @@ export const isRawImage = async path => { const buffer = await readChunk(path, 0, 12) const { ext } = imageType(buffer) - const rawTypes = ['cr2', 'arw', 'crw', 'dng'] - return rawTypes.includes(ext) } catch (e) { throw new Error(`isRawImage error at ${path}: ${JSON.stringify(e)}`)