api: sort results of /list endpoints (#1828)
This commit is contained in:
@@ -3,6 +3,7 @@ package core
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/conf"
|
||||
@@ -200,6 +201,10 @@ outer:
|
||||
data.Items = append(data.Items, muxer.apiItem())
|
||||
}
|
||||
|
||||
sort.Slice(data.Items, func(i, j int) bool {
|
||||
return data.Items[i].Created.Before(data.Items[j].Created)
|
||||
})
|
||||
|
||||
req.res <- hlsManagerAPIMuxersListRes{
|
||||
data: data,
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package core
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/conf"
|
||||
@@ -513,6 +514,10 @@ func (pm *pathManager) apiPathsList() (*apiPathsList, error) {
|
||||
res.data.Items = append(res.data.Items, item)
|
||||
}
|
||||
|
||||
sort.Slice(res.data.Items, func(i, j int) bool {
|
||||
return res.data.Items[i].Name < res.data.Items[j].Name
|
||||
})
|
||||
|
||||
return res.data, nil
|
||||
|
||||
case <-pm.ctx.Done():
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -223,6 +224,10 @@ outer:
|
||||
data.Items = append(data.Items, c.apiItem())
|
||||
}
|
||||
|
||||
sort.Slice(data.Items, func(i, j int) bool {
|
||||
return data.Items[i].Created.Before(data.Items[j].Created)
|
||||
})
|
||||
|
||||
req.res <- rtmpServerAPIConnsListRes{data: data}
|
||||
|
||||
case req := <-s.chAPIConnsGet:
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -360,6 +361,10 @@ func (s *rtspServer) apiConnsList() (*apiRTSPConnsList, error) {
|
||||
data.Items = append(data.Items, c.apiItem())
|
||||
}
|
||||
|
||||
sort.Slice(data.Items, func(i, j int) bool {
|
||||
return data.Items[i].Created.Before(data.Items[j].Created)
|
||||
})
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
@@ -401,6 +406,10 @@ func (s *rtspServer) apiSessionsList() (*apiRTSPSessionsList, error) {
|
||||
data.Items = append(data.Items, s.apiItem())
|
||||
}
|
||||
|
||||
sort.Slice(data.Items, func(i, j int) bool {
|
||||
return data.Items[i].Created.Before(data.Items[j].Created)
|
||||
})
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -150,7 +151,7 @@ type webRTCManager struct {
|
||||
chSessionClose chan *webRTCSession
|
||||
chSessionAddCandidates chan webRTCSessionAddCandidatesReq
|
||||
chAPISessionsList chan webRTCManagerAPISessionsListReq
|
||||
chAPIConnsGet chan webRTCManagerAPISessionsGetReq
|
||||
chAPISessionsGet chan webRTCManagerAPISessionsGetReq
|
||||
chAPIConnsKick chan webRTCManagerAPISessionsKickReq
|
||||
|
||||
// out
|
||||
@@ -194,7 +195,7 @@ func newWebRTCManager(
|
||||
chSessionClose: make(chan *webRTCSession),
|
||||
chSessionAddCandidates: make(chan webRTCSessionAddCandidatesReq),
|
||||
chAPISessionsList: make(chan webRTCManagerAPISessionsListReq),
|
||||
chAPIConnsGet: make(chan webRTCManagerAPISessionsGetReq),
|
||||
chAPISessionsGet: make(chan webRTCManagerAPISessionsGetReq),
|
||||
chAPIConnsKick: make(chan webRTCManagerAPISessionsKickReq),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
@@ -312,9 +313,13 @@ outer:
|
||||
data.Items = append(data.Items, sx.apiItem())
|
||||
}
|
||||
|
||||
sort.Slice(data.Items, func(i, j int) bool {
|
||||
return data.Items[i].Created.Before(data.Items[j].Created)
|
||||
})
|
||||
|
||||
req.res <- webRTCManagerAPISessionsListRes{data: data}
|
||||
|
||||
case req := <-m.chAPIConnsGet:
|
||||
case req := <-m.chAPISessionsGet:
|
||||
sx := m.findSessionByUUID(req.uuid)
|
||||
if sx == nil {
|
||||
req.res <- webRTCManagerAPISessionsGetRes{err: fmt.Errorf("not found")}
|
||||
@@ -479,7 +484,7 @@ func (m *webRTCManager) apiSessionsGet(uuid uuid.UUID) (*apiWebRTCSession, error
|
||||
}
|
||||
|
||||
select {
|
||||
case m.chAPIConnsGet <- req:
|
||||
case m.chAPISessionsGet <- req:
|
||||
res := <-req.res
|
||||
return res.data, res.err
|
||||
|
||||
|
||||
Reference in New Issue
Block a user