notifications.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package admin
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "github.com/owncast/owncast/controllers"
  6. "github.com/owncast/owncast/core/data"
  7. "github.com/owncast/owncast/models"
  8. )
  9. // SetDiscordNotificationConfiguration will set the discord notification configuration.
  10. func SetDiscordNotificationConfiguration(w http.ResponseWriter, r *http.Request) {
  11. if !requirePOST(w, r) {
  12. return
  13. }
  14. type request struct {
  15. Value models.DiscordConfiguration `json:"value"`
  16. }
  17. decoder := json.NewDecoder(r.Body)
  18. var config request
  19. if err := decoder.Decode(&config); err != nil {
  20. controllers.WriteSimpleResponse(w, false, "unable to update discord config with provided values")
  21. return
  22. }
  23. if err := data.SetDiscordConfig(config.Value); err != nil {
  24. controllers.WriteSimpleResponse(w, false, "unable to update discord config with provided values")
  25. return
  26. }
  27. controllers.WriteSimpleResponse(w, true, "updated discord config with provided values")
  28. }
  29. // SetBrowserNotificationConfiguration will set the browser notification configuration.
  30. func SetBrowserNotificationConfiguration(w http.ResponseWriter, r *http.Request) {
  31. if !requirePOST(w, r) {
  32. return
  33. }
  34. type request struct {
  35. Value models.BrowserNotificationConfiguration `json:"value"`
  36. }
  37. decoder := json.NewDecoder(r.Body)
  38. var config request
  39. if err := decoder.Decode(&config); err != nil {
  40. controllers.WriteSimpleResponse(w, false, "unable to update browser push config with provided values")
  41. return
  42. }
  43. if err := data.SetBrowserPushConfig(config.Value); err != nil {
  44. controllers.WriteSimpleResponse(w, false, "unable to update browser push config with provided values")
  45. return
  46. }
  47. controllers.WriteSimpleResponse(w, true, "updated browser push config with provided values")
  48. }