bug bashin

This commit is contained in:
filifa 2025-04-07 23:12:44 -04:00
parent de3a09f145
commit 7c18c0a396
1 changed files with 24 additions and 24 deletions

View File

@ -46,14 +46,14 @@ func extractPatches(resp []byte) ([]jsonpatch.Patch, error) {
patches = append(patches, patch)
}
return patches, err
return patches, nil
}
func patch(body []byte, client *api.APIClient) error {
func patch(body []byte, client *api.APIClient) ([]byte, error) {
var v any
err := json.Unmarshal(body, &v)
if err != nil {
return err
return body, err
}
vobj := v.(map[string]any)
@ -61,31 +61,31 @@ func patch(body []byte, client *api.APIClient) error {
timestamp := metaData["timeStamp"]
req := client.GameAPI.LiveGameDiffPatchV1(context.Background(), gamePk)
req.StartTimecode(timestamp)
req = req.StartTimecode(timestamp)
resp, err := req.Execute()
if err != nil {
return err
return body, err
}
diffPatch, err := io.ReadAll(resp.Body)
if err != nil {
return err
return body, err
}
patches, err := extractPatches(diffPatch)
if err != nil {
return err
return body, err
}
for _, patch := range patches {
body, err = patch.Apply(body)
if err != nil {
return err
return body, err
}
}
return err
return body, nil
}
func newWebsocket(gamePk int32) (*gamedayWebsocket, <-chan error, error) {
@ -97,7 +97,7 @@ func newWebsocket(gamePk int32) (*gamedayWebsocket, <-chan error, error) {
ch := make(chan error)
go ws.keepAlive(10*time.Second, ch)
return ws, ch, err
return ws, ch, nil
}
func handleUnexpectedClose(body []byte, client *api.APIClient) (*gamedayWebsocket, error) {
@ -116,7 +116,7 @@ func handleUnexpectedClose(body []byte, client *api.APIClient) (*gamedayWebsocke
return ws, err
}
func updateFeed(body []byte, ws *gamedayWebsocket, client *api.APIClient) error {
func updateFeed(body []byte, ws *gamedayWebsocket, client *api.APIClient) ([]byte, error) {
var p push
err := ws.ReadJSON(&p)
if websocket.IsUnexpectedCloseError(err, GameFinalCode, GameUnavailableCode) {
@ -124,30 +124,30 @@ func updateFeed(body []byte, ws *gamedayWebsocket, client *api.APIClient) error
newWs, err := handleUnexpectedClose(body, client)
if err != nil {
return err
return body, err
}
*ws = *newWs
return err
return body, nil
} else if err != nil {
return err
return body, err
}
err = patch(body, client)
body, err = patch(body, client)
if err != nil {
req := client.GameAPI.LiveGameV1(context.Background(), gamePk)
resp, err := req.Execute()
if err != nil {
return err
return body, err
}
body, err = io.ReadAll(resp.Body)
if err != nil {
return err
return body, err
}
}
return err
return body, nil
}
func subscribe(cmd *cobra.Command, args []string) {
@ -164,15 +164,15 @@ func subscribe(cmd *cobra.Command, args []string) {
log.Fatal(err)
}
for {
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
for {
fmt.Println(string(body))
err = updateFeed(body, ws, statsAPIClient)
body, err = updateFeed(body, ws, statsAPIClient)
if err != nil {
log.Fatal(err)
}