Config repository (#3988)
* WIP * fix(test): fix ap test failing * fix: fix unkeyed fields being used * chore(tests): clean up browser tests by splitting out federation UI tests
This commit is contained in:
17
yp/api.go
17
yp/api.go
@@ -4,8 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/owncast/owncast/core/data"
|
||||
"github.com/owncast/owncast/models"
|
||||
"github.com/owncast/owncast/persistence/configrepository"
|
||||
"github.com/owncast/owncast/utils"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -28,28 +28,29 @@ type ypDetailsResponse struct {
|
||||
|
||||
// GetYPResponse gets the status of the server for YP purposes.
|
||||
func GetYPResponse(w http.ResponseWriter, r *http.Request) {
|
||||
if !data.GetDirectoryEnabled() {
|
||||
configRepository := configrepository.Get()
|
||||
if !configRepository.GetDirectoryEnabled() {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
status := getStatus()
|
||||
|
||||
streamTitle := data.GetStreamTitle()
|
||||
streamTitle := configRepository.GetStreamTitle()
|
||||
|
||||
response := ypDetailsResponse{
|
||||
Name: data.GetServerName(),
|
||||
Description: data.GetServerSummary(),
|
||||
Name: configRepository.GetServerName(),
|
||||
Description: configRepository.GetServerSummary(),
|
||||
StreamTitle: streamTitle,
|
||||
Logo: "/logo",
|
||||
NSFW: data.GetNSFW(),
|
||||
Tags: data.GetServerMetadataTags(),
|
||||
NSFW: configRepository.GetNSFW(),
|
||||
Tags: configRepository.GetServerMetadataTags(),
|
||||
Online: status.Online,
|
||||
ViewerCount: status.ViewerCount,
|
||||
OverallMaxViewerCount: status.OverallMaxViewerCount,
|
||||
SessionMaxViewerCount: status.SessionMaxViewerCount,
|
||||
LastConnectTime: status.LastConnectTime,
|
||||
Social: data.GetSocialHandles(),
|
||||
Social: configRepository.GetSocialHandles(),
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
14
yp/yp.go
14
yp/yp.go
@@ -9,8 +9,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/owncast/owncast/config"
|
||||
"github.com/owncast/owncast/core/data"
|
||||
"github.com/owncast/owncast/models"
|
||||
"github.com/owncast/owncast/persistence/configrepository"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -61,7 +61,9 @@ func (yp *YP) Stop() {
|
||||
}
|
||||
|
||||
func (yp *YP) ping() {
|
||||
if !data.GetDirectoryEnabled() {
|
||||
configRepository := configrepository.Get()
|
||||
|
||||
if !configRepository.GetDirectoryEnabled() {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -71,7 +73,7 @@ func (yp *YP) ping() {
|
||||
return
|
||||
}
|
||||
|
||||
myInstanceURL := data.GetServerURL()
|
||||
myInstanceURL := configRepository.GetServerURL()
|
||||
if myInstanceURL == "" {
|
||||
log.Warnln("Server URL not set in the configuration. Directory access is disabled until this is set.")
|
||||
return
|
||||
@@ -85,9 +87,9 @@ func (yp *YP) ping() {
|
||||
return
|
||||
}
|
||||
|
||||
key := data.GetDirectoryRegistrationKey()
|
||||
key := configRepository.GetDirectoryRegistrationKey()
|
||||
|
||||
log.Traceln("Pinging YP as: ", data.GetServerName(), "with key", key)
|
||||
log.Traceln("Pinging YP as: ", configRepository.GetServerName(), "with key", key)
|
||||
|
||||
request := ypPingRequest{
|
||||
Key: key,
|
||||
@@ -129,7 +131,7 @@ func (yp *YP) ping() {
|
||||
_inErrorState = false
|
||||
|
||||
if pingResponse.Key != key {
|
||||
if err := data.SetDirectoryRegistrationKey(key); err != nil {
|
||||
if err := configRepository.SetDirectoryRegistrationKey(key); err != nil {
|
||||
log.Errorln("unable to save directory key:", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user