A
This commit is contained in:
parent
9f01d52b31
commit
a0bef1245c
|
|
@ -7,6 +7,17 @@ router.post('/', global.auth, async (req, res) => {
|
||||||
if (!serverId || totalPlayers === undefined || duration === undefined) {
|
if (!serverId || totalPlayers === undefined || duration === undefined) {
|
||||||
return res.status(400).json({ error: 'Missing required fields' });
|
return res.status(400).json({ error: 'Missing required fields' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db.get('SELECT * FROM analytics WHERE id = ?', [serverId], (err, row) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('Failed to find server for heartbeat', err);
|
||||||
|
return res.status(500).json({ error: 'Database error' });
|
||||||
|
}
|
||||||
|
if (!row) {
|
||||||
|
return res.status(404).json({ error: 'Server not found' });
|
||||||
|
}
|
||||||
|
console.log(`Recording heartbeat: ${serverId} with ${JSON.stringify(totalPlayers)} players and duration ${duration}`);
|
||||||
|
|
||||||
const nextHeartbeat = Date.now() + ((parseInt(process.env.MAX_HEARTBEAT, 10) || 60) * 1000);
|
const nextHeartbeat = Date.now() + ((parseInt(process.env.MAX_HEARTBEAT, 10) || 60) * 1000);
|
||||||
db.run(
|
db.run(
|
||||||
'UPDATE analytics SET serverDuration = ?, allPlayers = ?, heartbeatCheck = ? WHERE id = ?',
|
'UPDATE analytics SET serverDuration = ?, allPlayers = ?, heartbeatCheck = ? WHERE id = ?',
|
||||||
|
|
@ -19,6 +30,7 @@ router.post('/', global.auth, async (req, res) => {
|
||||||
return res.status(200).json({ message: 'Heartbeat data recorded' });
|
return res.status(200).json({ message: 'Heartbeat data recorded' });
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
Loading…
Reference in a new issue