CSV funktionert
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user