format for latest standard
This commit is contained in:
parent
4108efd9c7
commit
c2af183911
77 changed files with 1697 additions and 1693 deletions
|
|
@ -38,43 +38,43 @@ function removeDeviceConfig (deviceId) {
|
|||
function unpair (deviceId) {
|
||||
const sql = 'delete from devices where device_id=$1'
|
||||
return db.none(sql, [deviceId])
|
||||
.then(() => removeDeviceConfig(deviceId))
|
||||
.then(() => removeDeviceConfig(deviceId))
|
||||
}
|
||||
|
||||
function pair (token, deviceId, machineModel) {
|
||||
return pullToken(token)
|
||||
.then(r => {
|
||||
if (r.expired) return false
|
||||
.then(r => {
|
||||
if (r.expired) return false
|
||||
|
||||
const insertSql = `insert into devices (device_id, name) values ($1, $2)
|
||||
const insertSql = `insert into devices (device_id, name) values ($1, $2)
|
||||
on conflict (device_id)
|
||||
do update set paired=TRUE, display=TRUE`
|
||||
|
||||
return configureNewDevice(deviceId, r.name, machineModel)
|
||||
.then(() => db.none(insertSql, [deviceId, r.name]))
|
||||
.then(() => true)
|
||||
})
|
||||
.catch(err => {
|
||||
logger.debug(err)
|
||||
return false
|
||||
})
|
||||
return configureNewDevice(deviceId, r.name, machineModel)
|
||||
.then(() => db.none(insertSql, [deviceId, r.name]))
|
||||
.then(() => true)
|
||||
})
|
||||
.catch(err => {
|
||||
logger.debug(err)
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
function authorizeCaDownload (caToken) {
|
||||
return pullToken(caToken)
|
||||
.then(r => {
|
||||
if (r.expired) throw new Error('Expired')
|
||||
.then(r => {
|
||||
if (r.expired) throw new Error('Expired')
|
||||
|
||||
const caPath = options.caPath
|
||||
return readFile(caPath, {encoding: 'utf8'})
|
||||
})
|
||||
const caPath = options.caPath
|
||||
return readFile(caPath, {encoding: 'utf8'})
|
||||
})
|
||||
}
|
||||
|
||||
function isPaired (deviceId) {
|
||||
const sql = 'select device_id from devices where device_id=$1 and paired=TRUE'
|
||||
|
||||
return db.oneOrNone(sql, [deviceId])
|
||||
.then(row => row && row.device_id === deviceId)
|
||||
.then(row => row && row.device_id === deviceId)
|
||||
}
|
||||
|
||||
module.exports = {pair, unpair, authorizeCaDownload, isPaired}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue