diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-07-21 04:48:52 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-07-21 04:48:52 +0200 |
| commit | d41070c7b00fafc974a1a6e7b6d1b42391fa57ed (patch) | |
| tree | 4178eba89627e8581cdc5eea65bf7f11591f6b45 /lib/worker/processFiles.js | |
| parent | d02cbad01f3abfa8a1aad0b55b8bd9cf544090cf (diff) | |
all async paths working
Diffstat (limited to 'lib/worker/processFiles.js')
| -rw-r--r-- | lib/worker/processFiles.js | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/worker/processFiles.js b/lib/worker/processFiles.js index c9b2724..2b89aea 100644 --- a/lib/worker/processFiles.js +++ b/lib/worker/processFiles.js @@ -14,18 +14,17 @@ module.exports = function processFiles() { if (processing) return processing = true - dbFile.crud.index({ processed: false }).then( (files) => { + dbFile.index({ processed: false, limit: 1 }).then( (files) => { console.log(files.length + ' files left to process') - if (files.length === 0) { + if (! files || files.length === 0) { processing = false return } - file = files.at(0) - console.log('processing', file.get('name')) - const mimeType = mimeFromExtension(file.get('name')) - file.set('mime', mimeType.mime) - file.set('type', mimeType.type) + let file = files.at ? files.at(0) : files[0] + const mimeType = mimeFromExtension(file.name) + file.mime = mimeType.mime + file.type = mimeType.type switch (mimeType.type) { case 'audio': return processAudio(file) @@ -42,9 +41,9 @@ module.exports = function processFiles() { } function processAudio(file) { - const filePath = path.join(__dirname, '../..', 'public/data', String(file.get('folder_id'))) + const filePath = path.join(__dirname, '../..', 'public/data', String(file.folder_id)) // console.log(filePath) - const fullPath = path.join(filePath, file.get('name')) + const fullPath = path.join(filePath, file.name) console.log(fullPath) return new Promise ( (resolve, reject) => { @@ -83,8 +82,14 @@ function cacheFfprobe(file, fullPath) { return new Promise ( (resolve, reject) => { console.log('ffprobe') ffprobe(fullPath, function(err, probeData) { - file.set('duration', probeData.format.duration) - file.set('analysis', JSON.stringify(probeData)) + if (err) { + console.error('\n------------------------- !!!\n\n') + console.error(err) + } + if (probeData) { + file.duration = probeData.format.duration + } + file.analysis = JSON.stringify(probeData) resolve() }) }) @@ -132,7 +137,7 @@ function processImage(file) { } function processDone(file) { - file.set({ processed: true }) - ipc.of.cortex && ipc.of.cortex.emit("processed", { file: file }) - return file.save() + file.processed = true + ipc.of.cortex && ipc.of.cortex.emit("updateFile", { file: file }) + return dbFile.update(file.id, file) }
\ No newline at end of file |
