Layout and scanner improvements

This commit is contained in:
viktorstrate
2019-07-18 22:33:18 +02:00
parent e09d80c9fc
commit 1d5ca69701
6 changed files with 83 additions and 23 deletions

View File

@@ -30,12 +30,14 @@
"fs-extra": "^8.1.0",
"graphql-tag": "^2.10.1",
"image-size": "^0.7.4",
"img-type": "^0.1.13",
"image-type": "^4.1.0",
"is-image": "^3.0.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.14",
"neo4j-driver": "^1.7.3",
"neo4j-graphql-js": "^2.6.3",
"node-fetch": "^2.3.0",
"read-chunk": "^3.2.0",
"regenerator-runtime": "^0.13.2",
"sharp": "^0.22.1",
"uuid": "^3.3.2"

View File

@@ -2,14 +2,31 @@ import fs from 'fs-extra'
import path from 'path'
import { resolve as pathResolve, basename as pathBasename } from 'path'
import { PubSub } from 'apollo-server'
import imgType from 'img-type'
import uuid from 'uuid'
import { exiftool } from 'exiftool-vendored'
import sharp from 'sharp'
import readChunk from 'read-chunk'
import imageType from 'image-type'
import config from './config'
export const EVENT_SCANNER_PROGRESS = 'SCANNER_PROGRESS'
const isImage = async path => {
const buffer = await readChunk(path, 0, 12)
const type = imageType(buffer)
return type != null
}
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)
}
class PhotoScanner {
constructor(driver) {
this.driver = driver
@@ -146,7 +163,7 @@ class PhotoScanner {
continue
}
if (!foundImage && (await imgType.isImg(itemPath))) {
if (!foundImage && (await isImage(itemPath))) {
foundImage = true
}
}
@@ -167,7 +184,7 @@ class PhotoScanner {
for (const item of list) {
const itemPath = pathResolve(path, item)
if (await imgType.isImg(itemPath)) {
if (await isImage(itemPath)) {
const session = this.driver.session()
const photoResult = await session.run(
@@ -217,13 +234,9 @@ class PhotoScanner {
await fs.remove(imagePath)
await fs.mkdirp(imagePath)
const type = await imgType.getType(photo.path)
let resizeBaseImg = photo.path
const rawTypes = ['cr2', 'arw', 'crw', 'dng']
if (rawTypes.includes(type)) {
if (await isRawImage(photo.path)) {
console.log('Processing RAW image')
const extractedPath = path.resolve(imagePath, 'extracted.jpg')