refactor: generalize updatePhotos
This commit is contained in:
parent
6c8ced3c1f
commit
60b016efb4
1 changed files with 6 additions and 9 deletions
|
|
@ -487,7 +487,7 @@ function updateDiagnostics (deviceId, images) {
|
||||||
const directory = `${OPERATOR_DATA_DIR}/diagnostics/${deviceId}/`
|
const directory = `${OPERATOR_DATA_DIR}/diagnostics/${deviceId}/`
|
||||||
const { scan, front } = images
|
const { scan, front } = images
|
||||||
|
|
||||||
return updatePhotos(scan, front, directory)
|
return updatePhotos(directory, [['scan.jpg', scan], ['front.jpg', front]])
|
||||||
.then(() => db.none(sql, [deviceId, !!scan, !!front]))
|
.then(() => db.none(sql, [deviceId, !!scan, !!front]))
|
||||||
.catch(err => logger.error('while running machine diagnostics: ', err))
|
.catch(err => logger.error('while running machine diagnostics: ', err))
|
||||||
}
|
}
|
||||||
|
|
@ -503,16 +503,13 @@ function createPhoto (name, data, dir) {
|
||||||
return fsPromises.writeFile(filename, decodedImageData)
|
return fsPromises.writeFile(filename, decodedImageData)
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePhotos (scan, front, dir) {
|
function updatePhotos (dir, photoPairs) {
|
||||||
const dirname = path.join(dir)
|
const dirname = path.join(dir)
|
||||||
_.attempt(() => makeDir.sync(dirname))
|
_.attempt(() => makeDir.sync(dirname))
|
||||||
|
return Promise.all(_.map(
|
||||||
const promises = [
|
([filename, data]) => createPhoto(filename, data, dirname),
|
||||||
createPhoto('scan.jpg', scan, dirname),
|
photoPairs
|
||||||
createPhoto('front.jpg', front, dirname)
|
))
|
||||||
]
|
|
||||||
|
|
||||||
return Promise.all(promises)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue