diff --git a/.gitignore b/.gitignore index 99a23c32d..2bab666eb 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/controllers/admin/changeStreamName.go b/controllers/admin/changeStreamName.go new file mode 100644 index 000000000..10384e7b5 --- /dev/null +++ b/controllers/admin/changeStreamName.go @@ -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"` +} diff --git a/controllers/admin/changeStreamTags.go b/controllers/admin/changeStreamTags.go new file mode 100644 index 000000000..38bb1b105 --- /dev/null +++ b/controllers/admin/changeStreamTags.go @@ -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"` +} diff --git a/controllers/admin/changeStreamTitle.go b/controllers/admin/changeStreamTitle.go new file mode 100644 index 000000000..2a3a95e14 --- /dev/null +++ b/controllers/admin/changeStreamTitle.go @@ -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"` +} diff --git a/openapi.yaml b/openapi.yaml index 49bb68eaa..1ff31eab6 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -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 diff --git a/router/router.go b/router/router.go index e2850f308..21481efc7 100644 --- a/router/router.go +++ b/router/router.go @@ -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))