* First pass at centralized database reference. Closes #282 * Add verbose logging option to launch.json * Clear current broadcaster on stream end. Closes #285 * Fix typo in verbose launch args * Add support for purging tailwind styles. For #224 * Don't need to pass db as param since it is stored * Commit updated Javascript packages Co-authored-by: Owncast <owncast@owncast.online>
This commit is contained in:
parent
6d0aa4bdd1
commit
19e86b8c04
1
.gitignore
vendored
1
.gitignore
vendored
@ -30,3 +30,4 @@ chat.db
|
|||||||
.yp.key
|
.yp.key
|
||||||
|
|
||||||
!webroot/js/web_modules/**/dist
|
!webroot/js/web_modules/**/dist
|
||||||
|
!core/data
|
||||||
|
@ -14,16 +14,16 @@ var Config *config
|
|||||||
var _default config
|
var _default config
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
ChatDatabaseFilePath string `yaml:"chatDatabaseFile"`
|
DatabaseFilePath string `yaml:"databaseFile"`
|
||||||
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"`
|
||||||
S3 S3 `yaml:"s3"`
|
S3 S3 `yaml:"s3"`
|
||||||
VersionInfo string `yaml:"-"` // For storing the version/build number
|
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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstanceDetails defines the user-visible information about this particular instance.
|
// InstanceDetails defines the user-visible information about this particular instance.
|
||||||
@ -193,6 +193,14 @@ func (c *config) GetYPServiceHost() string {
|
|||||||
return _default.YP.YPServiceURL
|
return _default.YP.YPServiceURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *config) GetDataFilePath() string {
|
||||||
|
if c.DatabaseFilePath != "" {
|
||||||
|
return c.DatabaseFilePath
|
||||||
|
}
|
||||||
|
|
||||||
|
return _default.DatabaseFilePath
|
||||||
|
}
|
||||||
|
|
||||||
func (c *config) GetVideoStreamQualities() []StreamQuality {
|
func (c *config) GetVideoStreamQualities() []StreamQuality {
|
||||||
if len(c.VideoSettings.StreamQualities) > 0 {
|
if len(c.VideoSettings.StreamQualities) > 0 {
|
||||||
return c.VideoSettings.StreamQualities
|
return c.VideoSettings.StreamQualities
|
||||||
|
@ -15,6 +15,7 @@ func getDefaults() config {
|
|||||||
defaults.Files.MaxNumberInPlaylist = 5
|
defaults.Files.MaxNumberInPlaylist = 5
|
||||||
defaults.YP.Enabled = false
|
defaults.YP.Enabled = false
|
||||||
defaults.YP.YPServiceURL = "https://yp.owncast.online"
|
defaults.YP.YPServiceURL = "https://yp.owncast.online"
|
||||||
|
defaults.DatabaseFilePath = "data/owncast.db"
|
||||||
|
|
||||||
defaultQuality := StreamQuality{
|
defaultQuality := StreamQuality{
|
||||||
IsAudioPassthrough: true,
|
IsAudioPassthrough: true,
|
||||||
|
@ -2,36 +2,22 @@ package chat
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"github.com/owncast/owncast/config"
|
"github.com/owncast/owncast/core/data"
|
||||||
"github.com/owncast/owncast/models"
|
"github.com/owncast/owncast/models"
|
||||||
"github.com/owncast/owncast/utils"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _db *sql.DB
|
var _db *sql.DB
|
||||||
|
|
||||||
func setupPersistence() {
|
func setupPersistence() {
|
||||||
file := config.Config.ChatDatabaseFilePath
|
_db = data.GetDatabase()
|
||||||
// Create empty DB file if it doesn't exist.
|
createTable()
|
||||||
if !utils.DoesFileExists(file) {
|
|
||||||
log.Traceln("Creating new chat history database at", file)
|
|
||||||
|
|
||||||
_, err := os.Create(file)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sqliteDatabase, _ := sql.Open("sqlite3", file)
|
|
||||||
_db = sqliteDatabase
|
|
||||||
createTable(sqliteDatabase)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTable(db *sql.DB) {
|
func createTable() {
|
||||||
createTableSQL := `CREATE TABLE IF NOT EXISTS messages (
|
createTableSQL := `CREATE TABLE IF NOT EXISTS messages (
|
||||||
"id" string NOT NULL PRIMARY KEY,
|
"id" string NOT NULL PRIMARY KEY,
|
||||||
"author" TEXT,
|
"author" TEXT,
|
||||||
|
37
core/data/data.go
Normal file
37
core/data/data.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// This is a centralized place to connect to the database, and hold a reference to it.
|
||||||
|
// Other packages can share this reference. This package would also be a place to add any kind of
|
||||||
|
// persistence-related convenience methods or migrations.
|
||||||
|
|
||||||
|
package data
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/owncast/owncast/config"
|
||||||
|
"github.com/owncast/owncast/utils"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _db *sql.DB
|
||||||
|
|
||||||
|
func GetDatabase() *sql.DB {
|
||||||
|
return _db
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetupPersistence() {
|
||||||
|
file := config.Config.DatabaseFilePath
|
||||||
|
|
||||||
|
// Create empty DB file if it doesn't exist.
|
||||||
|
if !utils.DoesFileExists(file) {
|
||||||
|
log.Traceln("Creating new database at", file)
|
||||||
|
|
||||||
|
_, err := os.Create(file)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sqliteDatabase, _ := sql.Open("sqlite3", file)
|
||||||
|
_db = sqliteDatabase
|
||||||
|
}
|
13
main.go
13
main.go
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/owncast/owncast/config"
|
"github.com/owncast/owncast/config"
|
||||||
"github.com/owncast/owncast/core"
|
"github.com/owncast/owncast/core"
|
||||||
|
"github.com/owncast/owncast/core/data"
|
||||||
"github.com/owncast/owncast/metrics"
|
"github.com/owncast/owncast/metrics"
|
||||||
"github.com/owncast/owncast/router"
|
"github.com/owncast/owncast/router"
|
||||||
)
|
)
|
||||||
@ -29,7 +30,7 @@ func main() {
|
|||||||
log.Infoln(getVersion())
|
log.Infoln(getVersion())
|
||||||
|
|
||||||
configFile := flag.String("configFile", "config.yaml", "Config File full path. Defaults to current folder")
|
configFile := flag.String("configFile", "config.yaml", "Config File full path. Defaults to current folder")
|
||||||
chatDbFile := flag.String("chatDatabase", "", "Path to the chat database file.")
|
dbFile := flag.String("database", "", "Path to the database file.")
|
||||||
enableDebugOptions := flag.Bool("enableDebugFeatures", false, "Enable additional debugging options.")
|
enableDebugOptions := flag.Bool("enableDebugFeatures", false, "Enable additional debugging options.")
|
||||||
enableVerboseLogging := flag.Bool("enableVerboseLogging", false, "Enable additional logging.")
|
enableVerboseLogging := flag.Bool("enableVerboseLogging", false, "Enable additional logging.")
|
||||||
|
|
||||||
@ -50,14 +51,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
config.Config.EnableDebugFeatures = *enableDebugOptions
|
config.Config.EnableDebugFeatures = *enableDebugOptions
|
||||||
|
|
||||||
if *chatDbFile != "" {
|
if *dbFile != "" {
|
||||||
config.Config.ChatDatabaseFilePath = *chatDbFile
|
config.Config.DatabaseFilePath = *dbFile
|
||||||
} else if config.Config.ChatDatabaseFilePath == "" {
|
} else if config.Config.DatabaseFilePath == "" {
|
||||||
config.Config.ChatDatabaseFilePath = "chat.db"
|
config.Config.DatabaseFilePath = config.Config.GetDataFilePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
go metrics.Start()
|
go metrics.Start()
|
||||||
|
|
||||||
|
data.SetupPersistence()
|
||||||
|
|
||||||
// starts the core
|
// starts the core
|
||||||
if err := core.Start(); err != nil {
|
if err := core.Start(); err != nil {
|
||||||
log.Error("failed to start the core package")
|
log.Error("failed to start the core package")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user