Feat twitch livestreams (#334)

* backend code

* fixed twitch authentication
This commit is contained in:
Marco Piovanello
2025-08-25 12:54:16 +02:00
committed by GitHub
parent 14a03d6a77
commit f4a0f688af
9 changed files with 440 additions and 14 deletions

40
server/twitch/rest.go Normal file
View File

@@ -0,0 +1,40 @@
package twitch
import (
"encoding/json"
"net/http"
"slices"
)
type addUserReq struct {
User string `json:"user"`
}
func MonitorUserHandler(m *Monitor) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req addUserReq
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
m.Add(req.User)
if err := json.NewEncoder(w).Encode("ok"); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
}
func GetMonitoredUsers(m *Monitor) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
it := m.GetMonitoredUsers()
if err := json.NewEncoder(w).Encode(slices.Collect(it)); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
}