generated from CubeCraft-Creations/Tracehound
hub: fix camera listing, heartbeat parse, and legacy-id migration
Three bugs surfaced once the camera reported in:
- ListCameras LEFT JOIN returns NULL status columns for a camera with no
status rows yet, which failed scanning into non-nullable int/time fields
(recording_state, online, recorded_at) and emptied the whole list.
COALESCE them (recorded_at falls back to the camera's created_at).
- handleHeartbeat rejected every heartbeat ("cannot unmarshal number into
string") because the node sends a numeric millis() timestamp. The handler
doesn't use it, so drop the Timestamp field and let it be ignored.
- handleAnnounce kept a stale cam-NNN row registered by MAC under the old
(pre-self-id) scheme, so self-id status inserts hit a FOREIGN KEY error.
When a MAC is known under a different id than the node's self-id, migrate:
drop the old row and re-register under the self-id.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -26,12 +26,12 @@ func ListCameras(database *db.DB) http.HandlerFunc {
|
||||
c.friendly_name,
|
||||
s.battery_pct,
|
||||
s.video_remaining_sec,
|
||||
s.recording_state,
|
||||
COALESCE(s.recording_state, 0),
|
||||
s.mode,
|
||||
s.resolution,
|
||||
s.fps,
|
||||
s.online,
|
||||
s.recorded_at
|
||||
COALESCE(s.online, 0),
|
||||
COALESCE(s.recorded_at, c.created_at)
|
||||
FROM cameras c
|
||||
LEFT JOIN (
|
||||
SELECT camera_id, battery_pct, video_remaining_sec, recording_state,
|
||||
|
||||
Reference in New Issue
Block a user