This commit is contained in:
metacryst
2026-01-13 17:24:52 -06:00
parent c3f0d8d70d
commit adf25488e4
9 changed files with 47 additions and 160 deletions

View File

@@ -1,10 +1,28 @@
import path from 'path'
import fs from 'fs'
import { broadcast } from './ws.js';
const CSV_PATH = path.join(process.cwd(), 'db/logs.csv')
function appendToCSV(row) {
const exists = fs.existsSync(CSV_PATH)
const header = 'name,latitude,longitude,timestamp\n'
const line = `${row.name},${row.latitude},${row.longitude},${row.timestamp}\n`
if (!exists) {
fs.appendFileSync(CSV_PATH, header + line, 'utf8')
} else {
fs.appendFileSync(CSV_PATH, line, 'utf8')
}
}
const handlers = {
updateLocation(req, res) {
const { name, latitude, longitude, timestamp } = req.body;
console.log(`Received location: (${name}, ${latitude}, ${longitude}) at ${timestamp}`);
broadcast("update-location", { name, latitude, longitude, timestamp });
appendToCSV({ name, latitude, longitude, timestamp })
res.json({ success: true });
},