From bf0fed23f9ba5dbe90efe627b5126e0900bc1d21 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Fri, 17 Jul 2026 17:21:28 +0800 Subject: [PATCH] fix: wizard reads device channels from agent /v1/preview/channels instead of SQLite --- internal/web/ui.go | 83 +++++++++++++++++++-------- internal/web/ui/templates/wizard.html | 9 +-- 2 files changed, 60 insertions(+), 32 deletions(-) diff --git a/internal/web/ui.go b/internal/web/ui.go index 1342601..4de8e04 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -1417,36 +1417,69 @@ func (u *UI) apiWizardDeviceInfo(w http.ResponseWriter, r *http.Request) { "device_id": dev.DeviceID, "name": dev.DisplayName(), } - if u.preview != nil { - if assignment, _ := u.preview.GetDeviceAssignment(deviceID); assignment != nil { - var sourceNames []string - for _, ref := range assignment.RecognitionUnits { - if unit, _ := u.preview.GetRecognitionUnit(ref); unit != nil { - sourceNames = append(sourceNames, unit.VideoSourceRef) - } - } - resp["sources"] = sourceNames - } - } + if u.agent != nil && dev.Online { - body, code, _ := u.agent.Do("GET", dev.IP, dev.AgentPort, "/v1/capabilities", nil) - if code == 200 { - var capsResp struct { - Capabilities []struct { - Key string `json:"key"` - Label string `json:"label"` - Available bool `json:"available"` - Description string `json:"description"` - } `json:"capabilities"` - } - if json.Unmarshal(body, &capsResp) == nil { - resp["capabilities"] = capsResp.Capabilities - } - } + channels := queryAgentChannels(u.agent, dev) + resp["channels"] = channels + + caps := queryAgentCapabilities(u.agent, dev) + resp["capabilities"] = caps } json.NewEncoder(w).Encode(resp) } +func queryAgentChannels(agent *service.AgentClient, dev *models.Device) []map[string]string { + body, code, err := agent.Do("GET", dev.IP, dev.AgentPort, "/v1/preview/channels", nil) + if err != nil || code != 200 { + return nil + } + var result struct { + Channels []struct { + Name string `json:"name"` + HlsURL string `json:"hls_url"` + } `json:"channels"` + } + if json.Unmarshal(body, &result) != nil { + return nil + } + var channels []map[string]string + for _, ch := range result.Channels { + channels = append(channels, map[string]string{ + "name": ch.Name, + "hls_url": ch.HlsURL, + }) + } + return channels +} + +func queryAgentCapabilities(agent *service.AgentClient, dev *models.Device) []map[string]any { + body, code, err := agent.Do("GET", dev.IP, dev.AgentPort, "/v1/capabilities", nil) + if err != nil || code != 200 { + return nil + } + var capsResp struct { + Capabilities []struct { + Key string `json:"key"` + Label string `json:"label"` + Available bool `json:"available"` + Description string `json:"description"` + } `json:"capabilities"` + } + if json.Unmarshal(body, &capsResp) != nil { + return nil + } + var caps []map[string]any + for _, c := range capsResp.Capabilities { + caps = append(caps, map[string]any{ + "key": c.Key, + "label": c.Label, + "available": c.Available, + "description": c.Description, + }) + } + return caps +} + func (u *UI) pageDevices(w http.ResponseWriter, r *http.Request) { u.render(w, r, "devices", u.deviceOverviewPageData(r, nil, "")) } diff --git a/internal/web/ui/templates/wizard.html b/internal/web/ui/templates/wizard.html index 1d5f4d0..f90d951 100644 --- a/internal/web/ui/templates/wizard.html +++ b/internal/web/ui/templates/wizard.html @@ -189,13 +189,8 @@ fetch("/ui/wizard/device-info?device_id=" + encodeURIComponent(selectedDevice)) .then(function(r){return r.json()}) .then(function(info){ - var existingNames = (info.sources || []).slice(); - existingNames.forEach(function(sn){ - var found = allVideoSources.find(function(v){return v.name === sn}); - if (found) { - step2Assigned.push({name: found.name, url: found.url}); - } - }); + var channels = info.channels || []; + step2Assigned = channels.map(function(ch){return {name: ch.name, url: ch.hls_url || ""}}); renderAssignedSources(); step2Features = [];