feat: 增加机器位置手动编辑功能及公开查看界面
This commit is contained in:
+14
-10
@@ -163,27 +163,31 @@ router.get('/check-update', (req, res) => {
|
||||
res.json({ update_counter: globalUpdateCounter });
|
||||
});
|
||||
|
||||
router.post('/machine-location', (req, res) => {
|
||||
router.post('/machine-location', async (req, res) => {
|
||||
const data = req.body || {};
|
||||
if (!data.device_id) return res.status(400).json({ ok: false, error: 'device_id required' });
|
||||
if (!data.station && data.station_code) {
|
||||
data.station = resolveStationName(data.station_code);
|
||||
}
|
||||
DataService.updateMachineLocation(data.device_id, data);
|
||||
await DataService.updateMachineLocation(data.device_id, data);
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
router.get('/machine-locations', (req, res) => {
|
||||
const locs = DataService.getMachineLocations() || {};
|
||||
// clean up old locations (> 5 minutes)
|
||||
const now = Date.now();
|
||||
const active = {};
|
||||
for (const [id, data] of Object.entries(locs)) {
|
||||
if (now - data.last_update_ts < 5 * 60 * 1000) {
|
||||
active[id] = data;
|
||||
}
|
||||
res.json({ ok: true, data: locs });
|
||||
});
|
||||
|
||||
router.put('/machine-location/:id', async (req, res) => {
|
||||
const id = req.params.id;
|
||||
const data = req.body || {};
|
||||
const current = DataService.getMachineLocations()[id];
|
||||
if (!current) return res.status(404).json({ ok: false, error: 'machine not found' });
|
||||
if (!data.station && data.station_code) {
|
||||
data.station = resolveStationName(data.station_code);
|
||||
}
|
||||
res.json({ ok: true, data: active });
|
||||
await DataService.updateMachineLocation(id, data);
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
// Config
|
||||
|
||||
Reference in New Issue
Block a user