Skip to content

Commit

Permalink
fix api issue
Browse files Browse the repository at this point in the history
  • Loading branch information
TimIsOverpowered committed Jul 29, 2024
1 parent 301e553 commit 36b7486
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
35 changes: 30 additions & 5 deletions api/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ import (

type Stream struct {
Created_at string `json:"createdAt"`
User struct {
Username string `json:"username"`
StreamKey string `json:"stream_key"`
} `json:"user"`
Ingest struct {
User User `json:"user"`
Ingest struct {
Server string `json:"server"`
Id string `json:"id"`
Mediamtx bool `json:"mediamtx"`
} `json:"ingest"`
}

type User struct {
Id string `json:"id"`
Username string `json:"username"`
StreamKey string `json:"stream_key"`
}

func Find() []Stream {
client := resty.New()
resp, _ := client.R().
Expand All @@ -42,3 +45,25 @@ func Find() []Stream {

return streams
}

func GetUser(id string) *User {
client := resty.New()
resp, _ := client.R().
SetHeader("X-Api-Key", utils.Config.StreamsAPI.AuthKey).
Get(utils.Config.StreamsAPI.Hostname + "/users/" + id)

statusCode := resp.StatusCode()
if statusCode >= 400 {
log.Printf("Unexpected status code, got %d %s", statusCode, string(resp.Body()))
return nil
}

var user User
err := json.Unmarshal(resp.Body(), &user)
if err != nil {
log.Printf("Unmarshal Error %v", err)
return nil
}

return &user
}
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ func saveStreams() {
log.Println(err)
}

user := api.GetUser(stream.User.Id)
if user == nil {
log.Println(err)
return
}
stream.User = *user

marshalledStream, err := json.Marshal(stream)
if err != nil {
fmt.Println(err)
Expand Down

0 comments on commit 36b7486

Please sign in to comment.