2020-06-23 03:11:56 +02:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
2022-05-24 00:15:32 +02:00
|
|
|
"time"
|
2020-06-23 03:11:56 +02:00
|
|
|
|
2020-10-05 19:07:09 +02:00
|
|
|
"github.com/owncast/owncast/core"
|
2022-06-26 09:46:55 +02:00
|
|
|
"github.com/owncast/owncast/core/data"
|
2020-10-05 19:07:09 +02:00
|
|
|
"github.com/owncast/owncast/router/middleware"
|
2021-03-01 08:30:46 +01:00
|
|
|
"github.com/owncast/owncast/utils"
|
2020-06-23 03:11:56 +02:00
|
|
|
)
|
|
|
|
|
2020-11-13 00:14:59 +01:00
|
|
|
// GetStatus gets the status of the server.
|
2020-06-23 03:11:56 +02:00
|
|
|
func GetStatus(w http.ResponseWriter, r *http.Request) {
|
2022-09-11 00:37:07 +02:00
|
|
|
response := getStatusResponse()
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
middleware.DisableCache(w)
|
|
|
|
|
|
|
|
if err := json.NewEncoder(w).Encode(response); err != nil {
|
|
|
|
InternalErrorHandler(w, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getStatusResponse() webStatusResponse {
|
2020-06-23 03:11:56 +02:00
|
|
|
status := core.GetStatus()
|
2021-03-01 08:30:46 +01:00
|
|
|
response := webStatusResponse{
|
2021-07-09 20:16:44 +02:00
|
|
|
Online: status.Online,
|
2022-05-24 00:15:32 +02:00
|
|
|
ServerTime: time.Now(),
|
2021-07-09 20:16:44 +02:00
|
|
|
LastConnectTime: status.LastConnectTime,
|
2021-03-01 08:30:46 +01:00
|
|
|
LastDisconnectTime: status.LastDisconnectTime,
|
2021-07-09 20:16:44 +02:00
|
|
|
VersionNumber: status.VersionNumber,
|
|
|
|
StreamTitle: status.StreamTitle,
|
2021-03-01 08:30:46 +01:00
|
|
|
}
|
2022-06-26 09:46:55 +02:00
|
|
|
if !data.GetHideViewerCount() {
|
|
|
|
response.ViewerCount = status.ViewerCount
|
|
|
|
}
|
2022-09-11 00:37:07 +02:00
|
|
|
return response
|
2020-06-23 03:11:56 +02:00
|
|
|
}
|
2021-03-01 08:30:46 +01:00
|
|
|
|
|
|
|
type webStatusResponse struct {
|
2022-05-24 00:15:32 +02:00
|
|
|
ServerTime time.Time `json:"serverTime"`
|
2021-08-04 02:47:16 +02:00
|
|
|
LastConnectTime *utils.NullTime `json:"lastConnectTime"`
|
|
|
|
LastDisconnectTime *utils.NullTime `json:"lastDisconnectTime"`
|
2021-03-01 08:30:46 +01:00
|
|
|
|
|
|
|
VersionNumber string `json:"versionNumber"`
|
|
|
|
StreamTitle string `json:"streamTitle"`
|
2023-05-30 19:31:43 +02:00
|
|
|
ViewerCount int `json:"viewerCount,omitempty"`
|
|
|
|
Online bool `json:"online"`
|
2021-07-09 20:16:44 +02:00
|
|
|
}
|