Set and get custom styling for web interface. For #718
This commit is contained in:
parent
36be7b76c2
commit
df7dff081f
@ -528,6 +528,17 @@ func SetExternalActions(w http.ResponseWriter, r *http.Request) {
|
|||||||
controllers.WriteSimpleResponse(w, true, "external actions update")
|
controllers.WriteSimpleResponse(w, true, "external actions update")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetCustomStyles will set the CSS string we insert into the page.
|
||||||
|
func SetCustomStyles(w http.ResponseWriter, r *http.Request) {
|
||||||
|
customStyles, success := getValueFromRequest(w, r)
|
||||||
|
if !success {
|
||||||
|
controllers.WriteSimpleResponse(w, false, "unable to update custom styles")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data.SetCustomStyles(customStyles.Value.(string))
|
||||||
|
}
|
||||||
|
|
||||||
func requirePOST(w http.ResponseWriter, r *http.Request) bool {
|
func requirePOST(w http.ResponseWriter, r *http.Request) bool {
|
||||||
if r.Method != controllers.POST {
|
if r.Method != controllers.POST {
|
||||||
controllers.WriteSimpleResponse(w, false, r.Method+" not supported")
|
controllers.WriteSimpleResponse(w, false, r.Method+" not supported")
|
||||||
|
@ -39,6 +39,7 @@ func GetServerConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
Logo: data.GetLogoPath(),
|
Logo: data.GetLogoPath(),
|
||||||
SocialHandles: data.GetSocialHandles(),
|
SocialHandles: data.GetSocialHandles(),
|
||||||
NSFW: data.GetNSFW(),
|
NSFW: data.GetNSFW(),
|
||||||
|
CustomStyles: data.GetCustomStyles(),
|
||||||
},
|
},
|
||||||
FFmpegPath: utils.ValidatedFfmpegPath(data.GetFfMpegPath()),
|
FFmpegPath: utils.ValidatedFfmpegPath(data.GetFfMpegPath()),
|
||||||
StreamKey: data.GetStreamKey(),
|
StreamKey: data.GetStreamKey(),
|
||||||
@ -94,6 +95,7 @@ type webConfigResponse struct {
|
|||||||
ExtraPageContent string `json:"extraPageContent"`
|
ExtraPageContent string `json:"extraPageContent"`
|
||||||
StreamTitle string `json:"streamTitle"` // What's going on with the current stream
|
StreamTitle string `json:"streamTitle"` // What's going on with the current stream
|
||||||
SocialHandles []models.SocialHandle `json:"socialHandles"`
|
SocialHandles []models.SocialHandle `json:"socialHandles"`
|
||||||
|
CustomStyles string `json:"customStyles"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type yp struct {
|
type yp struct {
|
||||||
|
@ -23,6 +23,7 @@ type webConfigResponse struct {
|
|||||||
SocialHandles []models.SocialHandle `json:"socialHandles"`
|
SocialHandles []models.SocialHandle `json:"socialHandles"`
|
||||||
ChatDisabled bool `json:"chatDisabled"`
|
ChatDisabled bool `json:"chatDisabled"`
|
||||||
ExternalActions []models.ExternalAction `json:"externalActions"`
|
ExternalActions []models.ExternalAction `json:"externalActions"`
|
||||||
|
CustomStyles string `json:"customStyles"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWebConfig gets the status of the server.
|
// GetWebConfig gets the status of the server.
|
||||||
@ -52,6 +53,7 @@ func GetWebConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
SocialHandles: socialHandles,
|
SocialHandles: socialHandles,
|
||||||
ChatDisabled: data.GetChatDisabled(),
|
ChatDisabled: data.GetChatDisabled(),
|
||||||
ExternalActions: data.GetExternalActions(),
|
ExternalActions: data.GetExternalActions(),
|
||||||
|
CustomStyles: data.GetCustomStyles(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.NewEncoder(w).Encode(configuration); err != nil {
|
if err := json.NewEncoder(w).Encode(configuration); err != nil {
|
||||||
|
@ -38,6 +38,7 @@ const videoLatencyLevel = "video_latency_level"
|
|||||||
const videoStreamOutputVariantsKey = "video_stream_output_variants"
|
const videoStreamOutputVariantsKey = "video_stream_output_variants"
|
||||||
const chatDisabledKey = "chat_disabled"
|
const chatDisabledKey = "chat_disabled"
|
||||||
const externalActionsKey = "external_actions"
|
const externalActionsKey = "external_actions"
|
||||||
|
const customStylesKey = "custom_styles"
|
||||||
|
|
||||||
// GetExtraPageBodyContent will return the user-supplied body content.
|
// GetExtraPageBodyContent will return the user-supplied body content.
|
||||||
func GetExtraPageBodyContent() string {
|
func GetExtraPageBodyContent() string {
|
||||||
@ -465,6 +466,21 @@ func SetExternalActions(actions []models.ExternalAction) error {
|
|||||||
return _datastore.Save(configEntry)
|
return _datastore.Save(configEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetCustomStyles will save a string with CSS to insert into the page.
|
||||||
|
func SetCustomStyles(styles string) error {
|
||||||
|
return _datastore.SetString(customStylesKey, styles)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCustomStyles will return a string with CSS to insert into the page.
|
||||||
|
func GetCustomStyles() string {
|
||||||
|
style, err := _datastore.GetString(customStylesKey)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return style
|
||||||
|
}
|
||||||
|
|
||||||
// VerifySettings will perform a sanity check for specific settings values.
|
// VerifySettings will perform a sanity check for specific settings values.
|
||||||
func VerifySettings() error {
|
func VerifySettings() error {
|
||||||
if GetStreamKey() == "" {
|
if GetStreamKey() == "" {
|
||||||
|
@ -196,6 +196,9 @@ func Start() error {
|
|||||||
// set external action links
|
// set external action links
|
||||||
http.HandleFunc("/api/admin/config/externalactions", middleware.RequireAdminAuth(admin.SetExternalActions))
|
http.HandleFunc("/api/admin/config/externalactions", middleware.RequireAdminAuth(admin.SetExternalActions))
|
||||||
|
|
||||||
|
// set custom style css
|
||||||
|
http.HandleFunc("api/admin/config/customstyles", middleware.RequireAdminAuth(admin.SetCustomStyles))
|
||||||
|
|
||||||
port := config.WebServerPort
|
port := config.WebServerPort
|
||||||
|
|
||||||
log.Infof("Web server is listening on port %d.", port)
|
log.Infof("Web server is listening on port %d.", port)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user