fix: wizard reads device channels from agent /v1/preview/channels instead of SQLite
This commit is contained in:
parent
b50ccda82d
commit
bf0fed23f9
@ -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, ""))
|
||||
}
|
||||
|
||||
@ -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 = [];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user