From 3e1b36714793b25bf063cb3a76eeaa019749f3e1 Mon Sep 17 00:00:00 2001 From: ila <2+ila@noreply.git.ilapage.cn> Date: Thu, 13 Aug 2026 12:42:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E5=BB=BA=E7=AB=8B?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E7=9B=91=E7=9C=8B=E5=AA=92=E4=BD=93=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=20(#51)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sense/server/app/sense/admission/service.go | 33 +++++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/Sense/server/app/sense/admission/service.go b/Sense/server/app/sense/admission/service.go index 674ce1f..e2dfe23 100644 --- a/Sense/server/app/sense/admission/service.go +++ b/Sense/server/app/sense/admission/service.go @@ -24,22 +24,35 @@ type Profile struct { Verification rtsp.Result `json:"verification"` } type Result struct { - DeviceID string `json:"device_id"` - Address string `json:"address"` - Status string `json:"status"` - Detail string `json:"detail"` - Profiles []Profile `json:"profiles"` - CheckedAt time.Time `json:"checked_at"` + DeviceID string `json:"device_id"` + Address string `json:"address"` + Status string `json:"status"` + Detail string `json:"detail"` + Profiles []Profile `json:"profiles"` + MediaStatus string `json:"media_status,omitempty"` + MediaDetail string `json:"media_detail,omitempty"` + CheckedAt time.Time `json:"checked_at"` } + +type MediaOutcome struct { + Status string + Detail string +} + +type ReadyHandler func(context.Context, identity.Principal, Result) MediaOutcome + type Service struct { onvif onvif.Client rtsp rtsp.Verifier discoveryIP string discoveryTimeout time.Duration store Store + readyHandler ReadyHandler now func() time.Time } +func (s *Service) SetReadyHandler(handler ReadyHandler) { s.readyHandler = handler } + func NewService(client onvif.Client, verifier rtsp.Verifier, discoveryIP string, stores ...Store) *Service { var store Store = NewMemoryStore() if len(stores) > 0 && stores[0] != nil { @@ -106,6 +119,14 @@ func (s *Service) Probe(ctx context.Context, actor identity.Principal, deviceID, break } } + if s.readyHandler != nil { + outcome := s.readyHandler(ctx, actor, result) + result.MediaStatus = outcome.Status + result.MediaDetail = outcome.Detail + if err := s.store.Save(ctx, result); err != nil { + return Result{}, err + } + } identity.RecordAudit(ctx, actor.UserID, "admission.probe", deviceID, "success", map[string]any{"profile_count": len(items), "status": status}) return result, nil }