DISPLAY AND DOWNLOAD LOGS

This commit is contained in:
BIG2EYEZ
2024-01-01 17:08:02 +08:00
parent e538a5fb6e
commit 7cc372497b
7 changed files with 525 additions and 351 deletions

View File

@ -722,7 +722,28 @@ app.get('/api/users', (req, res) => {
});
}
app.get('/api/getLogs', (req, res) => {
// Query the database to fetch logs
const query = 'SELECT id, username, activity, timestamp FROM user_logs';
connection.query(query, (err, results) => {
if (err) {
console.error('Error fetching logs from MySQL:', err);
res.status(500).json({ error: 'Error fetching logs from MySQL' });
return;
}
// Format timestamps to a more readable format
const formattedLogs = results.map((log) => ({
id: log.id,
username: log.username,
activity: log.activity,
timestamp: new Date(log.timestamp).toLocaleString('en-US', { timeZone: 'Asia/Singapore' }),
}));
// Send the formatted logs as a JSON response
res.json(formattedLogs);
});
});
app.use(express.static("views"));