Remove custom paths and add constants (#216)
This commit is contained in:
parent
f30cfcf20f
commit
922dfec77a
@ -15,15 +15,12 @@ var _default config
|
|||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
ChatDatabaseFilePath string `yaml:"chatDatabaseFile"`
|
ChatDatabaseFilePath string `yaml:"chatDatabaseFile"`
|
||||||
DisableWebFeatures bool `yaml:"disableWebFeatures"`
|
|
||||||
EnableDebugFeatures bool `yaml:"-"`
|
EnableDebugFeatures bool `yaml:"-"`
|
||||||
FFMpegPath string `yaml:"ffmpegPath"`
|
FFMpegPath string `yaml:"ffmpegPath"`
|
||||||
Files files `yaml:"files"`
|
Files files `yaml:"files"`
|
||||||
InstanceDetails InstanceDetails `yaml:"instanceDetails"`
|
InstanceDetails InstanceDetails `yaml:"instanceDetails"`
|
||||||
PrivateHLSPath string `yaml:"privateHLSPath"`
|
|
||||||
PublicHLSPath string `yaml:"publicHLSPath"`
|
|
||||||
S3 S3 `yaml:"s3"`
|
S3 S3 `yaml:"s3"`
|
||||||
VersionInfo string `yaml:"-"`
|
VersionInfo string `yaml:"-"` // For storing the version/build number
|
||||||
VideoSettings videoSettings `yaml:"videoSettings"`
|
VideoSettings videoSettings `yaml:"videoSettings"`
|
||||||
WebServerPort int `yaml:"webServerPort"`
|
WebServerPort int `yaml:"webServerPort"`
|
||||||
YP yp `yaml:"yp"`
|
YP yp `yaml:"yp"`
|
||||||
@ -158,22 +155,6 @@ func (c *config) GetVideoSegmentSecondsLength() int {
|
|||||||
return _default.GetVideoSegmentSecondsLength()
|
return _default.GetVideoSegmentSecondsLength()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *config) GetPublicHLSSavePath() string {
|
|
||||||
if c.PublicHLSPath != "" {
|
|
||||||
return c.PublicHLSPath
|
|
||||||
}
|
|
||||||
|
|
||||||
return _default.PublicHLSPath
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *config) GetPrivateHLSSavePath() string {
|
|
||||||
if c.PrivateHLSPath != "" {
|
|
||||||
return c.PrivateHLSPath
|
|
||||||
}
|
|
||||||
|
|
||||||
return _default.PrivateHLSPath
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *config) GetPublicWebServerPort() int {
|
func (c *config) GetPublicWebServerPort() int {
|
||||||
if c.WebServerPort != 0 {
|
if c.WebServerPort != 0 {
|
||||||
return c.WebServerPort
|
return c.WebServerPort
|
||||||
|
12
config/constants.go
Normal file
12
config/constants.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import "path/filepath"
|
||||||
|
|
||||||
|
const (
|
||||||
|
WebRoot = "webroot"
|
||||||
|
PrivateHLSStoragePath = "hls"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
PublicHLSStoragePath = filepath.Join(WebRoot, "hls")
|
||||||
|
)
|
@ -12,8 +12,6 @@ func getDefaults() config {
|
|||||||
defaults.FFMpegPath = getDefaultFFMpegPath()
|
defaults.FFMpegPath = getDefaultFFMpegPath()
|
||||||
defaults.VideoSettings.ChunkLengthInSeconds = 4
|
defaults.VideoSettings.ChunkLengthInSeconds = 4
|
||||||
defaults.Files.MaxNumberInPlaylist = 5
|
defaults.Files.MaxNumberInPlaylist = 5
|
||||||
defaults.PublicHLSPath = "webroot/hls"
|
|
||||||
defaults.PrivateHLSPath = "hls"
|
|
||||||
defaults.VideoSettings.OfflineContent = "static/offline.m4v"
|
defaults.VideoSettings.OfflineContent = "static/offline.m4v"
|
||||||
defaults.InstanceDetails.ExtraInfoFile = "/static/content.md"
|
defaults.InstanceDetails.ExtraInfoFile = "/static/content.md"
|
||||||
defaults.YP.Enabled = false
|
defaults.YP.Enabled = false
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gabek/owncast/config"
|
||||||
"github.com/gabek/owncast/models"
|
"github.com/gabek/owncast/models"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -20,7 +21,7 @@ const emojiPath = "/img/emoji" // Relative to webroot
|
|||||||
func GetCustomEmoji(w http.ResponseWriter, r *http.Request) {
|
func GetCustomEmoji(w http.ResponseWriter, r *http.Request) {
|
||||||
emojiList := make([]models.CustomEmoji, 0)
|
emojiList := make([]models.CustomEmoji, 0)
|
||||||
|
|
||||||
fullPath := filepath.Join("webroot", emojiPath)
|
fullPath := filepath.Join(config.WebRoot, emojiPath)
|
||||||
files, err := ioutil.ReadDir(fullPath)
|
files, err := ioutil.ReadDir(fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln(err)
|
log.Errorln(err)
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
@ -30,13 +31,6 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
isIndexRequest := r.URL.Path == "/" || r.URL.Path == "/index.html"
|
isIndexRequest := r.URL.Path == "/" || r.URL.Path == "/index.html"
|
||||||
|
|
||||||
// Reject requests for the web UI if it's disabled.
|
|
||||||
if isIndexRequest && config.Config.DisableWebFeatures {
|
|
||||||
w.WriteHeader(http.StatusNotFound)
|
|
||||||
w.Write([]byte("404 - y u ask 4 this? If this is an error let us know: https://github.com/owncast/owncast/issues"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// For search engine bots and social scrapers return a special
|
// For search engine bots and social scrapers return a special
|
||||||
// server-rendered page.
|
// server-rendered page.
|
||||||
if utils.IsUserAgentABot(r.UserAgent()) && isIndexRequest {
|
if utils.IsUserAgentABot(r.UserAgent()) && isIndexRequest {
|
||||||
@ -60,7 +54,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Set a cache control max-age header
|
// Set a cache control max-age header
|
||||||
middleware.SetCachingHeaders(w, r)
|
middleware.SetCachingHeaders(w, r)
|
||||||
|
|
||||||
http.ServeFile(w, r, path.Join("webroot", r.URL.Path))
|
http.ServeFile(w, r, path.Join(config.WebRoot, r.URL.Path))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a basic HTML page with server-rendered metadata from the config file
|
// Return a basic HTML page with server-rendered metadata from the config file
|
||||||
@ -75,7 +69,7 @@ func handleScraperMetadataPage(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// If the thumbnail does not exist or we're offline then just use the logo image
|
// If the thumbnail does not exist or we're offline then just use the logo image
|
||||||
var thumbnailURL string
|
var thumbnailURL string
|
||||||
if status.Online && utils.DoesFileExists("webroot/thumbnail.jpg") {
|
if status.Online && utils.DoesFileExists(filepath.Join(config.WebRoot, "thumbnail.jpg")) {
|
||||||
thumbnail, err := url.Parse(fmt.Sprintf("http://%s%s", r.Host, "/thumbnail.jpg"))
|
thumbnail, err := url.Parse(fmt.Sprintf("http://%s%s", r.Host, "/thumbnail.jpg"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln(err)
|
log.Errorln(err)
|
||||||
|
23
core/core.go
23
core/core.go
@ -3,6 +3,7 @@ package core
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -56,8 +57,8 @@ func Start() error {
|
|||||||
|
|
||||||
func createInitialOfflineState() error {
|
func createInitialOfflineState() error {
|
||||||
// Provide default files
|
// Provide default files
|
||||||
if !utils.DoesFileExists("webroot/thumbnail.jpg") {
|
if !utils.DoesFileExists(filepath.Join(config.WebRoot, "thumbnail.jpg")) {
|
||||||
if err := utils.Copy("static/logo.png", "webroot/thumbnail.jpg"); err != nil {
|
if err := utils.Copy("static/logo.png", filepath.Join(config.WebRoot, "thumbnail.jpg")); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,22 +94,22 @@ func resetDirectories() {
|
|||||||
log.Trace("Resetting file directories to a clean slate.")
|
log.Trace("Resetting file directories to a clean slate.")
|
||||||
|
|
||||||
// Wipe the public, web-accessible hls data directory
|
// Wipe the public, web-accessible hls data directory
|
||||||
os.RemoveAll(config.Config.GetPublicHLSSavePath())
|
os.RemoveAll(config.PublicHLSStoragePath)
|
||||||
os.RemoveAll(config.Config.GetPrivateHLSSavePath())
|
os.RemoveAll(config.PrivateHLSStoragePath)
|
||||||
os.MkdirAll(config.Config.GetPublicHLSSavePath(), 0777)
|
os.MkdirAll(config.PublicHLSStoragePath, 0777)
|
||||||
os.MkdirAll(config.Config.GetPrivateHLSSavePath(), 0777)
|
os.MkdirAll(config.PrivateHLSStoragePath, 0777)
|
||||||
|
|
||||||
// Remove the previous thumbnail
|
// Remove the previous thumbnail
|
||||||
os.Remove("webroot/thumbnail.jpg")
|
os.Remove(filepath.Join(config.WebRoot, "thumbnail.jpg"))
|
||||||
|
|
||||||
// Create private hls data dirs
|
// Create private hls data dirs
|
||||||
if len(config.Config.VideoSettings.StreamQualities) != 0 {
|
if len(config.Config.VideoSettings.StreamQualities) != 0 {
|
||||||
for index := range config.Config.VideoSettings.StreamQualities {
|
for index := range config.Config.VideoSettings.StreamQualities {
|
||||||
os.MkdirAll(path.Join(config.Config.GetPrivateHLSSavePath(), strconv.Itoa(index)), 0777)
|
os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(index)), 0777)
|
||||||
os.MkdirAll(path.Join(config.Config.GetPublicHLSSavePath(), strconv.Itoa(index)), 0777)
|
os.MkdirAll(path.Join(config.PublicHLSStoragePath, strconv.Itoa(index)), 0777)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
os.MkdirAll(path.Join(config.Config.GetPrivateHLSSavePath(), strconv.Itoa(0)), 0777)
|
os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(0)), 0777)
|
||||||
os.MkdirAll(path.Join(config.Config.GetPublicHLSSavePath(), strconv.Itoa(0)), 0777)
|
os.MkdirAll(path.Join(config.PublicHLSStoragePath, strconv.Itoa(0)), 0777)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,8 @@ func StartThumbnailGenerator(chunkPath string, variantIndex int) {
|
|||||||
|
|
||||||
func fireThumbnailGenerator(chunkPath string, variantIndex int) error {
|
func fireThumbnailGenerator(chunkPath string, variantIndex int) error {
|
||||||
// JPG takes less time to encode than PNG
|
// JPG takes less time to encode than PNG
|
||||||
outputFile := path.Join("webroot", "thumbnail.jpg")
|
outputFile := path.Join(config.WebRoot, "thumbnail.jpg")
|
||||||
previewGifFile := path.Join("webroot", "preview.gif")
|
previewGifFile := path.Join(config.WebRoot, "preview.gif")
|
||||||
|
|
||||||
framePath := path.Join(chunkPath, strconv.Itoa(variantIndex))
|
framePath := path.Join(chunkPath, strconv.Itoa(variantIndex))
|
||||||
files, err := ioutil.ReadDir(framePath)
|
files, err := ioutil.ReadDir(framePath)
|
||||||
|
@ -188,15 +188,15 @@ func NewTranscoder() Transcoder {
|
|||||||
var outputPath string
|
var outputPath string
|
||||||
if config.Config.S3.Enabled {
|
if config.Config.S3.Enabled {
|
||||||
// Segments are not available via the local HTTP server
|
// Segments are not available via the local HTTP server
|
||||||
outputPath = config.Config.GetPrivateHLSSavePath()
|
outputPath = config.PrivateHLSStoragePath
|
||||||
} else {
|
} else {
|
||||||
// Segments are available via the local HTTP server
|
// Segments are available via the local HTTP server
|
||||||
outputPath = config.Config.GetPublicHLSSavePath()
|
outputPath = config.PublicHLSStoragePath
|
||||||
}
|
}
|
||||||
|
|
||||||
transcoder.segmentOutputPath = outputPath
|
transcoder.segmentOutputPath = outputPath
|
||||||
// Playlists are available via the local HTTP server
|
// Playlists are available via the local HTTP server
|
||||||
transcoder.playlistOutputPath = config.Config.GetPublicHLSSavePath()
|
transcoder.playlistOutputPath = config.PublicHLSStoragePath
|
||||||
|
|
||||||
transcoder.input = utils.GetTemporaryPipePath()
|
transcoder.input = utils.GetTemporaryPipePath()
|
||||||
transcoder.segmentLengthSeconds = config.Config.GetVideoSegmentSecondsLength()
|
transcoder.segmentLengthSeconds = config.Config.GetVideoSegmentSecondsLength()
|
||||||
|
@ -26,7 +26,7 @@ var (
|
|||||||
func StartVideoContentMonitor(storage models.ChunkStorageProvider) error {
|
func StartVideoContentMonitor(storage models.ChunkStorageProvider) error {
|
||||||
_storage = storage
|
_storage = storage
|
||||||
|
|
||||||
pathToMonitor := config.Config.GetPrivateHLSSavePath()
|
pathToMonitor := config.PrivateHLSStoragePath
|
||||||
|
|
||||||
// Create at least one structure to store the segments for the different stream variants
|
// Create at least one structure to store the segments for the different stream variants
|
||||||
variants = make([]models.Variant, len(config.Config.VideoSettings.StreamQualities))
|
variants = make([]models.Variant, len(config.Config.VideoSettings.StreamQualities))
|
||||||
@ -63,11 +63,9 @@ func StartVideoContentMonitor(storage models.ChunkStorageProvider) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt.Println(event.Op, relativePath)
|
|
||||||
|
|
||||||
// Handle updates to the master playlist by copying it to webroot
|
// Handle updates to the master playlist by copying it to webroot
|
||||||
if relativePath == path.Join(config.Config.GetPrivateHLSSavePath(), "stream.m3u8") {
|
if relativePath == path.Join(config.PrivateHLSStoragePath, "stream.m3u8") {
|
||||||
utils.Copy(event.Path, path.Join(config.Config.GetPublicHLSSavePath(), "stream.m3u8"))
|
utils.Copy(event.Path, path.Join(config.PublicHLSStoragePath, "stream.m3u8"))
|
||||||
|
|
||||||
} else if filepath.Ext(event.Path) == ".m3u8" {
|
} else if filepath.Ext(event.Path) == ".m3u8" {
|
||||||
// Handle updates to playlists, but not the master playlist
|
// Handle updates to playlists, but not the master playlist
|
||||||
@ -82,7 +80,7 @@ func StartVideoContentMonitor(storage models.ChunkStorageProvider) error {
|
|||||||
|
|
||||||
newObjectPathChannel := make(chan string, 1)
|
newObjectPathChannel := make(chan string, 1)
|
||||||
go func() {
|
go func() {
|
||||||
newObjectPath, err := storage.Save(path.Join(config.Config.GetPrivateHLSSavePath(), segment.RelativeUploadPath), 0)
|
newObjectPath, err := storage.Save(path.Join(config.PrivateHLSStoragePath, segment.RelativeUploadPath), 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("failed to save the file to the chunk storage.", err)
|
log.Errorln("failed to save the file to the chunk storage.", err)
|
||||||
}
|
}
|
||||||
@ -155,5 +153,5 @@ func updateVariantPlaylist(fullPath string) error {
|
|||||||
playlistString := string(playlistBytes)
|
playlistString := string(playlistBytes)
|
||||||
playlistString = _storage.GenerateRemotePlaylist(playlistString, variant)
|
playlistString = _storage.GenerateRemotePlaylist(playlistString, variant)
|
||||||
|
|
||||||
return WritePlaylist(playlistString, path.Join(config.Config.GetPublicHLSSavePath(), relativePath))
|
return WritePlaylist(playlistString, path.Join(config.PublicHLSStoragePath, relativePath))
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,9 @@ func SetStreamAsConnected() {
|
|||||||
_stats.LastConnectTime = utils.NullTime{time.Now(), true}
|
_stats.LastConnectTime = utils.NullTime{time.Now(), true}
|
||||||
_stats.LastDisconnectTime = utils.NullTime{time.Now(), false}
|
_stats.LastDisconnectTime = utils.NullTime{time.Now(), false}
|
||||||
|
|
||||||
chunkPath := config.Config.GetPublicHLSSavePath()
|
chunkPath := config.PublicHLSStoragePath
|
||||||
if usingExternalStorage {
|
if usingExternalStorage {
|
||||||
chunkPath = config.Config.GetPrivateHLSSavePath()
|
chunkPath = config.PrivateHLSStoragePath
|
||||||
}
|
}
|
||||||
|
|
||||||
if _yp != nil {
|
if _yp != nil {
|
||||||
|
@ -94,7 +94,7 @@ func (s *S3Storage) GenerateRemotePlaylist(playlist string, variant models.Varia
|
|||||||
if fullRemotePath == nil {
|
if fullRemotePath == nil {
|
||||||
line = ""
|
line = ""
|
||||||
} else if s.s3ServingEndpoint != "" {
|
} else if s.s3ServingEndpoint != "" {
|
||||||
line = fmt.Sprintf("%s/%s/%s", s.s3ServingEndpoint, config.Config.GetPrivateHLSSavePath(), fullRemotePath.RelativeUploadPath)
|
line = fmt.Sprintf("%s/%s/%s", s.s3ServingEndpoint, config.PrivateHLSStoragePath, fullRemotePath.RelativeUploadPath)
|
||||||
} else {
|
} else {
|
||||||
line = fullRemotePath.RemoteID
|
line = fullRemotePath.RemoteID
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ func Start() error {
|
|||||||
// custom emoji supported in the chat
|
// custom emoji supported in the chat
|
||||||
http.HandleFunc("/api/emoji", controllers.GetCustomEmoji)
|
http.HandleFunc("/api/emoji", controllers.GetCustomEmoji)
|
||||||
|
|
||||||
if !config.Config.DisableWebFeatures {
|
|
||||||
// websocket chat server
|
// websocket chat server
|
||||||
go chat.Start()
|
go chat.Start()
|
||||||
|
|
||||||
@ -47,7 +46,6 @@ func Start() error {
|
|||||||
http.HandleFunc("/embed/video", controllers.GetVideoEmbed)
|
http.HandleFunc("/embed/video", controllers.GetVideoEmbed)
|
||||||
|
|
||||||
http.HandleFunc("/api/yp", yp.GetYPResponse)
|
http.HandleFunc("/api/yp", yp.GetYPResponse)
|
||||||
}
|
|
||||||
|
|
||||||
// Authenticated admin requests
|
// Authenticated admin requests
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user