feat: migrate Flutter to Cupertino with daily logs and computer groups

This commit is contained in:
tongtong committed 2026-11-13 11:27:46 +08:00
1 parent c568749d23
commit 87e1fff59b
22 files changed
+808 -55

No files matched your search

+24 -3
View File
@@ -188,14 +188,35 @@ func (b *broker) agentEndpoint(w http.ResponseWriter, r *http.Request) {
}
func (b *broker) devicesEndpoint(w http.ResponseWriter, r *http.Request) {
type device struct {
ID string `json:"id"`
Busy bool `json:"busy"`
ID string `json:"id"`
Busy bool `json:"busy"`
AgentID string `json:"agent_id,omitempty"`
ComputerName string `json:"computer_name,omitempty"`
}
devices := []device{}
b.mu.Lock()
for id, a := range b.agents {
if a.ws != nil {
devices = append(devices, device{id, b.leases[id] != nil})
item := device{ID: id, Busy: b.leases[id] != nil}
for agentID, m := range b.managers {
if m.ws == nil {
continue
}
for _, phone := range m.status.Devices {
if phone.ID == id {
item.AgentID = agentID
item.ComputerName = m.status.Name
if item.ComputerName == "" {
item.ComputerName = m.status.Hostname
}
break
}
}
if item.AgentID != "" {
break
}
}
devices = append(devices, item)
}
}
b.mu.Unlock()
+26
View File
@@ -150,3 +150,29 @@ func TestAgentDisconnectReleasesOwnership(t *testing.T) {
time.Sleep(time.Millisecond)
}
}
func TestClientDeviceListIncludesComputerName(t *testing.T) {
b, base := testServer(t)
b.mu.Lock()
b.agents["phone"] = &agent{id: "phone", ws: &websocket.Conn{}}
b.managers["host"] = &manager{ws: &websocket.Conn{}, status: managedStatus{Name: "Office PC", Hostname: "desktop", Devices: []managedDevice{{ID: "phone"}}}}
b.mu.Unlock()
req, _ := http.NewRequest("GET", base+"/v1/devices", nil)
req.Header.Set("Authorization", "Bearer "+testClientToken)
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
var rows []struct {
ID string `json:"id"`
Agent string `json:"agent_id"`
Computer string `json:"computer_name"`
}
if err = json.NewDecoder(resp.Body).Decode(&rows); err != nil {
t.Fatal(err)
}
if len(rows) != 1 || rows[0].Agent != "host" || rows[0].Computer != "Office PC" {
t.Fatalf("wrong computer association: %+v", rows)
}
}