From 8a40e85866fa6fa7b8e6680428791cc0cb097ca1 Mon Sep 17 00:00:00 2001 From: ila <2+ila@noreply.git.ilapage.cn> Date: Thu, 13 Aug 2026 12:42:08 +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/liveview/service.go | 44 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/Sense/server/app/sense/liveview/service.go b/Sense/server/app/sense/liveview/service.go index 101ee80..dc412a4 100644 --- a/Sense/server/app/sense/liveview/service.go +++ b/Sense/server/app/sense/liveview/service.go @@ -10,15 +10,34 @@ import ( "sync" "time" + "yovision.local/sense/app/sense/admission" + "yovision.local/sense/app/sense/device" "yovision.local/sense/app/sense/media" ) +type Route struct { + ID string `json:"id"` + DeviceID string `json:"device_id"` + DeviceName string `json:"device_name"` + DeviceLocation string `json:"device_location"` + ProfileToken string `json:"profile_token"` + ProfileName string `json:"profile_name"` + ProfileKind string `json:"profile_kind"` + Desired string `json:"desired"` + Actual string `json:"actual"` + Detail string `json:"detail"` + Readers int `json:"readers"` +} + type Session struct { ID string `json:"id"` OwnerID string `json:"-"` RouteID string `json:"route_id"` DeviceID string `json:"device_id"` + DeviceName string `json:"device_name"` ProfileToken string `json:"profile_token"` + ProfileName string `json:"profile_name"` + ProfileKind string `json:"profile_kind"` PlayerURL string `json:"player_url"` Status string `json:"status"` Detail string `json:"detail"` @@ -47,15 +66,24 @@ func NewService(rawBase string, ttl time.Duration) (*Service, error) { } return &Service{base: parsed, ttl: ttl, route: media.PlaybackRoute, routes: media.PlaybackRoutes, sessions: map[string]Session{}, now: time.Now}, nil } -func (s *Service) Routes(ctx context.Context) ([]media.Route, error) { +func (s *Service) Routes(ctx context.Context) ([]Route, error) { items, err := s.routes(ctx) if err != nil { return nil, err } - result := items[:0] + result := make([]Route, 0, len(items)) for _, item := range items { if item.Desired == "running" { - result = append(result, item) + view := Route{ID: item.ID, DeviceID: item.DeviceID, DeviceName: item.DeviceID, ProfileToken: item.ProfileToken, ProfileName: item.ProfileToken, Desired: item.Desired, Actual: item.Actual, Detail: item.Detail, Readers: item.Readers} + if info, describeErr := device.Describe(ctx, item.DeviceID); describeErr == nil { + view.DeviceName = info.Name + view.DeviceLocation = info.Location + } + if profile, profileErr := admission.VerifiedProfile(item.DeviceID, item.ProfileToken); profileErr == nil { + view.ProfileName = profile.Name + view.ProfileKind = profile.Kind + } + result = append(result, view) } } return result, nil @@ -69,7 +97,14 @@ func (s *Service) Create(ctx context.Context, owner, routeID string) (Session, e return Session{}, fmt.Errorf("media route is stopped") } id := newID() - session := Session{ID: id, OwnerID: owner, RouteID: route.ID, DeviceID: route.DeviceID, ProfileToken: route.ProfileToken, PlayerURL: "/api/v1/liveview/sessions/" + id + "/player", Status: route.Actual, Detail: route.Detail, ExpiresAt: s.now().UTC().Add(s.ttl)} + session := Session{ID: id, OwnerID: owner, RouteID: route.ID, DeviceID: route.DeviceID, DeviceName: route.DeviceID, ProfileToken: route.ProfileToken, ProfileName: route.ProfileToken, PlayerURL: "/api/v1/liveview/sessions/" + id + "/player", Status: route.Actual, Detail: route.Detail, ExpiresAt: s.now().UTC().Add(s.ttl)} + if info, describeErr := device.Describe(ctx, route.DeviceID); describeErr == nil { + session.DeviceName = info.Name + } + if profile, profileErr := admission.VerifiedProfile(route.DeviceID, route.ProfileToken); profileErr == nil { + session.ProfileName = profile.Name + session.ProfileKind = profile.Kind + } s.mu.Lock() s.sessions[id] = session s.mu.Unlock() @@ -110,3 +145,4 @@ func newID() string { } return "view_" + hex.EncodeToString(b) } +