From 953360d25114ea7efd0aaf34296504358e16a35f Mon Sep 17 00:00:00 2001 From: cclohmar Date: Mon, 10 Aug 2026 07:03:31 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20real=20camera=20online=20status=20?= =?UTF-8?q?=E2=80=94=20checks=20latest.jpg=20modification=20time?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.go | 22 ++++++++++++++++++++-- public/app.js | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/api.go b/api.go index d107dc6..8b96def 100644 --- a/api.go +++ b/api.go @@ -13,6 +13,7 @@ import ( "net/http/httputil" "net/url" "os" + "path/filepath" "strings" "time" ) @@ -27,9 +28,19 @@ func (s *Server) handleCameras(w http.ResponseWriter, r *http.Request) { statuses := make([]CameraStatus, 0, len(s.appConfig.Cameras)) for _, cam := range s.appConfig.Cameras { + online := false + // Check if latest.jpg was recently updated. + camDir := cam.Name + if camDir == "" { + camDir = cam.ID + } + snapFile := filepath.Join(s.appConfig.Storage.RecordingsPath, camDir, "latest.jpg") + if info, err := os.Stat(snapFile); err == nil { + online = time.Since(info.ModTime()) < 10*time.Second + } statuses = append(statuses, CameraStatus{ CameraConfig: cam, - Online: false, // TODO: real stream health check in M2 + Online: online, Uptime: "n/a", Streams: 0, }) @@ -56,9 +67,16 @@ func (s *Server) handleCameraByID(w http.ResponseWriter, r *http.Request) { switch r.Method { case http.MethodGet: + online := false + camDir := cam.Name + if camDir == "" { camDir = cam.ID } + snapFile := filepath.Join(s.appConfig.Storage.RecordingsPath, camDir, "latest.jpg") + if info, err := os.Stat(snapFile); err == nil { + online = time.Since(info.ModTime()) < 10*time.Second + } status := CameraStatus{ CameraConfig: *cam, - Online: false, + Online: online, Uptime: "n/a", Streams: 0, } diff --git a/public/app.js b/public/app.js index 97b5203..1512aa3 100644 --- a/public/app.js +++ b/public/app.js @@ -104,7 +104,7 @@ function renderLiveGrid() { ${cam.name} - + ${cam.name} `; tile.addEventListener('click', () => openFocus(cam));