Only scan web compatiable image formats
This commit is contained in:
parent
8f7e50c4ba
commit
0496a65f9c
|
@ -5,6 +5,9 @@ import { promisify } from 'util'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import config from '../config'
|
import config from '../config'
|
||||||
|
|
||||||
|
const rawTypes = ['cr2', 'arw', 'crw', 'dng']
|
||||||
|
const imageTypes = [...rawTypes, 'jpg', 'png', 'gif', 'bmp']
|
||||||
|
|
||||||
export const isImage = async path => {
|
export const isImage = async path => {
|
||||||
if ((await fs.stat(path)).isDirectory()) {
|
if ((await fs.stat(path)).isDirectory()) {
|
||||||
return false
|
return false
|
||||||
|
@ -13,7 +16,8 @@ export const isImage = async path => {
|
||||||
try {
|
try {
|
||||||
const buffer = await readChunk(path, 0, 12)
|
const buffer = await readChunk(path, 0, 12)
|
||||||
const type = imageType(buffer)
|
const type = imageType(buffer)
|
||||||
return type != null
|
|
||||||
|
return type && imageTypes.includes(type.ext)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`isImage error at ${path}: ${JSON.stringify(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 buffer = await readChunk(path, 0, 12)
|
||||||
const { ext } = imageType(buffer)
|
const { ext } = imageType(buffer)
|
||||||
|
|
||||||
const rawTypes = ['cr2', 'arw', 'crw', 'dng']
|
|
||||||
|
|
||||||
return rawTypes.includes(ext)
|
return rawTypes.includes(ext)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`isRawImage error at ${path}: ${JSON.stringify(e)}`)
|
throw new Error(`isRawImage error at ${path}: ${JSON.stringify(e)}`)
|
||||||
|
|
Loading…
Reference in New Issue