feat: reject requests from incompatible machines
This commit is contained in:
parent
737672c07a
commit
1830f90c2c
5 changed files with 31 additions and 19 deletions
24
lib/middlewares/rejectIncompatbleMachines.js
Normal file
24
lib/middlewares/rejectIncompatbleMachines.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
const semver = require('semver')
|
||||
const version = require('../../package.json').version
|
||||
const logger = require('../logger')
|
||||
|
||||
const rejectIncompatibleMachines = function (req, res, next) {
|
||||
const machineVersion = req.query.version
|
||||
const deviceId = req.deviceId
|
||||
|
||||
if (!machineVersion) return next()
|
||||
|
||||
const serverMajor = semver.major(version)
|
||||
const machineMajor = semver.major(machineVersion)
|
||||
|
||||
if (serverMajor - machineMajor > 1) {
|
||||
logger.error(`Machine version too old: ${machineVersion} deviceId: ${deviceId}`)
|
||||
return res.status(400).json({
|
||||
error: 'Machine version too old'
|
||||
})
|
||||
}
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
module.exports = rejectIncompatibleMachines
|
||||
Loading…
Add table
Add a link
Reference in a new issue