CSV funktionert

This commit is contained in:
ChK
2026-04-05 07:51:37 +02:00
parent 74ae3f2bf8
commit d2096eca70
4 changed files with 156 additions and 2 deletions

View File

@@ -185,6 +185,10 @@ app.get('/api/events', (req, res) => {
});
});
//snapshot_video0_1775319258906_two_cam.csv
//snapshot_video0_1775319258906_two_cam_annotated.jpg
// Neuester Snapshot-Endpunkt
app.get('/api/latest-snapshot', (req, res) => {
const snapshotsDir = path.join(path.resolve('public'), 'snapshots');
@@ -197,18 +201,35 @@ app.get('/api/latest-snapshot', (req, res) => {
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];
const baseName = path.basename(latestFile.name, path.extname(latestFile.name));
const imageFilename = `${baseName}_annotated.jpg`;
const imagePath = path.join(snapshotsDir, imageFilename);
fs.readFile(latestFile.path, 'utf8', (err, data) => {
if (err) {
return res.status(500).json({ error: 'Fehler beim Lesen der Datei' });
}
res.json({
const response = {
filename: latestFile.name,
mtime: latestFile.mtime.toISOString(),
content: data
};
fs.readFile(imagePath, { encoding: 'base64' }, (jpgErr, jpgBase64) => {
if (!jpgErr && jpgBase64) {
response.imageFile = {
filename: imageFilename,
mimeType: 'image/jpeg',
contentBase64: jpgBase64
};
}
res.json(response);
});
});
});