doppelt senden unterbinden. CSV
This commit is contained in:
@@ -149,6 +149,7 @@ app.post('/api/send', (req, res) => {
|
||||
console.log(`G0 ${arrayMsg[1].toUpperCase()} F1000 gesendet`);
|
||||
}
|
||||
*/
|
||||
return res.json({ ok: true, sent: msg.payload});
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -186,6 +187,35 @@ app.get('/api/events', (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Neuester Snapshot-Endpunkt
|
||||
app.get('/api/latest-snapshot', (req, res) => {
|
||||
const snapshotsDir = path.join(path.resolve('public'), 'snapshots');
|
||||
fs.readdir(snapshotsDir, (err, files) => {
|
||||
if (err) {
|
||||
return res.status(500).json({ error: 'Fehler beim Lesen des Snapshots-Verzeichnisses' });
|
||||
}
|
||||
const csvFiles = files.filter(file => file.endsWith('.csv')).map(file => ({
|
||||
name: file,
|
||||
path: path.join(snapshotsDir, file),
|
||||
mtime: fs.statSync(path.join(snapshotsDir, file)).mtime
|
||||
})).sort((a, b) => b.mtime - a.mtime);
|
||||
if (csvFiles.length === 0) {
|
||||
return res.status(404).json({ error: 'Keine CSV-Dateien gefunden' });
|
||||
}
|
||||
const latestFile = csvFiles[0];
|
||||
fs.readFile(latestFile.path, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
return res.status(500).json({ error: 'Fehler beim Lesen der Datei' });
|
||||
}
|
||||
res.json({
|
||||
filename: latestFile.name,
|
||||
mtime: latestFile.mtime.toISOString(),
|
||||
content: data
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Statisches Frontend
|
||||
app.use('/', express.static(path.resolve('public')));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user