fixed twitch authentication

This commit is contained in:
2025-08-25 12:48:30 +02:00
parent 4e1b4bad0a
commit 4f8510bac8
7 changed files with 61 additions and 16 deletions

View File

@@ -36,7 +36,7 @@ func NewAuthenticationManager(clientId, clientSecret string) *AuthenticationMana
}
func (a *AuthenticationManager) GetAccessToken() (*AccessToken, error) {
if a.accesToken != nil && a.accesToken.Expiry.After(time.Now()) {
if a.accesToken != nil && a.accesToken.Token != "" && a.accesToken.Expiry.After(time.Now()) {
return a.accesToken, nil
}

View File

@@ -70,6 +70,11 @@ func (c *Client) PollStream(channel string, liveChannel chan<- *StreamInfo) erro
return err
}
if len(sr.Data) == 0 {
liveChannel <- &StreamInfo{UserName: channel, IsLive: false}
return nil
}
s := sr.Data[0]
started, _ := time.Parse(time.RFC3339, s.StartedAt)

View File

@@ -3,6 +3,7 @@ package twitch
import (
"encoding/json"
"net/http"
"slices"
)
type addUserReq struct {
@@ -26,3 +27,14 @@ func MonitorUserHandler(m *Monitor) http.HandlerFunc {
}
}
}
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
}
}
}