Added new endpoints to modify settings in-memory (#517)

* Added new endpoints to modify settings in-memory

* Added missing controllers
This commit is contained in:
Mirco T 2020-12-29 23:03:57 +01:00 committed by GitHub
parent 8a74af202d
commit a149e2bb50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 216 additions and 0 deletions

4
.gitignore vendored
View File

@ -11,6 +11,10 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# ignore IDE specific files
.idea/
*.iml
# Dependency directories (remove the comment below to include it)
vendor/

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"
)
// ChangeStreamName will change the stream key (in memory).
func ChangeStreamName(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 changeStreamNameRequest
err := decoder.Decode(&request)
if err != nil {
log.Errorln(err)
controllers.WriteSimpleResponse(w, false, "")
return
}
config.Config.InstanceDetails.Name = request.Name
controllers.WriteSimpleResponse(w, true, "changed")
}
type changeStreamNameRequest struct {
Name string `json:"name"`
}

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"
)
// ChangeStreamTags will change the stream key (in memory).
func ChangeStreamTags(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 changeStreamTagsRequest
err := decoder.Decode(&request)
if err != nil {
log.Errorln(err)
controllers.WriteSimpleResponse(w, false, "")
return
}
config.Config.InstanceDetails.Tags = request.Tags
controllers.WriteSimpleResponse(w, true, "changed")
}
type changeStreamTagsRequest struct {
Tags []string `json:"tags"`
}

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"
)
// ChangeStreamTitle will change the stream key (in memory).
func ChangeStreamTitle(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 changeStreamTitleRequest
err := decoder.Decode(&request)
if err != nil {
log.Errorln(err)
controllers.WriteSimpleResponse(w, false, "")
return
}
config.Config.InstanceDetails.Title = request.Title
controllers.WriteSimpleResponse(w, true, "changed")
}
type changeStreamTitleRequest struct {
Title string `json:"title"`
}

View File

@ -607,6 +607,104 @@ paths:
type: string
example: changed
/api/admin/changetitle:
post:
summary: Update Stream Title. Pre-release, do not use.
description: Change the stream title in memory, but not in the config file.
tags: ["Admin", "Pre-release"]
security:
- AdminBasicAuth: []
requestBody:
description: ""
required: true
content:
application/json:
schema:
type: object
properties:
title:
type: string
responses:
'200':
description: Title was changed.
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: changed
/api/admin/changename:
post:
summary: Update Stream Name. Pre-release, do not use.
description: Change the stream name in memory, but not in the config file.
tags: ["Admin", "Pre-release"]
security:
- AdminBasicAuth: []
requestBody:
description: ""
required: true
content:
application/json:
schema:
type: object
properties:
name:
type: string
responses:
'200':
description: Name was changed.
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: changed
/api/admin/changetags:
post:
summary: Update Stream Tags. Pre-release, do not use.
description: Change the stream tags in memory, but not in the config file.
tags: ["Admin", "Pre-release"]
security:
- AdminBasicAuth: []
requestBody:
description: ""
required: true
content:
application/json:
schema:
type: object
properties:
tags:
type: array
items:
type: string
responses:
'200':
description: Tags were changed.
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
example: true
message:
type: string
example: changed
/api/admin/serverconfig:
get:
summary: Server Configuration

View File

@ -61,6 +61,15 @@ func Start() error {
// Change the current streaming key in memory
http.HandleFunc("/api/admin/changekey", middleware.RequireAdminAuth(admin.ChangeStreamKey))
// Change the current streaming name in memory
http.HandleFunc("/api/admin/changename", middleware.RequireAdminAuth(admin.ChangeStreamName))
// Change the current streaming name in memory
http.HandleFunc("/api/admin/changetitle", middleware.RequireAdminAuth(admin.ChangeStreamTitle))
// Change the current streaming name in memory
http.HandleFunc("/api/admin/changetags", middleware.RequireAdminAuth(admin.ChangeStreamTags))
// Change the extra page content in memory
http.HandleFunc("/api/admin/changeextrapagecontent", middleware.RequireAdminAuth(admin.ChangeExtraPageContent))