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