fix: change photos path
This commit is contained in:
parent
c221437618
commit
c7d56c8110
6 changed files with 42 additions and 50 deletions
|
|
@ -15,7 +15,7 @@ POSTGRES_PASS=postgres123
|
|||
OFAC_DATA_DIR=$CONFIG_DIR/ofac
|
||||
IDPHOTOCARD_DIR=$CONFIG_DIR/idphotocard
|
||||
FRONTCAMERA_DIR=$CONFIG_DIR/frontcamera
|
||||
IDCARDDATA_DIR=$CONFIG_DIR/idcarddata
|
||||
OPERATOR_DIR=$CONFIG_DIR/operatordata
|
||||
|
||||
mkdir -p $CERT_DIR
|
||||
mkdir -p $CONFIG_DIR >> $LOG_FILE 2>&1
|
||||
|
|
@ -115,7 +115,7 @@ cat <<EOF > $CONFIG_DIR/lamassu.json
|
|||
],
|
||||
"idPhotoCardDir": "$IDPHOTOCARD_DIR",
|
||||
"frontCameraDir": "$FRONTCAMERA_DIR",
|
||||
"idCardDataDir": "$IDCARDDATA_DIR"
|
||||
"operatorDataDir": "$OPERATOR_DIR"
|
||||
}
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -15,5 +15,5 @@
|
|||
},
|
||||
"idPhotoCardDir": "/opt/lamassu-server/idphotocard",
|
||||
"frontCameraDir": "/opt/lamassu-server/frontcamera",
|
||||
"idCardDataDir": "/opt/lamassu-server/idcarddata"
|
||||
"operatorDataDir": "/opt/lamassu-server/operatordata"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ BLOCKCHAIN_DIR=/mnt/blockchains
|
|||
OFAC_DATA_DIR=/var/lamassu/ofac
|
||||
ID_PHOTO_CARD_DIR=/opt/lamassu-server/idphotocard
|
||||
FRONTCAMERA_DIR=/opt/lamassu-server/frontcamera
|
||||
IDCARDDATA_DIR=/opt/lamassu-server/idcarddata
|
||||
OPERATOR_DIR=/opt/lamassu-server/operatordata
|
||||
|
||||
# Look into http://unix.stackexchange.com/questions/140734/configure-localtime-dpkg-reconfigure-tzdata
|
||||
|
||||
|
|
@ -184,7 +184,7 @@ cat <<EOF > $CONFIG_DIR/lamassu.json
|
|||
"ofacDataDir": "$OFAC_DATA_DIR",
|
||||
"idPhotoCardDir": "$ID_PHOTO_CARD_DIR",
|
||||
"frontCameraDir": "$FRONTCAMERA_DIR",
|
||||
"idCardDataDir": "$IDCARDDATA_DIR"
|
||||
"operatorDataDir": "$OPERATOR_DIR"
|
||||
"strike": {
|
||||
"baseUrl": "https://api.strike.acinq.co/api/"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ const NEVER = new Date(Date.now() + 100 * T.years)
|
|||
const REAUTHENTICATE_INTERVAL = T.minute
|
||||
const idPhotoCardBasedir = _.get('idPhotoCardDir', options)
|
||||
const frontCameraBasedir = _.get('frontCameraDir', options)
|
||||
const operatorDataBasedir = _.get('operatorDataDir', options)
|
||||
|
||||
const devMode = argv.dev
|
||||
|
||||
|
|
@ -236,8 +237,13 @@ if (!fs.existsSync(frontCameraBasedir)) {
|
|||
makeDir.sync(frontCameraBasedir)
|
||||
}
|
||||
|
||||
if (!fs.existsSync(operatorDataBasedir)) {
|
||||
makeDir.sync(operatorDataBasedir)
|
||||
}
|
||||
|
||||
app.use('/id-card-photo', serveStatic(idPhotoCardBasedir, {index: false}))
|
||||
app.use('/front-camera-photo', serveStatic(frontCameraBasedir, {index: false}))
|
||||
app.use('/operator-data', serveStatic(operatorDataBasedir, {index: false}))
|
||||
|
||||
function register (req, res, next) {
|
||||
const otp = req.query.otp
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ const notifierUtils = require('./notifier/utils')
|
|||
const NUM_RESULTS = 1000
|
||||
const idPhotoCardBasedir = _.get('idPhotoCardDir', options)
|
||||
const frontCameraBaseDir = _.get('frontCameraDir', options)
|
||||
const idCardDataDir = _.get('idCardDataDir', options)
|
||||
const operatorDataDir = _.get('operatorDataDir', options)
|
||||
|
||||
/**
|
||||
* Add new customer
|
||||
|
|
@ -576,51 +576,36 @@ function updatePhotoCard (id, patch) {
|
|||
* @param {String} directory directory path of id card data for a certain user
|
||||
*/
|
||||
|
||||
function updatePhoto (imageData, directory) {
|
||||
return Promise.resolve(imageData)
|
||||
function updatePhotos (imagesData, id, dir) {
|
||||
return Promise.resolve(imagesData)
|
||||
.then(patch => {
|
||||
if (_.isEmpty(imageData)) {
|
||||
if (_.isEmpty(imagesData)) {
|
||||
return patch
|
||||
}
|
||||
|
||||
const newPatch = {
|
||||
idCardDataPath: ''
|
||||
}
|
||||
|
||||
// decode the base64 string to binary data
|
||||
const decodedImageData = Buffer.from(imageData, 'base64')
|
||||
|
||||
// workout the image hash
|
||||
// i.e. 240e85ff2e4bb931f235985dd0134e459239496d2b5af6c5665168d38ef89b50
|
||||
const hash = crypto
|
||||
.createHash('sha256')
|
||||
.update(imageData)
|
||||
.digest('hex')
|
||||
|
||||
// workout the image folder
|
||||
// i.e. 24/0e/85
|
||||
const rpath = _.join(path.sep, _.map(_.wrap(_.join, ''), _.take(3, _.chunk(2, _.split('', hash)))))
|
||||
|
||||
// i.e. ../<lamassu-server-home>/idcardphoto/customer_id/24/0e/85
|
||||
const dirname = path.join(directory, rpath)
|
||||
|
||||
const newPatch = {}
|
||||
// i.e. ../<lamassu-server-home>/<operatorid>/<customerid>/idcarddata
|
||||
console.log(dir, 'directoryyyy')
|
||||
const dirname = path.join(dir)
|
||||
console.log(dirname, 'dirnaaaaaaaaaaaaaaame')
|
||||
// create the directory tree if needed
|
||||
_.attempt(() => makeDir.sync(dirname))
|
||||
const promises = imagesData.map((imageData, index) => {
|
||||
console.log(index)
|
||||
// decode the base64 string to binary data
|
||||
const decodedImageData = Buffer.from(imageData, 'base64')
|
||||
|
||||
// i.e. ../<lamassu-server-home>/idcardphoto/customer_id/24/0e/85/240e85ff2e4bb931f235985dd01....jpg
|
||||
const filename = path.join(dirname, hash + '.jpg')
|
||||
// i.e. ../<lamassu-server-home>/<operatorid>/<customerid>/idcarddata/1.jpg
|
||||
const filename = path.join(dirname, index + '.jpg')
|
||||
|
||||
//
|
||||
// i.e. {
|
||||
// "idCardDataPath": "24/0e/85/240e85ff2e4bb931f235985dd01....jpg",
|
||||
// "idCardDataAt": "now()"
|
||||
// }
|
||||
newPatch.idCardData = path.join(rpath)
|
||||
newPatch.idCardDataAt = 'now()'
|
||||
return writeFile(filename, decodedImageData)
|
||||
})
|
||||
|
||||
// write image file
|
||||
return writeFile(filename, decodedImageData)
|
||||
.then(() => newPatch)
|
||||
return Promise.all(promises)
|
||||
.then(arr => {
|
||||
newPatch.idCardData = path.join(dirname)
|
||||
newPatch.idCardDataAt = 'now()'
|
||||
return newPatch
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -630,15 +615,16 @@ function updatePhoto (imageData, directory) {
|
|||
* @returns {Promise<Object>} new patch to be applied
|
||||
*/
|
||||
function updateIdCardData (patch, id) {
|
||||
const directory = idCardDataDir + '/' + id
|
||||
/* TODO: fetch operator id */
|
||||
const operatorId = 'id-operator'
|
||||
const directory = operatorDataDir + '/' + operatorId + '/' + id + '/'
|
||||
console.log(directory)
|
||||
return Promise.resolve(patch)
|
||||
.then(patch => {
|
||||
const imagesData = _.get('photos', patch)
|
||||
_.map(imageData => {
|
||||
return updatePhoto(imageData, directory)
|
||||
.then(newPatch => newPatch)
|
||||
.catch(err => console.log('An error ocurred while saving the image ', err))
|
||||
}, imagesData)
|
||||
return updatePhotos(imagesData, id, directory)
|
||||
.then(newPatch => newPatch)
|
||||
.catch(err => console.log('An error ocurred while saving the image ', err))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -103,6 +103,6 @@ router.patch('/:id', updateCustomer)
|
|||
router.patch('/:id/sanctions', triggerSanctions)
|
||||
router.patch('/:id/block', triggerBlock)
|
||||
router.patch('/:id/suspend', triggerSuspend)
|
||||
router.patch('/:id/cardphotos', updateIdCardData)
|
||||
router.patch('/:id/dataphotos', updateIdCardData)
|
||||
|
||||
module.exports = router
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue