From 856961ad2d92eabb384d1b9738b89921cc74b721 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Thu, 5 Nov 2020 18:29:16 -0800 Subject: [PATCH] Replace admin broadcaster with status api --- config-example.yaml | 2 + config/config.go | 23 ++++++----- .../admin/inboundBroadcasterDetails.go | 35 ---------------- controllers/admin/status.go | 40 +++++++++++++++++++ controllers/status.go | 8 ---- router/router.go | 5 +-- 6 files changed, 55 insertions(+), 58 deletions(-) delete mode 100644 controllers/admin/inboundBroadcasterDetails.go create mode 100644 controllers/admin/status.go diff --git a/config-example.yaml b/config-example.yaml index addb4798a..35b0d7ad9 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -26,3 +26,5 @@ videoSettings: # Change this value and keep it secure. Treat it like a password to your live stream. streamingKey: abc123 +# Set to true if you don't want the service checking for future releases. +disableUpgradeChecks: false diff --git a/config/config.go b/config/config.go index 420164226..49d5c4a10 100644 --- a/config/config.go +++ b/config/config.go @@ -14,17 +14,18 @@ var Config *config var _default config type config struct { - DatabaseFilePath string `yaml:"databaseFile"` - EnableDebugFeatures bool `yaml:"-"` - FFMpegPath string `yaml:"ffmpegPath"` - Files files `yaml:"files"` - InstanceDetails InstanceDetails `yaml:"instanceDetails"` - S3 S3 `yaml:"s3"` - VersionInfo string `yaml:"-"` // For storing the version/build number - VersionNumber string `yaml:"-"` - VideoSettings videoSettings `yaml:"videoSettings"` - WebServerPort int `yaml:"webServerPort"` - YP YP `yaml:"yp"` + DatabaseFilePath string `yaml:"databaseFile"` + EnableDebugFeatures bool `yaml:"-"` + FFMpegPath string `yaml:"ffmpegPath"` + Files files `yaml:"files"` + InstanceDetails InstanceDetails `yaml:"instanceDetails"` + S3 S3 `yaml:"s3"` + VersionInfo string `yaml:"-"` // For storing the version/build number + VersionNumber string `yaml:"-"` + VideoSettings videoSettings `yaml:"videoSettings"` + WebServerPort int `yaml:"webServerPort"` + DisableUpgradeChecks bool `yaml:"disableUpgradeChecks"` + YP YP `yaml:"yp"` } // InstanceDetails defines the user-visible information about this particular instance. diff --git a/controllers/admin/inboundBroadcasterDetails.go b/controllers/admin/inboundBroadcasterDetails.go deleted file mode 100644 index 83581e19d..000000000 --- a/controllers/admin/inboundBroadcasterDetails.go +++ /dev/null @@ -1,35 +0,0 @@ -package admin - -import ( - "encoding/json" - "net/http" - - "github.com/owncast/owncast/controllers" - "github.com/owncast/owncast/core" - "github.com/owncast/owncast/models" -) - -// GetInboundBroadasterDetails gets the details of the inbound broadcaster -func GetInboundBroadasterDetails(w http.ResponseWriter, r *http.Request) { - broadcaster := core.GetBroadcaster() - if broadcaster == nil { - controllers.WriteSimpleResponse(w, false, "no broadcaster connected") - return - } - - response := inboundBroadasterDetailsResponse{ - models.BaseAPIResponse{ - true, - "", - }, - broadcaster, - } - - w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(response) -} - -type inboundBroadasterDetailsResponse struct { - models.BaseAPIResponse - Broadcaster *models.Broadcaster `json:"broadcaster"` -} diff --git a/controllers/admin/status.go b/controllers/admin/status.go new file mode 100644 index 000000000..50bcba868 --- /dev/null +++ b/controllers/admin/status.go @@ -0,0 +1,40 @@ +package admin + +import ( + "encoding/json" + "net/http" + + "github.com/owncast/owncast/config" + "github.com/owncast/owncast/core" + "github.com/owncast/owncast/models" +) + +// Status gets the details of the inbound broadcaster +func Status(w http.ResponseWriter, r *http.Request) { + broadcaster := core.GetBroadcaster() + status := core.GetStatus() + + response := adminStatusResponse{ + Broadcaster: broadcaster, + Online: status.Online, + ViewerCount: status.ViewerCount, + OverallPeakViewerCount: status.OverallMaxViewerCount, + SessionPeakViewerCount: status.SessionMaxViewerCount, + VersionNumber: status.VersionNumber, + DisableUpgradeChecks: config.Config.DisableUpgradeChecks, + } + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(response) +} + +type adminStatusResponse struct { + Broadcaster *models.Broadcaster `json:"broadcaster"` + Online bool `json:"online"` + ViewerCount int `json:"viewerCount"` + OverallPeakViewerCount int `json:"overallPeakViewerCount"` + SessionPeakViewerCount int `json:"sessionPeakViewerCount"` + + VersionNumber string `json:"versionNumber"` + DisableUpgradeChecks bool `json:"disableUpgradeChecks"` +} diff --git a/controllers/status.go b/controllers/status.go index 93f81eb47..14aa88624 100644 --- a/controllers/status.go +++ b/controllers/status.go @@ -17,11 +17,3 @@ func GetStatus(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(status) } - -//GetStatus gets the status of the server -func GetAdminStatus(w http.ResponseWriter, r *http.Request) { - status := core.GetStatus() - w.Header().Set("Content-Type", "application/json") - - json.NewEncoder(w).Encode(status) -} diff --git a/router/router.go b/router/router.go index 2423a467a..4622410fc 100644 --- a/router/router.go +++ b/router/router.go @@ -44,11 +44,8 @@ func Start() error { // Authenticated admin requests - // status of the system - http.HandleFunc("/api/admin/status", middleware.RequireAdminAuth(controllers.GetAdminStatus)) - // Current inbound broadcaster - http.HandleFunc("/api/admin/broadcaster", middleware.RequireAdminAuth(admin.GetInboundBroadasterDetails)) + http.HandleFunc("/api/admin/status", middleware.RequireAdminAuth(admin.Status)) // Disconnect inbound stream http.HandleFunc("/api/admin/disconnect", middleware.RequireAdminAuth(admin.DisconnectInboundConnection))