mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-19 17:50:03 -08:00
Reply with "status": "ok" in case of success, and with "status": "error" in case of error. This makes the API more accessible and user friendly.
49 lines
1 KiB
Go
49 lines
1 KiB
Go
//nolint:dupl
|
|
package api //nolint:revive
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/servers/hls"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (a *API) onHLSMuxersList(ctx *gin.Context) {
|
|
data, err := a.HLSServer.APIMuxersList()
|
|
if err != nil {
|
|
a.writeError(ctx, http.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
|
|
data.ItemCount = len(data.Items)
|
|
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
|
|
if err != nil {
|
|
a.writeError(ctx, http.StatusBadRequest, err)
|
|
return
|
|
}
|
|
data.PageCount = pageCount
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
|
}
|
|
|
|
func (a *API) onHLSMuxersGet(ctx *gin.Context) {
|
|
pathName, ok := paramName(ctx)
|
|
if !ok {
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name"))
|
|
return
|
|
}
|
|
|
|
data, err := a.HLSServer.APIMuxersGet(pathName)
|
|
if err != nil {
|
|
if errors.Is(err, hls.ErrMuxerNotFound) {
|
|
a.writeError(ctx, http.StatusNotFound, err)
|
|
} else {
|
|
a.writeError(ctx, http.StatusInternalServerError, err)
|
|
}
|
|
return
|
|
}
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
|
}
|