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 { scan, front } = images
|
||||
|
||||
return updatePhotos(scan, front, directory)
|
||||
return updatePhotos(directory, [['scan.jpg', scan], ['front.jpg', front]])
|
||||
.then(() => db.none(sql, [deviceId, !!scan, !!front]))
|
||||
.catch(err => logger.error('while running machine diagnostics: ', err))
|
||||
}
|
||||
|
|
@ -503,16 +503,13 @@ function createPhoto (name, data, dir) {
|
|||
return fsPromises.writeFile(filename, decodedImageData)
|
||||
}
|
||||
|
||||
function updatePhotos (scan, front, dir) {
|
||||
function updatePhotos (dir, photoPairs) {
|
||||
const dirname = path.join(dir)
|
||||
_.attempt(() => makeDir.sync(dirname))
|
||||
|
||||
const promises = [
|
||||
createPhoto('scan.jpg', scan, dirname),
|
||||
createPhoto('front.jpg', front, dirname)
|
||||
]
|
||||
|
||||
return Promise.all(promises)
|
||||
return Promise.all(_.map(
|
||||
([filename, data]) => createPhoto(filename, data, dirname),
|
||||
photoPairs
|
||||
))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue