Skip to content

Commit

Permalink
Merge pull request #1408 from woogles-io/fix_cop_bug_2
Browse files Browse the repository at this point in the history
  • Loading branch information
domino14 authored Dec 26, 2024
2 parents b063049 + 1070a8d commit ebdb0c4
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions pkg/pair/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ package pair

import (
"context"
"encoding/base64"
"encoding/json"
"errors"

"connectrpc.com/connect"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/lambda"
"github.com/aws/aws-sdk-go-v2/service/lambda/types"
"google.golang.org/protobuf/proto"

"github.com/woogles-io/liwords/pkg/apiserver"
"github.com/woogles-io/liwords/pkg/config"
pb "github.com/woogles-io/liwords/rpc/api/proto/ipc"
)
Expand All @@ -23,7 +20,7 @@ type PairService struct {
}

type LambdaInvokeIO struct {
Bytes []byte
Bytes []byte `json:"bytes"`
}

func NewPairService(cfg *config.Config, lc *lambda.Client) *PairService {
Expand Down Expand Up @@ -53,31 +50,13 @@ func (ps *PairService) HandlePairRequest(ctx context.Context, req *connect.Reque
return nil, err
}

type lambdaOutput struct {
StatusCode int `json:"statusCode"`
Body string `json:"body"`
Payload string `json:"payload"`
}

lo := &lambdaOutput{}
lo := &LambdaInvokeIO{}
err = json.Unmarshal(out.Payload, lo)
if err != nil {
return nil, err
}
if lo.StatusCode != 200 {
return nil, apiserver.InternalErr(errors.New(lo.Body))
}
bts, err := base64.StdEncoding.DecodeString(lo.Payload)
if err != nil {
return nil, err
}
lambdaInvokeIOResponse := &LambdaInvokeIO{}
err = json.Unmarshal(bts, lambdaInvokeIOResponse)
if err != nil {
return nil, err
}
pairResponse := &pb.PairResponse{}
err = proto.Unmarshal(lambdaInvokeIOResponse.Bytes, pairResponse)
err = proto.Unmarshal(lo.Bytes, pairResponse)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ebdb0c4

Please sign in to comment.