-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathetl.js
executable file
·48 lines (43 loc) · 1.3 KB
/
etl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require('dotenv').config()
const debug = require('debug')('hub:etl')
const path = require('path')
const watch = require('node-watch')
const { insertImage } = require('./lib/db.js')
const getDTO = require('./lib/exif.js')
require('dotenv').config()
const MEDIA_PATH = process.env.MEDIA_PATH
if (!MEDIA_PATH) {
console.error(new Error('MEDIA_PATH'))
process.exit(1)
}
const STORAGE = 'storage'
const STORAGE_PATH = path.join(MEDIA_PATH, STORAGE)
debug('STORAGE_PATH', STORAGE_PATH)
const EXIFTOOL_PATH = process.env.EXIFTOOL_PATH
if (!EXIFTOOL_PATH) {
console.error(new Error('no EXIFTOOL_PATH'))
process.exit(1)
}
debug('EXIFTOOL_PATH', EXIFTOOL_PATH)
function addImageToDatabase ({ fileName, dateTimeOriginal, fullPath }) {
debug('insert', fileName)
const inserted = insertImage.run({ fileName, dateTimeOriginal, fullPath })
debug('inserted', inserted)
}
if (require.main === module) {
debug('watching')
watch(STORAGE_PATH, {
filter: new RegExp(/.JPG$/, 'i'),
recursive: true
}, (evt, name) => {
if (evt === 'update') {
getDTO(name, (err, DTO) => {
if (err) {
return debug('error in worker callback', err)
}
const model = { dateTimeOriginal: DTO, fullPath: name, fileName: path.basename(name) }
addImageToDatabase(model)
})
}
})
}