Adding cameras api

This commit is contained in:
Eran Gonen 2025-11-25 09:28:42 +02:00
parent f1a8d5061a
commit 9a3398307a
4 changed files with 45 additions and 0 deletions

1
VERSION Normal file
View file

@ -0,0 +1 @@
v1.15.3-kela-v0.1

View file

@ -143,6 +143,7 @@ func (a *API) Initialize() error {
group.GET("/paths/list", a.onPathsList)
group.GET("/paths/get/*name", a.onPathsGet)
group.GET("/paths/cameras", a.onPathsCameras)
if !interfaceIsEmpty(a.HLSServer) {
group.GET("/hlsmuxers/list", a.onHLSMuxersList)
@ -594,6 +595,47 @@ func (a *API) onPathsGet(ctx *gin.Context) {
ctx.JSON(http.StatusOK, data)
}
func (a *API) onPathsCameras(ctx *gin.Context) {
data, err := a.PathManager.APIPathsList()
if err != nil {
a.writeError(ctx, http.StatusInternalServerError, err)
return
}
// Filter by search parameter if provided and extract only name and meta
search := ctx.Query("search")
items := []map[string]any{}
for _, item := range data.Items {
if search == "" || strings.Contains(strings.ToLower(item.Name), strings.ToLower(search)) {
cameraItem := map[string]any{
"name": item.Name,
}
if item.Meta != nil {
// Merge meta fields at the same level as name
for k, v := range item.Meta {
cameraItem[k] = v
}
}
items = append(items, cameraItem)
}
}
itemCount := len(items)
pageCount, err := paginate(&items, ctx.Query("itemsPerPage"), ctx.Query("page"))
if err != nil {
a.writeError(ctx, http.StatusBadRequest, err)
return
}
response := map[string]any{
"itemCount": itemCount,
"pageCount": pageCount,
"items": items,
}
ctx.JSON(http.StatusOK, response)
}
func (a *API) onRTSPConnsList(ctx *gin.Context) {
data, err := a.RTSPServer.APIConnsList()
if err != nil {

View file

@ -653,6 +653,7 @@ func (pa *path) doAPIPathsGet(req pathAPIPathsGetReq) {
}
return &ts
}(),
Meta: pa.conf.Meta,
},
}
}

View file

@ -87,6 +87,7 @@ type APIPath struct {
Readers []APIPathSourceOrReader `json:"readers"`
BitrateReceived float64 `json:"bitrateReceived"`
LastRTPTimestamp *int64 `json:"lastRTPTimestamp"`
Meta map[string]any `json:"meta,omitempty"`
}
// APIPathList is a list of paths.