47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
const express = require('express');
|
|
const http = require('http');
|
|
const WebSocket = require('ws');
|
|
const axios = require('axios');
|
|
|
|
const app = express();
|
|
const server = http.createServer(app);
|
|
const wss = new WebSocket.Server({ server });
|
|
|
|
let logCache = new Set();
|
|
|
|
app.use(express.static('public'));
|
|
|
|
wss.on('connection', (ws) => {
|
|
console.log('Client connected');
|
|
});
|
|
|
|
setInterval(async () => {
|
|
try {
|
|
const response = await axios.post('https://vmselect.riff.cc/select/logsql/query', 'query=_time:5s relay received');
|
|
const logs = response.data.data; // Assuming the logs are in response.data.data
|
|
console.log('Logs response:', logs);
|
|
|
|
if (Array.isArray(logs)) {
|
|
logs.forEach(log => {
|
|
const logIdentifier = `${log.msg_hash}-${log.receivedTime}`;
|
|
if (!logCache.has(logIdentifier)) {
|
|
logCache.add(logIdentifier);
|
|
wss.clients.forEach(client => {
|
|
if (client.readyState === WebSocket.OPEN) {
|
|
client.send(JSON.stringify(log));
|
|
}
|
|
});
|
|
}
|
|
});
|
|
} else {
|
|
console.error('Logs response is not an array:', logs);
|
|
}
|
|
} catch (error) {
|
|
console.error('Error querying logs:', error);
|
|
}
|
|
}, 3000);
|
|
|
|
server.listen(3000, () => {
|
|
console.log('Server is listening on port 3000');
|
|
});
|