From 73b69374960b40d4b84ed7c803bd32ef35612967 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Sun, 28 Jun 2020 15:10:00 -0700 Subject: [PATCH] Consolidate config files and surface frontend values via API. Closes #30 --- config-example.yaml | 20 ++++++++++++++++++++ config/config.go | 29 +++++++++++++++++++++-------- controllers/config.go | 18 ++++++++++++++++++ router/router.go | 3 +++ webroot/js/config.js | 2 +- webroot/js/config.json | 21 --------------------- 6 files changed, 63 insertions(+), 30 deletions(-) create mode 100644 controllers/config.go delete mode 100644 webroot/js/config.json diff --git a/config-example.yaml b/config-example.yaml index 1e8a3e8bb8..8033fc3fc8 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -3,6 +3,26 @@ privateHLSPath: hls ffmpegPath: /usr/bin/ffmpeg webServerPort: 8080 +instanceDetails: + name: Owncast + title: Owncast Demo Server + logo: /img/logo128.png + summary: "This is brief summary of whom you are or what your stream is. demo server for Owncast. You can read more about it at owncast.online. You can edit this description in your web config file.\n\nBlathers is an owl with brown feathers. His face is white and he has a yellow beak. His arms are wing shaped and he has yellow talons. His eyes are very big with small black irises. He also has big pink cheek circles on his cheeks. His belly appears to be checkered in diamonds with light brown and white squares, similar to an argyle vest, which is traditionally associated with academia. His green bowtie further alludes to his academic nature." + extraUserInfoFileName: "/static/content.md" + + tags: + - music + - software + - animal crossing + + # See documentation for full list of supported social links. All optional. + socialHandles: + twitter: http://twitter.com/owncast + instagram: http://instagram.biz/owncast + facebook: http://facebook.gov/owncast + tiktok: http://tiktok.cn/owncast + soundcloud: http://soundcloud.com/owncast + videoSettings: chunkLengthInSeconds: 4 streamingKey: abc123 diff --git a/config/config.go b/config/config.go index 7419537539..0b67e4ba3e 100644 --- a/config/config.go +++ b/config/config.go @@ -15,14 +15,26 @@ import ( var Config *config type config struct { - IPFS ipfs `yaml:"ipfs"` - PublicHLSPath string `yaml:"publicHLSPath"` - PrivateHLSPath string `yaml:"privateHLSPath"` - VideoSettings videoSettings `yaml:"videoSettings"` - Files files `yaml:"files"` - FFMpegPath string `yaml:"ffmpegPath"` - WebServerPort int `yaml:"webServerPort"` - S3 s3 `yaml:"s3"` + IPFS ipfs `yaml:"ipfs"` + PublicHLSPath string `yaml:"publicHLSPath"` + PrivateHLSPath string `yaml:"privateHLSPath"` + VideoSettings videoSettings `yaml:"videoSettings"` + Files files `yaml:"files"` + FFMpegPath string `yaml:"ffmpegPath"` + WebServerPort int `yaml:"webServerPort"` + S3 s3 `yaml:"s3"` + InstanceDetails InstanceDetails `yaml:"instanceDetails"` +} + +// InstanceDetails defines the user-visible information about this particular instance. +type InstanceDetails struct { + Name string `yaml:"name" json:"name"` + Title string `yaml:"title" json:"title"` + Summary string `yaml:"summary" json:"summary"` + Logo string `yaml:"logo" json:"logo"` + Tags []string `yaml:"tags" json:"tags"` + SocialHandles map[string]string `yaml:"socialHandles" json:"socialHandles"` + ExtraInfoFile string `yaml:"extraUserInfoFileName" json:"extraUserInfoFileName"` } type videoSettings struct { @@ -33,6 +45,7 @@ type videoSettings struct { EnablePassthrough bool `yaml:"passthrough"` } +// StreamQuality defines the specifics of a single HLS stream variant. type StreamQuality struct { // Enable passthrough to copy the video and/or audio directly from the // incoming stream and disable any transcoding. It will ignore any of diff --git a/controllers/config.go b/controllers/config.go new file mode 100644 index 0000000000..502029a816 --- /dev/null +++ b/controllers/config.go @@ -0,0 +1,18 @@ +package controllers + +import ( + "encoding/json" + "net/http" + + "github.com/gabek/owncast/config" + "github.com/gabek/owncast/router/middleware" +) + +//GetWebConfig gets the status of the server +func GetWebConfig(w http.ResponseWriter, r *http.Request) { + middleware.EnableCors(&w) + + config := config.Config.InstanceDetails + + json.NewEncoder(w).Encode(config) +} diff --git a/router/router.go b/router/router.go index 7acc7936c8..a7dd6ae89f 100644 --- a/router/router.go +++ b/router/router.go @@ -29,6 +29,9 @@ func Start() error { // chat rest api http.HandleFunc("/chat", controllers.GetChatMessages) + // web config api + http.HandleFunc("/config", controllers.GetWebConfig) + port := config.Config.WebServerPort log.Printf("Starting public web server on port: %d", port) diff --git a/webroot/js/config.js b/webroot/js/config.js index a3538abeb9..1602ea62e2 100644 --- a/webroot/js/config.js +++ b/webroot/js/config.js @@ -1,7 +1,7 @@ // add more to the promises later. class Config { async init() { - const configFileLocation = "./js/config.json"; + const configFileLocation = "/config"; try { const response = await fetch(configFileLocation); diff --git a/webroot/js/config.json b/webroot/js/config.json deleted file mode 100644 index a83b98954e..0000000000 --- a/webroot/js/config.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "gabek", - "title": "Owncast Demo Server", - "logo": "/img/logo128.png", - - "summary": "This is brief summary of whom you are or what your stream is. demo server for Owncast. You can read more about it at owncast.online. You can edit this description in your web config file.\n\nBlathers is an owl with brown feathers. His face is white and he has a yellow beak. His arms are wing shaped and he has yellow talons. His eyes are very big with small black irises. He also has big pink cheek circles on his cheeks. His belly appears to be checkered in diamonds with light brown and white squares, similar to an argyle vest, which is traditionally associated with academia. His green bowtie further alludes to his academic nature.", - - "tags": [ - "music", - "software", - "animal crossing" - ], - "socialHandles": [ - { "platform": "twitter", "handle": "abc" }, - { "platform": "instagram", "handle": "abc" }, - { "platform": "facebook", "handle": "" }, - { "platform": "tiktok", "handle": "abc" }, - { "platform": "soundcloud", "handle": "abc" }, - { "platform": "newone", "handle": "abc" } - ] -} \ No newline at end of file