Update extra page content API (#240)

* Mark change stream key api as pre-release

* Add API for changing extra page content. Renanme usercontent -> pagecontent. closes #236
This commit is contained in:
Gabe Kangas 2020-10-14 09:38:48 -07:00 committed by GitHub
parent d7c3991b59
commit 64a85e68aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 84 additions and 10 deletions

View File

@ -36,7 +36,7 @@ type InstanceDetails struct {
SocialHandles []socialHandle `yaml:"socialHandles" json:"socialHandles"`
Version string `json:"version"`
NSFW bool `yaml:"nsfw" json:"nsfw"`
ExtraUserContent string `json:"extraUserContent"`
ExtraPageContent string `json:"extraPageContent"`
}
type logo struct {
@ -122,7 +122,7 @@ func (c *config) load(filePath string) error {
customContentMarkdownData, err := ioutil.ReadFile(ExtraInfoFile)
if err == nil {
customContentMarkdownString := string(customContentMarkdownData)
c.InstanceDetails.ExtraUserContent = utils.RenderSimpleMarkdown(customContentMarkdownString)
c.InstanceDetails.ExtraPageContent = utils.RenderSimpleMarkdown(customContentMarkdownString)
}
return nil

View File

@ -0,0 +1,35 @@
package admin
import (
"encoding/json"
"net/http"
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/controllers"
log "github.com/sirupsen/logrus"
)
// ChangeExtraPageContent will change the optional page content
func ChangeExtraPageContent(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
controllers.WriteSimpleResponse(w, false, r.Method+" not supported")
return
}
decoder := json.NewDecoder(r.Body)
var request changeExtraPageContentRequest
err := decoder.Decode(&request)
if err != nil {
log.Errorln(err)
controllers.WriteSimpleResponse(w, false, "")
return
}
config.Config.InstanceDetails.ExtraPageContent = request.Key
controllers.WriteSimpleResponse(w, true, "changed")
}
type changeExtraPageContentRequest struct {
Key string `json:"content"`
}

File diff suppressed because one or more lines are too long

View File

@ -57,6 +57,9 @@ func Start() error {
// Change the current streaming key in memory
http.HandleFunc("/api/admin/changekey", middleware.RequireAdminAuth(admin.ChangeStreamKey))
// Change the extra page content in memory
http.HandleFunc("/api/admin/changeextrapagecontent", middleware.RequireAdminAuth(admin.ChangeExtraPageContent))
// Server config
http.HandleFunc("/api/admin/serverconfig", middleware.RequireAdminAuth(admin.GetServerConfig))

View File

@ -55,7 +55,7 @@ export default class App extends Component {
generateAvatar(`${this.username}${Date.now()}`),
configData: {},
extraUserContent: '',
extraPageContent: '',
playerActive: false, // player object is active
streamOnline: false, // stream is active/online
@ -347,7 +347,7 @@ export default class App extends Component {
summary,
tags = [],
title,
extraUserContent,
extraPageContent,
} = configData;
const {
small: smallLogo = TEMP_IMAGE,
@ -485,7 +485,7 @@ export default class App extends Component {
<div
id="extra-user-content"
class="extra-user-content px-8"
dangerouslySetInnerHTML=${{ __html: extraUserContent }}
dangerouslySetInnerHTML=${{ __html: extraPageContent }}
></div>
</section>