safesight/edge/agent/internal/httpapi/capabilities.go
tian 29d9ef5d0d refactor: 项目结构梳理 - 设备端/管理端对称布局
仓库结构:
  edge/     设备端(原根目录设备端代码整体移入)
  control/  管理端(清理后)
  docs/     文档(PRD 移入 design/)
  README.md 根导航(新增)

清理:
- control/.brainstorm 临时草稿删除
- control 根级重复文档(API表/PRD_04)并入 docs/design/
- control/plan.md -> docs/implementation/control-plan.md
- control/safesightd-linux-arm64 二进制取消版本控制(.gitignore)
- edge/transform 模型转换产物归入 models/,onnx/pt 大源文件取消跟踪(.gitignore)
- Readme.md(PRD) -> docs/design/PRD_Product_v1.2.md(避开 README 大小写冲突)

更新:
- 根 README.md 导航、docs/README.md 文档索引
- deployment.md/检查表路径加 edge/ 前缀
- .gitignore 重写(edge/control 分区规则)
2026-08-02 11:39:54 +08:00

93 lines
2.9 KiB
Go

package httpapi
import (
"net/http"
)
// Capability represents a detection capability the device supports.
type Capability struct {
Key string `json:"key"` // "face", "shoe", "intrusion", ...
Label string `json:"label"` // human-readable name
Available bool `json:"available"` // whether the device has the required plugins
Description string `json:"description"` // brief description
}
// handleCapabilities returns the list of detection capabilities supported by this device,
// derived from the available media-server node types (plugins).
func (s *Server) handleCapabilities(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
errorJSON(w, http.StatusMethodNotAllowed, "method not allowed")
return
}
if !s.authorize(r, false) {
errorJSON(w, http.StatusUnauthorized, "unauthorized")
return
}
// Query media-server for installed node types.
installed := s.installedNodeTypes()
caps := []Capability{
{
Key: "face",
Label: "人脸识别",
Available: hasAll(installed, "ai_face_recog"),
Description: "人脸检测与识别",
},
{
Key: "shoe",
Label: "劳保鞋检测",
Available: hasAll(installed, "ai_shoe_det"),
Description: "工鞋/劳保鞋检测",
},
{
Key: "helmet",
Label: "安全帽检测",
Available: hasAll(installed, "ai_yolo"),
Description: "安全帽佩戴检测(需安全帽模型)",
},
{
Key: "intrusion",
Label: "区域入侵",
Available: hasAll(installed, "region_event"),
Description: "区域入侵/越线检测",
},
{
Key: "action",
Label: "行为识别",
Available: hasAll(installed, "action_recog"),
Description: "摔倒、打架等行为识别",
},
{
Key: "tracking",
Label: "人员跟踪",
Available: hasAll(installed, "tracker"),
Description: "多目标跟踪",
},
}
writeJSON(w, http.StatusOK, map[string]any{
"capabilities": caps,
})
}
// installedNodeTypes returns all node types known to this agent build.
// The media-server binary carries the same plugin set, so all catalogued
// types are considered available.
func (s *Server) installedNodeTypes() map[string]bool {
set := map[string]bool{}
for _, nt := range graphNodeTypesCatalog() {
set[nt.Type] = true
}
return set
}
func hasAll(installed map[string]bool, keys ...string) bool {
for _, k := range keys {
if !installed[k] {
return false
}
}
return true
}