diff --git a/.gitignore b/.gitignore index 08e5eea..6510dbd 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ config.js database.sqlite config.js test/.devKeys -config_prod.js \ No newline at end of file +config_prod.js +database - copy.sqlite \ No newline at end of file diff --git a/controllers/devices.js b/controllers/devices.js index 83daf31..248b5b6 100644 --- a/controllers/devices.js +++ b/controllers/devices.js @@ -19,7 +19,12 @@ async function pairDevice(account, qr_string) { } else { pairJWT = qr_string; const data = await authenticationController.readJWT(qr_string); - deviceQuery = await models_orm.models.device.findOne({ where: { dongle_id: data.identiy }}); + if (data.pair === true) { + deviceQuery = await models_orm.models.device.findOne({ where: { dongle_id: data.identiy }}); + } else{ + return {success: false, noPair: true} + } + } diff --git a/routes/api.js b/routes/api.js index cdbddf3..95e7991 100644 --- a/routes/api.js +++ b/routes/api.js @@ -106,7 +106,7 @@ router.get('/v1.1/devices/:dongleId/', runAsyncWrapper(async (req, res) => { return res.send('Unauthorized.').status(400) } - let response={'is_paired': (device.account_id>0 ? true : false), 'prime': (device.account_id>0 ? true : false)}; + let response={'is_paired': (device.account_id !== 0 ? true : false), 'prime': (device.account_id>0 ? true : false)}; logger.info("HTTP.DEVICES for " + req.params.dongleId + " returning: "+JSON.stringify(response)); res.status(200); @@ -215,9 +215,7 @@ router.get('/v1/devices/:dongleId/owner', runAsyncWrapper(async (req, res) => { res.json(response); })) - -// DRIVE & BOOT/CRASH LOG FILE UPLOAD URL REQUEST -router.get('/v1.3/:dongleId/upload_url/', runAsyncWrapper(async (req, res) => { +async function upload(req,res) { var path = req.query.path; const dongleId = req.params.dongleId; const auth = req.headers.authorization; @@ -347,7 +345,12 @@ router.get('/v1.3/:dongleId/upload_url/', runAsyncWrapper(async (req, res) => { res.status(400); res.send('Malformed Request.'); } -})) +} + + +// DRIVE & BOOT/CRASH LOG FILE UPLOAD URL REQUEST +router.get('/v1.3/:dongleId/upload_url/', upload) +router.get('/v1.4/:dongleId/upload_url/', upload) // DEVICE REGISTRATION OR RE-ACTIVATION diff --git a/routes/userAdminApi.js b/routes/userAdminApi.js index abeae04..0ef9d7c 100644 --- a/routes/userAdminApi.js +++ b/routes/userAdminApi.js @@ -218,7 +218,7 @@ router.post('/retropilot/0/pair_device', bodyParser.urlencoded({extended: true}) res.json({success: false, msg: 'UNAUTHORISED', status: 403}) } - const pairDevice = await controllers.devices.pairDevice(req.body.qr_string); + const pairDevice = await controllers.devices.pairDevice(account, req.body.qr_string); if (pairDevice.success === true) { res.json({success: true, msg: 'Paired', status: 200, data: pairDevice})