v12.0.0 - initial commit
This commit is contained in:
commit
e2c49ea43c
1145 changed files with 97211 additions and 0 deletions
25
packages/server/lib/middlewares/populateMachineSettings.js
Normal file
25
packages/server/lib/middlewares/populateMachineSettings.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
const machineSettings = require('../machine-settings')
|
||||
|
||||
const getMachineVersion = machineVersion => {
|
||||
if (!machineVersion) return null
|
||||
machineVersion = parseInt(machineVersion, 10)
|
||||
return isNaN(machineVersion) ? null : machineVersion
|
||||
}
|
||||
|
||||
const populateMachineSettings = (req, res, next) => {
|
||||
const deviceId = req.deviceId
|
||||
const machineVersion = getMachineVersion(req.headers['settings-version'])
|
||||
machineSettings
|
||||
.getOrUpdate(deviceId, machineVersion)
|
||||
.then(settings => {
|
||||
if (!settings)
|
||||
return next(
|
||||
new Error(`No cached settings found for machine ${deviceId}`),
|
||||
)
|
||||
req.machineSettings = settings
|
||||
next()
|
||||
})
|
||||
.catch(err => next(err))
|
||||
}
|
||||
|
||||
module.exports = populateMachineSettings
|
||||
Loading…
Add table
Add a link
Reference in a new issue