bug bashin

This commit is contained in:
filifa 2025-04-07 23:12:44 -04:00
parent 543434c311
commit ccf95a1a21
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) 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 var v any
err := json.Unmarshal(body, &v) err := json.Unmarshal(body, &v)
if err != nil { if err != nil {
return err return body, err
} }
vobj := v.(map[string]any) vobj := v.(map[string]any)
@ -61,31 +61,31 @@ func patch(body []byte, client *api.APIClient) error {
timestamp := metaData["timeStamp"] timestamp := metaData["timeStamp"]
req := client.GameAPI.LiveGameDiffPatchV1(context.Background(), gamePk) req := client.GameAPI.LiveGameDiffPatchV1(context.Background(), gamePk)
req.StartTimecode(timestamp) req = req.StartTimecode(timestamp)
resp, err := req.Execute() resp, err := req.Execute()
if err != nil { if err != nil {
return err return body, err
} }
diffPatch, err := io.ReadAll(resp.Body) diffPatch, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return body, err
} }
patches, err := extractPatches(diffPatch) patches, err := extractPatches(diffPatch)
if err != nil { if err != nil {
return err return body, err
} }
for _, patch := range patches { for _, patch := range patches {
body, err = patch.Apply(body) body, err = patch.Apply(body)
if err != nil { if err != nil {
return err return body, err
} }
} }
return err return body, nil
} }
func newWebsocket(gamePk int32) (*gamedayWebsocket, <-chan error, error) { func newWebsocket(gamePk int32) (*gamedayWebsocket, <-chan error, error) {
@ -97,7 +97,7 @@ func newWebsocket(gamePk int32) (*gamedayWebsocket, <-chan error, error) {
ch := make(chan error) ch := make(chan error)
go ws.keepAlive(10*time.Second, ch) go ws.keepAlive(10*time.Second, ch)
return ws, ch, err return ws, ch, nil
} }
func handleUnexpectedClose(body []byte, client *api.APIClient) (*gamedayWebsocket, error) { func handleUnexpectedClose(body []byte, client *api.APIClient) (*gamedayWebsocket, error) {
@ -116,7 +116,7 @@ func handleUnexpectedClose(body []byte, client *api.APIClient) (*gamedayWebsocke
return ws, err 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 var p push
err := ws.ReadJSON(&p) err := ws.ReadJSON(&p)
if websocket.IsUnexpectedCloseError(err, GameFinalCode, GameUnavailableCode) { 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) newWs, err := handleUnexpectedClose(body, client)
if err != nil { if err != nil {
return err return body, err
} }
*ws = *newWs *ws = *newWs
return err return body, nil
} else if err != nil { } else if err != nil {
return err return body, err
} }
err = patch(body, client) body, err = patch(body, client)
if err != nil { if err != nil {
req := client.GameAPI.LiveGameV1(context.Background(), gamePk) req := client.GameAPI.LiveGameV1(context.Background(), gamePk)
resp, err := req.Execute() resp, err := req.Execute()
if err != nil { if err != nil {
return err return body, err
} }
body, err = io.ReadAll(resp.Body) body, err = io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err return body, err
} }
} }
return err return body, nil
} }
func subscribe(cmd *cobra.Command, args []string) { func subscribe(cmd *cobra.Command, args []string) {
@ -164,15 +164,15 @@ func subscribe(cmd *cobra.Command, args []string) {
log.Fatal(err) log.Fatal(err)
} }
for {
body, err := io.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
for {
fmt.Println(string(body)) fmt.Println(string(body))
err = updateFeed(body, ws, statsAPIClient) body, err = updateFeed(body, ws, statsAPIClient)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }