This commit is contained in:
Josh Harvey 2016-12-09 01:03:33 +02:00
parent 1b89ed5c76
commit 2355054cdc
3 changed files with 20 additions and 21 deletions

View file

@ -153,13 +153,11 @@ function ca (req, res) {
}
function pair (req, res, next) {
console.log('DEBUG100')
const token = req.query.token
const deviceId = req.deviceId
return pairing.pair(token, deviceId)
.then(valid => {
console.log('DEBUG102')
if (valid) return res.end()
throw httpError('Pairing failed')
})
@ -422,14 +420,22 @@ function populateDeviceId (req, res, next) {
}
function populateSettings (req, res, next) {
if (req.query.force_config === 'true') {
return settingsLoader.loadLatest()
.then(settings => { req.settings = settings })
.then(() => next())
.catch(next)
}
const versionId = req.headers['config-version']
if (!versionId) {
logger.debug('No config-version header')
return res.sendStatus(400)
}
settingsLoader.log(versionId)
settingsLoader.load(versionId)
.then(settings => { req.settings = settings })
.then(() => helpers.updateDeviceConfigVersion(versionId))
.then(() => next())
.catch(next)
}