chore: use monorepo organization
This commit is contained in:
parent
deaf7d6ecc
commit
a687827f7e
1099 changed files with 8184 additions and 11535 deletions
34
packages/server/lib/routes/logsRoutes.js
Normal file
34
packages/server/lib/routes/logsRoutes.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
const express = require('express')
|
||||
const router = express.Router()
|
||||
|
||||
const state = require('../middlewares/state')
|
||||
const logs = require('../logs')
|
||||
|
||||
const THROTTLE_LOGS_QUERY = 30 * 1000
|
||||
|
||||
function getLastSeen (req, res, next) {
|
||||
const deviceId = req.deviceId
|
||||
const timestamp = Date.now()
|
||||
const shouldTrigger = !state.canGetLastSeenMap[deviceId] ||
|
||||
timestamp - state.canGetLastSeenMap[deviceId] >= THROTTLE_LOGS_QUERY
|
||||
|
||||
if (shouldTrigger) {
|
||||
state.canGetLastSeenMap[deviceId] = timestamp
|
||||
return logs.getLastSeen(deviceId)
|
||||
.then(r => res.json(r))
|
||||
.catch(next)
|
||||
}
|
||||
|
||||
return res.status(408).json({})
|
||||
}
|
||||
|
||||
function updateLogs (req, res, next) {
|
||||
return logs.update(req.deviceId, req.body.logs)
|
||||
.then(status => res.json({ success: status }))
|
||||
.catch(next)
|
||||
}
|
||||
|
||||
router.get('/', getLastSeen)
|
||||
router.post('/', updateLogs)
|
||||
|
||||
module.exports = router
|
||||
Loading…
Add table
Add a link
Reference in a new issue