2022-03-18 23:33:23 +03:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/owncast/owncast/models"
|
2024-11-16 06:20:58 +03:00
|
|
|
"github.com/owncast/owncast/persistence/configrepository"
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils "github.com/owncast/owncast/webserver/utils"
|
2022-03-18 23:33:23 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// SetDiscordNotificationConfiguration will set the discord notification configuration.
|
|
|
|
func SetDiscordNotificationConfiguration(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if !requirePOST(w, r) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
type request struct {
|
|
|
|
Value models.DiscordConfiguration `json:"value"`
|
|
|
|
}
|
|
|
|
|
2024-11-16 06:20:58 +03:00
|
|
|
configRepository := configrepository.Get()
|
|
|
|
|
2022-03-18 23:33:23 +03:00
|
|
|
decoder := json.NewDecoder(r.Body)
|
|
|
|
var config request
|
|
|
|
if err := decoder.Decode(&config); err != nil {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, "unable to update discord config with provided values")
|
2022-03-18 23:33:23 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-11-16 06:20:58 +03:00
|
|
|
if err := configRepository.SetDiscordConfig(config.Value); err != nil {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, "unable to update discord config with provided values")
|
2022-03-18 23:33:23 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, true, "updated discord config with provided values")
|
2022-03-18 23:33:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetBrowserNotificationConfiguration will set the browser notification configuration.
|
|
|
|
func SetBrowserNotificationConfiguration(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if !requirePOST(w, r) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
type request struct {
|
|
|
|
Value models.BrowserNotificationConfiguration `json:"value"`
|
|
|
|
}
|
|
|
|
|
2024-11-16 06:20:58 +03:00
|
|
|
configRepository := configrepository.Get()
|
2022-03-18 23:33:23 +03:00
|
|
|
decoder := json.NewDecoder(r.Body)
|
|
|
|
var config request
|
|
|
|
if err := decoder.Decode(&config); err != nil {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, "unable to update browser push config with provided values")
|
2022-03-18 23:33:23 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-11-16 06:20:58 +03:00
|
|
|
if err := configRepository.SetBrowserPushConfig(config.Value); err != nil {
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, false, "unable to update browser push config with provided values")
|
2022-03-18 23:33:23 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-07-02 07:44:37 +03:00
|
|
|
webutils.WriteSimpleResponse(w, true, "updated browser push config with provided values")
|
2022-03-18 23:33:23 +03:00
|
|
|
}
|