chore(api): add integration version of the status api. Closes #3981

This commit is contained in:
Gabe Kangas
2025-02-11 21:48:07 -08:00
parent 7b88b1099d
commit d4dec25129
6 changed files with 74 additions and 28 deletions

View File

@@ -12,6 +12,7 @@ import (
"strings"
"github.com/owncast/owncast/activitypub/outbox"
"github.com/owncast/owncast/core"
"github.com/owncast/owncast/core/chat"
"github.com/owncast/owncast/core/webhooks"
"github.com/owncast/owncast/models"
@@ -89,6 +90,12 @@ func ExternalSetStreamTitle(integration models.ExternalAPIUser, w http.ResponseW
SetStreamTitle(w, r)
}
// ExternalGetStatus will return the status of the server.
func ExternalGetStatus(integration models.ExternalAPIUser, w http.ResponseWriter, r *http.Request) {
status := core.GetStatus()
webutils.WriteResponse(w, status)
}
func sendSystemChatAction(messageText string, ephemeral bool) {
if err := chat.SendSystemAction(messageText, ephemeral); err != nil {
log.Errorln(err)

View File

@@ -614,6 +614,9 @@ type ServerInterface interface {
// Get a user's details
// (GET /integrations/moderation/chat/user/{userId})
ExternalGetUserDetails(w http.ResponseWriter, r *http.Request, userId string)
// Get the server's status
// (GET /integrations/status)
ExternalGetStatus(w http.ResponseWriter, r *http.Request)
// (OPTIONS /integrations/streamtitle)
ExternalSetStreamTitleOptions(w http.ResponseWriter, r *http.Request)
@@ -1762,6 +1765,12 @@ func (_ Unimplemented) ExternalGetUserDetails(w http.ResponseWriter, r *http.Req
w.WriteHeader(http.StatusNotImplemented)
}
// Get the server's status
// (GET /integrations/status)
func (_ Unimplemented) ExternalGetStatus(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotImplemented)
}
// (OPTIONS /integrations/streamtitle)
func (_ Unimplemented) ExternalSetStreamTitleOptions(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotImplemented)
@@ -5149,8 +5158,6 @@ func (siw *ServerInterfaceWrapper) SendIntegrationChatMessageOptions(w http.Resp
func (siw *ServerInterfaceWrapper) SendIntegrationChatMessage(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.SendIntegrationChatMessage(w, r)
}))
@@ -5340,6 +5347,23 @@ func (siw *ServerInterfaceWrapper) ExternalGetUserDetails(w http.ResponseWriter,
handler.ServeHTTP(w, r.WithContext(ctx))
}
// ExternalGetStatus operation middleware
func (siw *ServerInterfaceWrapper) ExternalGetStatus(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.ExternalGetStatus(w, r)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r.WithContext(ctx))
}
// ExternalSetStreamTitleOptions operation middleware
func (siw *ServerInterfaceWrapper) ExternalSetStreamTitleOptions(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
@@ -6269,6 +6293,9 @@ func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handl
r.Group(func(r chi.Router) {
r.Get(options.BaseURL+"/integrations/moderation/chat/user/{userId}", wrapper.ExternalGetUserDetails)
})
r.Group(func(r chi.Router) {
r.Get(options.BaseURL+"/integrations/status", wrapper.ExternalGetStatus)
})
r.Group(func(r chi.Router) {
r.Options(options.BaseURL+"/integrations/streamtitle", wrapper.ExternalSetStreamTitleOptions)
})

View File

@@ -88,6 +88,10 @@ func (*ServerInterfaceImpl) ExternalGetConnectedChatClientsOptions(w http.Respon
middleware.RequireExternalAPIAccessToken(models.ScopeHasAdminAccess, admin.ExternalGetConnectedChatClients)(w, r)
}
func (*ServerInterfaceImpl) ExternalGetStatus(w http.ResponseWriter, r *http.Request) {
middleware.RequireExternalAPIAccessToken(models.ScopeHasAdminAccess, admin.ExternalGetStatus)(w, r)
}
func (*ServerInterfaceImpl) GetPrometheusAPI(w http.ResponseWriter, r *http.Request) {
// might need to bring this out of the codegen
middleware.RequireAdminAuth(func(w http.ResponseWriter, r *http.Request) {