diff --git a/activitypub/controllers/nodeinfo.go b/activitypub/controllers/nodeinfo.go index aeb9832dd..32e9f38d6 100644 --- a/activitypub/controllers/nodeinfo.go +++ b/activitypub/controllers/nodeinfo.go @@ -9,8 +9,8 @@ import ( "github.com/owncast/owncast/activitypub/crypto" "github.com/owncast/owncast/activitypub/persistence" "github.com/owncast/owncast/activitypub/requests" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" + "github.com/owncast/owncast/services/config" log "github.com/sirupsen/logrus" ) @@ -95,6 +95,7 @@ func NodeInfoV2Controller(w http.ResponseWriter, r *http.Request) { } localPostCount, _ := persistence.GetLocalPostCount() + c := config.GetConfig() res := response{ Version: "2.0", @@ -104,7 +105,7 @@ func NodeInfoV2Controller(w http.ResponseWriter, r *http.Request) { }, Software: software{ Name: "owncast", - Version: config.VersionNumber, + Version: c.VersionNumber, }, Usage: usage{ Users: users{ @@ -175,6 +176,7 @@ func XNodeInfo2Controller(w http.ResponseWriter, r *http.Request) { } localPostCount, _ := persistence.GetLocalPostCount() + c := config.GetConfig() res := &response{ Organization: Organization{ @@ -183,7 +185,7 @@ func XNodeInfo2Controller(w http.ResponseWriter, r *http.Request) { }, Server: Server{ BaseURL: serverURL, - Version: config.VersionNumber, + Version: c.VersionNumber, Name: "owncast", Software: "owncast", }, @@ -192,7 +194,7 @@ func XNodeInfo2Controller(w http.ResponseWriter, r *http.Request) { Outbound: []string{"activitypub"}, }, Protocols: []string{"activitypub"}, - Version: config.VersionNumber, + Version: c.VersionNumber, Usage: Usage{ Users: Users{ ActiveWeek: 1, @@ -251,13 +253,14 @@ func InstanceV1Controller(w http.ResponseWriter, r *http.Request) { thumbnail.Path = "/logo/external" localPostCount, _ := persistence.GetLocalPostCount() + c := config.GetConfig() res := response{ URI: serverURL, Title: data.GetServerName(), ShortDescription: data.GetServerSummary(), Description: data.GetServerSummary(), - Version: config.GetReleaseString(), + Version: c.GetReleaseString(), Stats: Stats{ UserCount: 1, StatusCount: int(localPostCount), diff --git a/activitypub/crypto/sign.go b/activitypub/crypto/sign.go index 48550976e..cc1cc481c 100644 --- a/activitypub/crypto/sign.go +++ b/activitypub/crypto/sign.go @@ -9,7 +9,7 @@ import ( "time" "github.com/go-fed/httpsig" - "github.com/owncast/owncast/config" + "github.com/owncast/owncast/services/config" log "github.com/sirupsen/logrus" ) @@ -77,7 +77,9 @@ func CreateSignedRequest(payload []byte, url *url.URL, fromActorIRI *url.URL) (* req, _ := http.NewRequest("POST", url.String(), bytes.NewBuffer(payload)) - ua := fmt.Sprintf("%s; https://owncast.online", config.GetReleaseString()) + c := config.GetConfig() + ua := fmt.Sprintf("%s; https://owncast.online", c.GetReleaseString()) + req.Header.Set("User-Agent", ua) req.Header.Set("Content-Type", "application/activity+json") diff --git a/activitypub/outbox/outbox.go b/activitypub/outbox/outbox.go index e035dd297..a123eda1c 100644 --- a/activitypub/outbox/outbox.go +++ b/activitypub/outbox/outbox.go @@ -18,8 +18,8 @@ import ( "github.com/owncast/owncast/activitypub/workerpool" "github.com/pkg/errors" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/utils" log "github.com/sirupsen/logrus" "github.com/teris-io/shortid" @@ -77,8 +77,9 @@ func SendLive() error { if err == nil { var imageToAttach string var mediaType string - previewGif := filepath.Join(config.TempDir, "preview.gif") - thumbnailJpg := filepath.Join(config.TempDir, "thumbnail.jpg") + c := config.GetConfig() + previewGif := filepath.Join(c.TempDir, "preview.gif") + thumbnailJpg := filepath.Join(c.TempDir, "thumbnail.jpg") uniquenessString := shortid.MustGenerate() if utils.DoesFileExists(previewGif) { imageToAttach = "preview.gif" diff --git a/activitypub/requests/http.go b/activitypub/requests/http.go index 1c879cb7b..c23c0eeac 100644 --- a/activitypub/requests/http.go +++ b/activitypub/requests/http.go @@ -10,7 +10,7 @@ import ( "github.com/go-fed/activity/streams" "github.com/go-fed/activity/streams/vocab" "github.com/owncast/owncast/activitypub/crypto" - "github.com/owncast/owncast/config" + "github.com/owncast/owncast/services/config" log "github.com/sirupsen/logrus" ) @@ -60,8 +60,8 @@ func CreateSignedRequest(payload []byte, url *url.URL, fromActorIRI *url.URL) (* log.Debugln("Sending", string(payload), "to", url) req, _ := http.NewRequest(http.MethodPost, url.String(), bytes.NewBuffer(payload)) - - ua := fmt.Sprintf("%s; https://owncast.online", config.GetReleaseString()) + c := config.GetConfig() + ua := fmt.Sprintf("%s; https://owncast.online", c.GetReleaseString()) req.Header.Set("User-Agent", ua) req.Header.Set("Content-Type", "application/activity+json") diff --git a/config/config.go b/config/config.go deleted file mode 100644 index d4f590382..000000000 --- a/config/config.go +++ /dev/null @@ -1,70 +0,0 @@ -package config - -import ( - "fmt" - "time" -) - -// These are runtime-set values used for configuration. - -// DatabaseFilePath is the path to the file ot be used as the global database for this run of the application. -var DatabaseFilePath = "data/owncast.db" - -// LogDirectory is the path to various log files. -var LogDirectory = "./data/logs" - -// TempDir is where we store temporary files. -var TempDir = "./data/tmp" - -// EnableDebugFeatures will print additional data to help in debugging. -var EnableDebugFeatures = false - -// VersionNumber is the current version string. -var VersionNumber = StaticVersionNumber - -// WebServerPort is the port for Owncast's webserver that is used for this execution of the service. -var WebServerPort = 8080 - -// WebServerIP is the IP address to bind the web server to. All interfaces by default. -var WebServerIP = "0.0.0.0" - -// InternalHLSListenerPort is the port for HLS writes that is used for this execution of the service. -var InternalHLSListenerPort = "8927" - -// GitCommit is an optional commit this build was made from. -var GitCommit = "" - -// BuildPlatform is the optional platform this release was built for. -var BuildPlatform = "dev" - -// EnableAutoUpdate will explicitly enable in-place auto-updates via the admin. -var EnableAutoUpdate = false - -// A temporary stream key that can be set via the command line. -var TemporaryStreamKey = "" - -// GetCommit will return an identifier used for identifying the point in time this build took place. -func GetCommit() string { - if GitCommit == "" { - GitCommit = time.Now().Format("20060102") - } - - return GitCommit -} - -// DefaultForbiddenUsernames are a list of usernames forbidden from being used in chat. -var DefaultForbiddenUsernames = []string{ - "owncast", "operator", "admin", "system", -} - -// MaxSocketPayloadSize is the maximum payload we will allow to to be received via the chat socket. -const MaxSocketPayloadSize = 2048 - -// GetReleaseString gets the version string. -func GetReleaseString() string { - versionNumber := VersionNumber - buildPlatform := BuildPlatform - gitCommit := GetCommit() - - return fmt.Sprintf("Owncast v%s-%s (%s)", versionNumber, buildPlatform, gitCommit) -} diff --git a/config/configUtils.go b/config/configUtils.go deleted file mode 100644 index d912156be..000000000 --- a/config/configUtils.go +++ /dev/null @@ -1 +0,0 @@ -package config diff --git a/config/updaterConfig_enabled.go b/config/updaterConfig_enabled.go deleted file mode 100644 index 5ede95638..000000000 --- a/config/updaterConfig_enabled.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:build enable_updates -// +build enable_updates - -package config - -func init() { - EnableAutoUpdate = true -} diff --git a/config/verifyInstall.go b/config/verifyInstall.go deleted file mode 100644 index 96b38bf69..000000000 --- a/config/verifyInstall.go +++ /dev/null @@ -1,66 +0,0 @@ -package config - -import ( - "errors" - "fmt" - "os" - "os/exec" - "strings" - - log "github.com/sirupsen/logrus" - - "golang.org/x/mod/semver" -) - -// VerifyFFMpegPath verifies that the path exists, is a file, and is executable. -func VerifyFFMpegPath(path string) error { - stat, err := os.Stat(path) - - if os.IsNotExist(err) { - return errors.New("ffmpeg path does not exist") - } - - if err != nil { - return fmt.Errorf("error while verifying the ffmpeg path: %s", err.Error()) - } - - if stat.IsDir() { - return errors.New("ffmpeg path can not be a folder") - } - - mode := stat.Mode() - // source: https://stackoverflow.com/a/60128480 - if mode&0o111 == 0 { - return errors.New("ffmpeg path is not executable") - } - - cmd := exec.Command(path) - out, _ := cmd.CombinedOutput() - - response := string(out) - if response == "" { - return fmt.Errorf("unable to determine the version of your ffmpeg installation at %s you may experience issues with video", path) - } - - responseComponents := strings.Split(response, " ") - if len(responseComponents) < 3 { - log.Debugf("unable to determine the version of your ffmpeg installation at %s you may experience issues with video", path) - return nil - } - - fullVersionString := responseComponents[2] - - versionString := "v" + strings.Split(fullVersionString, "-")[0] - - // Some builds of ffmpeg have weird build numbers that we can't parse - if !semver.IsValid(versionString) { - log.Debugf("unable to determine if ffmpeg version %s is recent enough. if you experience issues with video you may want to look into updating", fullVersionString) - return nil - } - - if semver.Compare(versionString, FfmpegSuggestedVersion) == -1 { - return fmt.Errorf("your %s version of ffmpeg at %s may be older than the suggested version of %s you may experience issues with video", versionString, path, FfmpegSuggestedVersion) - } - - return nil -} diff --git a/core/chat/chat.go b/core/chat/chat.go index 03d32c6ec..6f90239ad 100644 --- a/core/chat/chat.go +++ b/core/chat/chat.go @@ -5,10 +5,10 @@ import ( "net/http" "sort" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/chat/events" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" log "github.com/sirupsen/logrus" @@ -29,12 +29,13 @@ func Start(getStatusFunc func() models.Status) error { go _server.Run() log.Traceln("Chat server started with max connection count of", _server.maxSocketConnectionLimit) + c := config.GetConfig() chatMessagesSentCounter = promauto.NewGauge(prometheus.GaugeOpts{ Name: "total_chat_message_count", Help: "The number of chat messages incremented over time.", ConstLabels: map[string]string{ - "version": config.VersionNumber, + "version": c.VersionNumber, "host": data.GetServerURL(), }, }) diff --git a/core/chat/chatclient.go b/core/chat/chatclient.go index fd398116e..8825d75cb 100644 --- a/core/chat/chatclient.go +++ b/core/chat/chatclient.go @@ -11,9 +11,9 @@ import ( "golang.org/x/time/rate" "github.com/gorilla/websocket" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/chat/events" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/services/geoip" ) diff --git a/core/chat/events.go b/core/chat/events.go index d7482a639..fa59f434c 100644 --- a/core/chat/events.go +++ b/core/chat/events.go @@ -6,9 +6,9 @@ import ( "strings" "time" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/chat/events" "github.com/owncast/owncast/core/data" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/services/webhooks" "github.com/owncast/owncast/storage" "github.com/owncast/owncast/utils" diff --git a/core/chat/server.go b/core/chat/server.go index 626c5ca79..1979cc8cb 100644 --- a/core/chat/server.go +++ b/core/chat/server.go @@ -11,10 +11,10 @@ import ( "github.com/gorilla/websocket" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/chat/events" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/services/geoip" "github.com/owncast/owncast/services/webhooks" "github.com/owncast/owncast/storage" diff --git a/core/core.go b/core/core.go index f1dea2a4c..c490ee3fc 100644 --- a/core/core.go +++ b/core/core.go @@ -7,11 +7,11 @@ import ( log "github.com/sirupsen/logrus" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/chat" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/models" "github.com/owncast/owncast/services/auth" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/services/notifications" "github.com/owncast/owncast/services/webhooks" "github.com/owncast/owncast/services/yp" @@ -113,7 +113,8 @@ func transitionToOfflineVideoStreamContent() { // Copy the logo to be the thumbnail logo := data.GetLogoPath() - dst := filepath.Join(config.TempDir, "thumbnail.jpg") + c := config.GetConfig() + dst := filepath.Join(c.TempDir, "thumbnail.jpg") if err = utils.Copy(filepath.Join("data", logo), dst); err != nil { log.Warnln(err) } @@ -126,7 +127,8 @@ func resetDirectories() { log.Trace("Resetting file directories to a clean slate.") // Wipe hls data directory - utils.CleanupDirectory(config.HLSStoragePath) + c := config.GetConfig() + utils.CleanupDirectory(c.HLSStoragePath) // Remove the previous thumbnail logo := data.GetLogoPath() diff --git a/core/data/config.go b/core/data/config.go index 47cc860af..d9ceaf58f 100644 --- a/core/data/config.go +++ b/core/data/config.go @@ -7,8 +7,8 @@ import ( "strings" "time" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/static" "github.com/owncast/owncast/utils" "github.com/pkg/errors" @@ -596,7 +596,8 @@ func GetVideoCodec() string { // VerifySettings will perform a sanity check for specific settings values. func VerifySettings() error { - if len(GetStreamKeys()) == 0 && config.TemporaryStreamKey == "" { + c := config.GetConfig() + if len(GetStreamKeys()) == 0 && c.TemporaryStreamKey == "" { log.Errorln("No stream key set. Streaming is disabled. Please set one via the admin or command line arguments") } diff --git a/core/data/data.go b/core/data/data.go index 9fc1dc74c..901ec3ba4 100644 --- a/core/data/data.go +++ b/core/data/data.go @@ -11,7 +11,7 @@ import ( "path/filepath" "time" - "github.com/owncast/owncast/config" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/utils" log "github.com/sirupsen/logrus" ) @@ -118,7 +118,8 @@ func SetupPersistence(file string) error { dbBackupTicker := time.NewTicker(1 * time.Hour) go func() { - backupFile := filepath.Join(config.BackupDirectory, "owncastdb.bak") + c := config.GetConfig() + backupFile := filepath.Join(c.BackupDirectory, "owncastdb.bak") for range dbBackupTicker.C { utils.Backup(_db, backupFile) } diff --git a/core/data/defaults.go b/core/data/defaults.go index 5a8415765..848c17375 100644 --- a/core/data/defaults.go +++ b/core/data/defaults.go @@ -1,8 +1,8 @@ package data import ( - "github.com/owncast/owncast/config" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" ) // HasPopulatedDefaults will determine if the defaults have been inserted into the database. diff --git a/core/data/emoji.go b/core/data/emoji.go index 86ea61d50..8862d00f2 100644 --- a/core/data/emoji.go +++ b/core/data/emoji.go @@ -9,8 +9,8 @@ import ( "sync" "time" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/static" "github.com/owncast/owncast/utils" "github.com/pkg/errors" @@ -102,11 +102,13 @@ func SetupEmojiDirectory() (err error) { isDir bool } - if utils.DoesFileExists(config.CustomEmojiPath) { + c := config.GetConfig() + + if utils.DoesFileExists(c.CustomEmojiPath) { return nil } - if err = os.MkdirAll(config.CustomEmojiPath, 0o750); err != nil { + if err = os.MkdirAll(c.CustomEmojiPath, 0o750); err != nil { return fmt.Errorf("unable to create custom emoji directory: %w", err) } @@ -137,7 +139,7 @@ func SetupEmojiDirectory() (err error) { // Now copy all built-in emojis to the custom emoji directory for _, path := range files { - emojiPath := filepath.Join(config.CustomEmojiPath, path.path) + emojiPath := filepath.Join(c.CustomEmojiPath, path.path) if path.isDir { if err := os.Mkdir(emojiPath, 0o700); err != nil { diff --git a/core/data/migrations.go b/core/data/migrations.go index 156e1c5fd..f14d890c8 100644 --- a/core/data/migrations.go +++ b/core/data/migrations.go @@ -6,15 +6,17 @@ import ( "path/filepath" "time" - "github.com/owncast/owncast/config" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/utils" log "github.com/sirupsen/logrus" "github.com/teris-io/shortid" ) func migrateDatabaseSchema(db *sql.DB, from, to int) error { + c := config.GetConfig() + log.Printf("Migrating database from version %d to %d", from, to) - dbBackupFile := filepath.Join(config.BackupDirectory, fmt.Sprintf("owncast-v%d.bak", from)) + dbBackupFile := filepath.Join(c.BackupDirectory, fmt.Sprintf("owncast-v%d.bak", from)) utils.Backup(db, dbBackupFile) for v := from; v < to; v++ { log.Tracef("Migration step from %d to %d\n", v, v+1) diff --git a/core/data/persistence.go b/core/data/persistence.go index a765f0b72..1aefa42a0 100644 --- a/core/data/persistence.go +++ b/core/data/persistence.go @@ -9,8 +9,8 @@ import ( // sqlite requires a blank import. _ "github.com/mattn/go-sqlite3" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/db" + "github.com/owncast/owncast/services/config" log "github.com/sirupsen/logrus" ) diff --git a/core/offlineState.go b/core/offlineState.go index e1257c37f..19e7d874e 100644 --- a/core/offlineState.go +++ b/core/offlineState.go @@ -6,7 +6,7 @@ import ( "path/filepath" "github.com/grafov/m3u8" - "github.com/owncast/owncast/config" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/static" "github.com/owncast/owncast/utils" log "github.com/sirupsen/logrus" @@ -19,8 +19,9 @@ func appendOfflineToVariantPlaylist(index int, playlistFilePath string) { return } + c := config.GetConfig() tmpFileName := fmt.Sprintf("tmp-stream-%d.m3u8", index) - atomicWriteTmpPlaylistFile, err := os.CreateTemp(config.TempDir, tmpFileName) + atomicWriteTmpPlaylistFile, err := os.CreateTemp(c.TempDir, tmpFileName) if err != nil { log.Errorln("error creating tmp playlist file to write to", playlistFilePath, err) return @@ -49,8 +50,9 @@ func appendOfflineToVariantPlaylist(index int, playlistFilePath string) { } func makeVariantIndexOffline(index int, offlineFilePath string, offlineFilename string) { - playlistFilePath := fmt.Sprintf(filepath.Join(config.HLSStoragePath, "%d/stream.m3u8"), index) - segmentFilePath := fmt.Sprintf(filepath.Join(config.HLSStoragePath, "%d/%s"), index, offlineFilename) + c := config.GetConfig() + playlistFilePath := fmt.Sprintf(filepath.Join(c.HLSStoragePath, "%d/stream.m3u8"), index) + segmentFilePath := fmt.Sprintf(filepath.Join(c.HLSStoragePath, "%d/%s"), index, offlineFilename) if err := utils.Copy(offlineFilePath, segmentFilePath); err != nil { log.Warnln(err) @@ -94,7 +96,8 @@ func createEmptyOfflinePlaylist(playlistFilePath string, offlineFilename string) func saveOfflineClipToDisk(offlineFilename string) (string, error) { offlineFileData := static.GetOfflineSegment() - offlineTmpFile, err := os.CreateTemp(config.TempDir, offlineFilename) + c := config.GetConfig() + offlineTmpFile, err := os.CreateTemp(c.TempDir, offlineFilename) if err != nil { log.Errorln("unable to create temp file for offline video segment", err) } diff --git a/core/status.go b/core/status.go index e0408b828..e2622f744 100644 --- a/core/status.go +++ b/core/status.go @@ -1,9 +1,9 @@ package core import ( - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" ) // GetStatus gets the status of the system. @@ -17,6 +17,8 @@ func GetStatus() models.Status { viewerCount = len(_stats.Viewers) } + c := config.GetConfig() + return models.Status{ Online: IsStreamConnected(), ViewerCount: viewerCount, @@ -24,7 +26,7 @@ func GetStatus() models.Status { SessionMaxViewerCount: _stats.SessionMaxViewerCount, LastDisconnectTime: _stats.LastDisconnectTime, LastConnectTime: _stats.LastConnectTime, - VersionNumber: config.VersionNumber, + VersionNumber: c.VersionNumber, StreamTitle: data.GetStreamTitle(), } } diff --git a/core/streamState.go b/core/streamState.go index 2b39109bb..05e0b36b9 100644 --- a/core/streamState.go +++ b/core/streamState.go @@ -8,10 +8,10 @@ import ( log "github.com/sirupsen/logrus" "github.com/owncast/owncast/activitypub" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/chat" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/services/notifications" "github.com/owncast/owncast/services/webhooks" "github.com/owncast/owncast/utils" @@ -51,7 +51,8 @@ func setStreamAsConnected(rtmpOut *io.PipeReader) { go _yp.Start() } - segmentPath := config.HLSStoragePath + c := config.GetConfig() + segmentPath := c.HLSStoragePath if err := setupStorage(); err != nil { log.Fatalln("failed to setup the storage", err) diff --git a/logging/paths.go b/logging/paths.go index 31d05e902..a3b747648 100644 --- a/logging/paths.go +++ b/logging/paths.go @@ -3,14 +3,16 @@ package logging import ( "path/filepath" - "github.com/owncast/owncast/config" + "github.com/owncast/owncast/services/config" ) // GetTranscoderLogFilePath returns the logging path for the transcoder log output. func GetTranscoderLogFilePath() string { - return filepath.Join(config.LogDirectory, "transcoder.log") + c := config.GetConfig() + return filepath.Join(c.LogDirectory, "transcoder.log") } func getLogFilePath() string { - return filepath.Join(config.LogDirectory, "owncast.log") + c := config.GetConfig() + return filepath.Join(c.LogDirectory, "owncast.log") } diff --git a/main.go b/main.go index 1e3da864e..cbf3967a2 100644 --- a/main.go +++ b/main.go @@ -9,10 +9,11 @@ import ( "github.com/owncast/owncast/webserver" log "github.com/sirupsen/logrus" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core" "github.com/owncast/owncast/core/data" + configservice "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/services/metrics" + "github.com/owncast/owncast/utils" ) @@ -28,12 +29,15 @@ var ( webServerPortOverride = flag.String("webserverport", "", "Force the web server to listen on a specific port") webServerIPOverride = flag.String("webserverip", "", "Force web server to listen on this IP address") rtmpPortOverride = flag.Int("rtmpport", 0, "Set listen port for the RTMP server") + config *configservice.Config ) // nolint:cyclop func main() { flag.Parse() + config = configservice.NewConfig() + if *logDirectory != "" { config.LogDirectory = *logDirectory } diff --git a/services/config/config.go b/services/config/config.go new file mode 100644 index 000000000..c58a17483 --- /dev/null +++ b/services/config/config.go @@ -0,0 +1,106 @@ +package config + +import ( + "fmt" + "path/filepath" + "time" +) + +// These are runtime-set values used for configuration. + +type Config struct { + // DatabaseFilePath is the path to the file ot be used as the global database for this run of the application. + DatabaseFilePath string + // LogDirectory is the path to various log files. + LogDirectory string + // TempDir is where we store temporary files. + TempDir string + // EnableDebugFeatures will print additional data to help in debugging. + EnableDebugFeatures bool + // VersionNumber is the current version string. + VersionNumber string + // WebServerPort is the port for Owncast's webserver that is used for this execution of the service. + WebServerPort int + // WebServerIP is the IP address to bind the web server to. All interfaces by default. + WebServerIP string + // InternalHLSListenerPort is the port for HLS writes that is used for this execution of the service. + InternalHLSListenerPort string + // GitCommit is an optional commit this build was made from. + GitCommit string + // BuildPlatform is the optional platform this release was built for. + BuildPlatform string + // EnableAutoUpdate will explicitly enable in-place auto-updates via the admin. + EnableAutoUpdate bool + // A temporary stream key that can be set via the command line. + TemporaryStreamKey string + // BackupDirectory is the directory we write backup files to. + BackupDirectory string + // HLSStoragePath is the directory HLS video is written to. + HLSStoragePath string + // CustomEmojiPath is the emoji directory. + CustomEmojiPath string + // PublicFilesPath is the optional directory for hosting public files. + PublicFilesPath string +} + +// NewFediAuth creates a new FediAuth instance. +func NewConfig() *Config { + // Default config values. + c := &Config{ + DatabaseFilePath: "data/owncast.db", + LogDirectory: "./data/logs", + TempDir: "./data/tmp", + EnableDebugFeatures: false, + VersionNumber: StaticVersionNumber, + WebServerPort: 8080, + WebServerIP: "0.0.0.0", + InternalHLSListenerPort: "8927", + GitCommit: "", + BuildPlatform: "dev", + EnableAutoUpdate: false, + TemporaryStreamKey: "", + BackupDirectory: filepath.Join(DataDirectory, "backup"), + HLSStoragePath: filepath.Join(DataDirectory, "hls"), + CustomEmojiPath: filepath.Join(DataDirectory, "emoji"), + PublicFilesPath: filepath.Join(DataDirectory, "public"), + } + return c +} + +var temporaryGlobalInstance *Config + +// GetConfig returns the temporary global instance. +// Remove this after dependency injection is implemented. +func GetConfig() *Config { + if temporaryGlobalInstance == nil { + temporaryGlobalInstance = NewConfig() + } + + return temporaryGlobalInstance +} + +// GetCommit will return an identifier used for identifying the point in time this build took place. +func (c *Config) GetCommit() string { + if c.GitCommit == "" { + c.GitCommit = time.Now().Format("20060102") + } + + return c.GitCommit +} + +// DefaultForbiddenUsernames are a list of usernames forbidden from being used in chat. +var DefaultForbiddenUsernames = []string{ + "owncast", "operator", "admin", "system", +} + +// MaxSocketPayloadSize is the maximum payload we will allow to to be received via the chat socket. +const MaxSocketPayloadSize = 2048 + +// GetReleaseString gets the version string. +func (c *Config) GetReleaseString() string { + versionNumber := c.VersionNumber + buildPlatform := c.BuildPlatform + gitCommit := c.GetCommit() + + return fmt.Sprintf("Owncast v%s-%s (%s)", versionNumber, buildPlatform, gitCommit) +} diff --git a/config/constants.go b/services/config/constants.go similarity index 60% rename from config/constants.go rename to services/config/constants.go index 36fa69109..efb3373e2 100644 --- a/config/constants.go +++ b/services/config/constants.go @@ -1,7 +1,5 @@ package config -import "path/filepath" - const ( // StaticVersionNumber is the version of Owncast that is used when it's not overwritten via build-time settings. StaticVersionNumber = "0.1.3" // Shown when you build from develop @@ -17,17 +15,3 @@ const ( // MaxChatDisplayNameLength is the maximum length of a chat display name. MaxChatDisplayNameLength = 30 ) - -var ( - // BackupDirectory is the directory we write backup files to. - BackupDirectory = filepath.Join(DataDirectory, "backup") - - // HLSStoragePath is the directory HLS video is written to. - HLSStoragePath = filepath.Join(DataDirectory, "hls") - - // CustomEmojiPath is the emoji directory. - CustomEmojiPath = filepath.Join(DataDirectory, "emoji") - - // PublicFilesPath is the optional directory for hosting public files. - PublicFilesPath = filepath.Join(DataDirectory, "public") -) diff --git a/config/defaults.go b/services/config/defaults.go similarity index 100% rename from config/defaults.go rename to services/config/defaults.go diff --git a/services/metrics/metrics.go b/services/metrics/metrics.go index 2453e2300..084656cec 100644 --- a/services/metrics/metrics.go +++ b/services/metrics/metrics.go @@ -4,9 +4,9 @@ import ( "sync" "time" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" ) // How often we poll for updates. @@ -61,8 +61,11 @@ func Start(getStatus func() models.Status) { if host == "" { host = "unknown" } + + c := config.GetConfig() + labels = map[string]string{ - "version": config.VersionNumber, + "version": c.VersionNumber, "host": host, } diff --git a/services/notifications/notifications.go b/services/notifications/notifications.go index b473f6490..cccacf674 100644 --- a/services/notifications/notifications.go +++ b/services/notifications/notifications.go @@ -3,9 +3,9 @@ package notifications import ( "fmt" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/services/notifications/browser" "github.com/owncast/owncast/services/notifications/discord" "github.com/pkg/errors" diff --git a/services/yp/yp.go b/services/yp/yp.go index 055dd1ec8..e3d2ca665 100644 --- a/services/yp/yp.go +++ b/services/yp/yp.go @@ -8,9 +8,9 @@ import ( "net/url" "time" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" log "github.com/sirupsen/logrus" ) diff --git a/storage/userRepository.go b/storage/userRepository.go index 8270b4682..6c07d5bb3 100644 --- a/storage/userRepository.go +++ b/storage/userRepository.go @@ -8,10 +8,10 @@ import ( "strings" "time" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/db" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/utils" "github.com/pkg/errors" "github.com/teris-io/shortid" diff --git a/video/rtmp/rtmp.go b/video/rtmp/rtmp.go index b9a4f96dd..e3e189d87 100644 --- a/video/rtmp/rtmp.go +++ b/video/rtmp/rtmp.go @@ -11,9 +11,9 @@ import ( log "github.com/sirupsen/logrus" "github.com/nareix/joy5/format/rtmp" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" ) var _hasInboundRTMPConnection = false @@ -81,9 +81,11 @@ func HandleConn(c *rtmp.Conn, nc net.Conn) { accessGranted := false validStreamingKeys := data.GetStreamKeys() + configservice := config.GetConfig() + // If a stream key override was specified then use that instead. - if config.TemporaryStreamKey != "" { - validStreamingKeys = []models.StreamKey{{Key: config.TemporaryStreamKey}} + if configservice.TemporaryStreamKey != "" { + validStreamingKeys = []models.StreamKey{{Key: configservice.TemporaryStreamKey}} } for _, key := range validStreamingKeys { diff --git a/video/storageproviders/local.go b/video/storageproviders/local.go index 65bcaa907..0429aeb14 100644 --- a/video/storageproviders/local.go +++ b/video/storageproviders/local.go @@ -8,8 +8,8 @@ import ( "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" + "github.com/owncast/owncast/services/config" ) // LocalStorage represents an instance of the local storage provider for HLS video. @@ -66,7 +66,8 @@ func (s *LocalStorage) Cleanup() error { // Determine how many files we should keep on disk maxNumber := data.GetStreamLatencyLevel().SegmentCount buffer := 10 - baseDirectory := config.HLSStoragePath + c := config.GetConfig() + baseDirectory := c.HLSStoragePath files, err := getAllFilesRecursive(baseDirectory) if err != nil { diff --git a/video/storageproviders/rewriteLocalPlaylist.go b/video/storageproviders/rewriteLocalPlaylist.go index 1edf13428..6afbf07d3 100644 --- a/video/storageproviders/rewriteLocalPlaylist.go +++ b/video/storageproviders/rewriteLocalPlaylist.go @@ -6,7 +6,7 @@ import ( "path/filepath" "github.com/grafov/m3u8" - "github.com/owncast/owncast/config" + "github.com/owncast/owncast/services/config" playlist "github.com/owncast/owncast/video/playlists" log "github.com/sirupsen/logrus" @@ -34,8 +34,8 @@ func rewritePlaylistLocations(localFilePath, remoteServingEndpoint, pathPrefix s } item.URI = remoteServingEndpoint + filepath.Join(finalPath, item.URI) } - - publicPath := filepath.Join(config.HLSStoragePath, filepath.Base(localFilePath)) + c := config.GetConfig() + publicPath := filepath.Join(c.HLSStoragePath, filepath.Base(localFilePath)) newPlaylist := p.String() diff --git a/video/storageproviders/s3Storage.go b/video/storageproviders/s3Storage.go index b5f8b330f..9647c7131 100644 --- a/video/storageproviders/s3Storage.go +++ b/video/storageproviders/s3Storage.go @@ -22,7 +22,7 @@ import ( "github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3/s3manager" - "github.com/owncast/owncast/config" + "github.com/owncast/owncast/services/config" ) // S3Storage is the s3 implementation of a storage provider. @@ -158,8 +158,10 @@ func (s *S3Storage) Save(filePath string, retryCount int) (string, error) { } defer file.Close() + c := config.GetConfig() + // Convert the local path to the variant/file path by stripping the local storage location. - normalizedPath := strings.TrimPrefix(filePath, config.HLSStoragePath) + normalizedPath := strings.TrimPrefix(filePath, c.HLSStoragePath) // Build the remote path by adding the "hls" path prefix. remotePath := strings.Join([]string{"hls", normalizedPath}, "") diff --git a/video/transcoder/fileWriterReceiverService.go b/video/transcoder/fileWriterReceiverService.go index 08c1427cf..74fa96ca7 100644 --- a/video/transcoder/fileWriterReceiverService.go +++ b/video/transcoder/fileWriterReceiverService.go @@ -8,7 +8,7 @@ import ( "path/filepath" "strings" - "github.com/owncast/owncast/config" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/utils" log "github.com/sirupsen/logrus" ) @@ -42,8 +42,9 @@ func (s *FileWriterReceiverService) SetupFileWriterReceiverService(callbacks Fil log.Fatalln("Unable to start internal video writing service", err) } + c := config.GetConfig() listenerPort := strings.Split(listener.Addr().String(), ":")[1] - config.InternalHLSListenerPort = listenerPort + c.InternalHLSListenerPort = listenerPort log.Traceln("Transcoder response service listening on: " + listenerPort) go func() { //nolint: gosec @@ -59,8 +60,9 @@ func (s *FileWriterReceiverService) uploadHandler(w http.ResponseWriter, r *http return } + c := config.GetConfig() path := r.URL.Path - writePath := filepath.Join(config.HLSStoragePath, path) + writePath := filepath.Join(c.HLSStoragePath, path) f, err := os.Create(writePath) //nolint: gosec if err != nil { returnError(err, w) diff --git a/video/transcoder/thumbnailGenerator.go b/video/transcoder/thumbnailGenerator.go index 311e98b96..642eee720 100644 --- a/video/transcoder/thumbnailGenerator.go +++ b/video/transcoder/thumbnailGenerator.go @@ -10,8 +10,8 @@ import ( log "github.com/sirupsen/logrus" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/utils" ) @@ -52,9 +52,11 @@ func StartThumbnailGenerator(chunkPath string, variantIndex int, isVideoPassthro } func fireThumbnailGenerator(segmentPath string, variantIndex int) error { + c := config.GetConfig() + // JPG takes less time to encode than PNG - outputFile := path.Join(config.TempDir, "thumbnail.jpg") - previewGifFile := path.Join(config.TempDir, "preview.gif") + outputFile := path.Join(c.TempDir, "thumbnail.jpg") + previewGifFile := path.Join(c.TempDir, "preview.gif") framePath := path.Join(segmentPath, strconv.Itoa(variantIndex)) files, err := os.ReadDir(framePath) @@ -91,7 +93,7 @@ func fireThumbnailGenerator(segmentPath string, variantIndex int) error { mostRecentFile := path.Join(framePath, names[0]) ffmpegPath := utils.ValidatedFfmpegPath(data.GetFfMpegPath()) - outputFileTemp := path.Join(config.TempDir, "tempthumbnail.jpg") + outputFileTemp := path.Join(c.TempDir, "tempthumbnail.jpg") thumbnailCmdFlags := []string{ ffmpegPath, @@ -120,8 +122,9 @@ func fireThumbnailGenerator(segmentPath string, variantIndex int) error { } func makeAnimatedGifPreview(sourceFile string, outputFile string) { + c := config.GetConfig() ffmpegPath := utils.ValidatedFfmpegPath(data.GetFfMpegPath()) - outputFileTemp := path.Join(config.TempDir, "temppreview.gif") + outputFileTemp := path.Join(c.TempDir, "temppreview.gif") // Filter is pulled from https://engineering.giphy.com/how-to-make-gifs-with-ffmpeg/ animatedGifFlags := []string{ diff --git a/video/transcoder/transcoder.go b/video/transcoder/transcoder.go index ff1bbaa72..713e6d423 100644 --- a/video/transcoder/transcoder.go +++ b/video/transcoder/transcoder.go @@ -11,10 +11,10 @@ import ( log "github.com/sirupsen/logrus" "github.com/teris-io/shortid" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/logging" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/utils" ) @@ -120,7 +120,9 @@ func (t *Transcoder) Start(shouldLog bool) { } createVariantDirectories() - if config.EnableDebugFeatures { + c := config.GetConfig() + + if c.EnableDebugFeatures { log.Println(command) } @@ -274,16 +276,17 @@ func getVariantFromConfigQuality(quality models.StreamOutputVariant, index int) // NewTranscoder will return a new Transcoder, populated by the config. func NewTranscoder() *Transcoder { ffmpegPath := utils.ValidatedFfmpegPath(data.GetFfMpegPath()) + c := config.GetConfig() transcoder := new(Transcoder) transcoder.ffmpegPath = ffmpegPath - transcoder.internalListenerPort = config.InternalHLSListenerPort + transcoder.internalListenerPort = c.InternalHLSListenerPort transcoder.currentStreamOutputSettings = data.GetStreamOutputVariants() transcoder.currentLatencyLevel = data.GetStreamLatencyLevel() transcoder.codec = getCodec(data.GetVideoCodec()) - transcoder.segmentOutputPath = config.HLSStoragePath - transcoder.playlistOutputPath = config.HLSStoragePath + transcoder.segmentOutputPath = c.HLSStoragePath + transcoder.playlistOutputPath = c.HLSStoragePath transcoder.input = "pipe:0" // stdin diff --git a/video/transcoder/utils.go b/video/transcoder/utils.go index 18c9c8a2d..7dc53ec9c 100644 --- a/video/transcoder/utils.go +++ b/video/transcoder/utils.go @@ -7,8 +7,8 @@ import ( "strings" "sync" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/utils" log "github.com/sirupsen/logrus" ) @@ -97,17 +97,19 @@ func handleTranscoderMessage(message string) { } func createVariantDirectories() { + c := config.GetConfig() + // Create private hls data dirs - utils.CleanupDirectory(config.HLSStoragePath) + utils.CleanupDirectory(c.HLSStoragePath) if len(data.GetStreamOutputVariants()) != 0 { for index := range data.GetStreamOutputVariants() { - if err := os.MkdirAll(path.Join(config.HLSStoragePath, strconv.Itoa(index)), 0o750); err != nil { + if err := os.MkdirAll(path.Join(c.HLSStoragePath, strconv.Itoa(index)), 0o750); err != nil { log.Fatalln(err) } } } else { - dir := path.Join(config.HLSStoragePath, strconv.Itoa(0)) + dir := path.Join(c.HLSStoragePath, strconv.Itoa(0)) log.Traceln("Creating", dir) if err := os.MkdirAll(dir, 0o750); err != nil { log.Fatalln(err) diff --git a/webserver/handlers/adminApiEmojiConfig.go b/webserver/handlers/adminApiEmojiConfig.go index 086a489b0..21fea849b 100644 --- a/webserver/handlers/adminApiEmojiConfig.go +++ b/webserver/handlers/adminApiEmojiConfig.go @@ -7,7 +7,7 @@ import ( "os" "path/filepath" - "github.com/owncast/owncast/config" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/utils" "github.com/owncast/owncast/webserver/requests" "github.com/owncast/owncast/webserver/responses" @@ -38,10 +38,11 @@ func (h *Handlers) UploadCustomEmoji(w http.ResponseWriter, r *http.Request) { } // Prevent path traversal attacks + c := config.GetConfig() emojiFileName := filepath.Base(emoji.Name) - targetPath := filepath.Join(config.CustomEmojiPath, emojiFileName) + targetPath := filepath.Join(c.CustomEmojiPath, emojiFileName) - err = os.MkdirAll(config.CustomEmojiPath, 0o700) + err = os.MkdirAll(c.CustomEmojiPath, 0o700) if err != nil { responses.WriteSimpleResponse(w, false, err.Error()) return @@ -77,8 +78,8 @@ func (h *Handlers) DeleteCustomEmoji(w http.ResponseWriter, r *http.Request) { return } - // var emojiFileName = filepath.Base(emoji.Name) - targetPath := filepath.Join(config.CustomEmojiPath, emoji.Name) + c := config.GetConfig() + targetPath := filepath.Join(c.CustomEmojiPath, emoji.Name) if err := os.Remove(targetPath); err != nil { if os.IsNotExist(err) { diff --git a/webserver/handlers/adminApiExternalAPIUsers.go b/webserver/handlers/adminApiExternalAPIUsers.go index 09e0a26af..8fef13bfb 100644 --- a/webserver/handlers/adminApiExternalAPIUsers.go +++ b/webserver/handlers/adminApiExternalAPIUsers.go @@ -6,8 +6,9 @@ import ( "net/http" "time" - "github.com/owncast/owncast/config" - "github.com/owncast/owncast/core/user" + "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" + "github.com/owncast/owncast/storage" "github.com/owncast/owncast/utils" "github.com/owncast/owncast/webserver/responses" ) diff --git a/webserver/handlers/adminApiServerConfig.go b/webserver/handlers/adminApiServerConfig.go index 9b8a9fea2..8d5c7c34d 100644 --- a/webserver/handlers/adminApiServerConfig.go +++ b/webserver/handlers/adminApiServerConfig.go @@ -4,9 +4,9 @@ import ( "encoding/json" "net/http" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/utils" "github.com/owncast/owncast/video/transcoder" "github.com/owncast/owncast/webserver/middleware" @@ -18,6 +18,7 @@ func (h *Handlers) GetServerConfig(w http.ResponseWriter, r *http.Request) { ffmpeg := utils.ValidatedFfmpegPath(data.GetFfMpegPath()) usernameBlocklist := data.GetForbiddenUsernameList() usernameSuggestions := data.GetSuggestedUsernamesList() + c := config.GetConfig() videoQualityVariants := make([]models.StreamOutputVariant, 0) for _, variant := range data.GetStreamOutputVariants() { @@ -52,9 +53,9 @@ func (h *Handlers) GetServerConfig(w http.ResponseWriter, r *http.Request) { FFmpegPath: ffmpeg, AdminPassword: data.GetAdminPassword(), StreamKeys: data.GetStreamKeys(), - StreamKeyOverridden: config.TemporaryStreamKey != "", - WebServerPort: config.WebServerPort, - WebServerIP: config.WebServerIP, + StreamKeyOverridden: c.TemporaryStreamKey != "", + WebServerPort: c.WebServerPort, + WebServerIP: c.WebServerIP, RTMPServerPort: data.GetRTMPPortNumber(), ChatDisabled: data.GetChatDisabled(), ChatJoinMessagesEnabled: data.GetChatJoinPartMessagesEnabled(), diff --git a/webserver/handlers/adminApiSoftwareUpdate.go b/webserver/handlers/adminApiSoftwareUpdate.go index 217887f53..d39c25d6d 100644 --- a/webserver/handlers/adminApiSoftwareUpdate.go +++ b/webserver/handlers/adminApiSoftwareUpdate.go @@ -9,7 +9,7 @@ import ( "strconv" "strings" - "github.com/owncast/owncast/config" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/webserver/responses" log "github.com/sirupsen/logrus" ) @@ -44,9 +44,11 @@ func (h *Handlers) AutoUpdateOptions(w http.ResponseWriter, r *http.Request) { CanRestart: false, } + c := config.GetConfig() + // Nothing is supported when running under "dev" or the feature is // explicitly disabled. - if config.BuildPlatform == "dev" || !config.EnableAutoUpdate { + if c.BuildPlatform == "dev" || !c.EnableAutoUpdate { responses.WriteResponse(w, updateOptions) return } diff --git a/webserver/handlers/chat.go b/webserver/handlers/chat.go index 69c16aec8..b533e2010 100644 --- a/webserver/handlers/chat.go +++ b/webserver/handlers/chat.go @@ -5,9 +5,10 @@ import ( "errors" "net/http" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/chat" - "github.com/owncast/owncast/core/user" + "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" + "github.com/owncast/owncast/storage" "github.com/owncast/owncast/utils" "github.com/owncast/owncast/webserver/middleware" "github.com/owncast/owncast/webserver/responses" diff --git a/webserver/handlers/config.go b/webserver/handlers/config.go index cfabe0bbe..ef5692c88 100644 --- a/webserver/handlers/config.go +++ b/webserver/handlers/config.go @@ -7,9 +7,9 @@ import ( "net/url" "github.com/owncast/owncast/activitypub" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/utils" "github.com/owncast/owncast/webserver/middleware" "github.com/owncast/owncast/webserver/responses" @@ -118,13 +118,15 @@ func getConfigResponse() webConfigResponse { IndieAuthEnabled: data.GetServerURL() != "", } + c := config.GetConfig() + return webConfigResponse{ Name: data.GetServerName(), Summary: serverSummary, OfflineMessage: offlineMessage, Logo: "/logo", Tags: data.GetServerMetadataTags(), - Version: config.GetReleaseString(), + Version: c.GetReleaseString(), NSFW: data.GetNSFW(), SocketHostOverride: data.GetWebsocketOverrideHost(), ExtraPageContent: pageContent, diff --git a/webserver/handlers/emoji.go b/webserver/handlers/emoji.go index 302f988a9..4a6a4f90b 100644 --- a/webserver/handlers/emoji.go +++ b/webserver/handlers/emoji.go @@ -6,9 +6,9 @@ import ( "os" "strings" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/router/middleware" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/webserver/responses" ) @@ -27,7 +27,9 @@ func (h *Handlers) GetCustomEmojiImage(w http.ResponseWriter, r *http.Request) { path := strings.TrimPrefix(r.URL.Path, "/img/emoji/") r.URL.Path = path - emojiFS := os.DirFS(config.CustomEmojiPath) + c := config.GetConfig() + emojiFS := os.DirFS(c.CustomEmojiPath) middleware.SetCachingHeaders(w, r) + http.FileServer(http.FS(emojiFS)).ServeHTTP(w, r) } diff --git a/webserver/handlers/hls.go b/webserver/handlers/hls.go index c1c0a9645..a2d11e57b 100644 --- a/webserver/handlers/hls.go +++ b/webserver/handlers/hls.go @@ -7,10 +7,10 @@ import ( "strconv" "strings" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core" "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/utils" "github.com/owncast/owncast/webserver/middleware" ) @@ -23,9 +23,11 @@ func (h *Handlers) HandleHLSRequest(w http.ResponseWriter, r *http.Request) { return } + c := config.GetConfig() + requestedPath := r.URL.Path relativePath := strings.Replace(requestedPath, "/hls/", "", 1) - fullPath := filepath.Join(config.HLSStoragePath, relativePath) + fullPath := filepath.Join(c.HLSStoragePath, relativePath) // If using external storage then only allow requests for the // master playlist at stream.m3u8, no variants or segments. diff --git a/webserver/handlers/images.go b/webserver/handlers/images.go index ff70810a4..8d2171fb3 100644 --- a/webserver/handlers/images.go +++ b/webserver/handlers/images.go @@ -4,7 +4,7 @@ import ( "net/http" "path/filepath" - "github.com/owncast/owncast/config" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/utils" "github.com/owncast/owncast/webserver/responses" ) @@ -16,8 +16,9 @@ const ( // GetThumbnail will return the thumbnail image as a response. func (h *Handlers) GetThumbnail(w http.ResponseWriter, r *http.Request) { + c := config.GetConfig() imageFilename := "thumbnail.jpg" - imagePath := filepath.Join(config.TempDir, imageFilename) + imagePath := filepath.Join(c.TempDir, imageFilename) var imageBytes []byte var err error @@ -40,8 +41,9 @@ func (h *Handlers) GetThumbnail(w http.ResponseWriter, r *http.Request) { // GetPreview will return the preview gif as a response. func (h *Handlers) GetPreview(w http.ResponseWriter, r *http.Request) { + c := config.GetConfig() imageFilename := "preview.gif" - imagePath := filepath.Join(config.TempDir, imageFilename) + imagePath := filepath.Join(c.TempDir, imageFilename) var imageBytes []byte var err error diff --git a/webserver/handlers/logo.go b/webserver/handlers/logo.go index 67a8debca..86cba6ad5 100644 --- a/webserver/handlers/logo.go +++ b/webserver/handlers/logo.go @@ -5,8 +5,8 @@ import ( "os" "path/filepath" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/data" + "github.com/owncast/owncast/services/config" "github.com/owncast/owncast/static" "github.com/owncast/owncast/utils" "github.com/owncast/owncast/webserver/responses" diff --git a/webserver/router.go b/webserver/router.go index 0f17d102e..556689531 100644 --- a/webserver/router.go +++ b/webserver/router.go @@ -4,10 +4,10 @@ import ( "net/http" "github.com/owncast/owncast/activitypub" - "github.com/owncast/owncast/config" "github.com/owncast/owncast/core/chat" "github.com/owncast/owncast/core/data" - "github.com/owncast/owncast/core/user" + "github.com/owncast/owncast/services/config" + "github.com/owncast/owncast/storage" "github.com/owncast/owncast/utils" fediverseauth "github.com/owncast/owncast/webserver/handlers/auth/fediverse" "github.com/owncast/owncast/webserver/handlers/auth/indieauth" @@ -49,6 +49,8 @@ func (s *webServer) setupRoutes() { } func (s *webServer) setupWebAssetRoutes() { + c := config.GetConfig() + // The admin web app. s.router.HandleFunc("/admin/", middleware.RequireAdminAuth(s.handlers.IndexHandler)) @@ -72,7 +74,7 @@ func (s *webServer) setupWebAssetRoutes() { s.router.HandleFunc("/robots.txt", s.handlers.GetRobotsDotTxt) // Optional public static files - s.router.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir(config.PublicFilesPath)))) + s.router.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir(c.PublicFilesPath)))) } func (s *webServer) setupInternalAPIRoutes() {