Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
tempo hack to write operation results as json, not rq gif
Browse files Browse the repository at this point in the history
  • Loading branch information
swelf19 committed Jul 28, 2021
1 parent 9f05129 commit 1b8cc84
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ func (c *BaseClient) GetOperationQRPath(operationID string) (string, error) {
return "", fmt.Errorf("failed to get operation in JSON: %w", err)
}

operationQRPath := filepath.Join(QrCodesDir, fmt.Sprintf("dc4bc_qr_%s", operationID))
operationQRPath := filepath.Join(QrCodesDir, fmt.Sprintf("dc4bc_json_%s", operationID))

qrPath := fmt.Sprintf("%s.gif", operationQRPath)
qrPath := fmt.Sprintf("%s.json", operationQRPath)
if err = c.qrProcessor.WriteQR(qrPath, operationJSON); err != nil {
return "", err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/dc4bc_cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/lidofinance/dc4bc/client/types"
"io/ioutil"
"log"
"net/http"
Expand All @@ -20,6 +19,7 @@ import (
"strings"
"time"

"github.com/lidofinance/dc4bc/client/types"
"github.com/lidofinance/dc4bc/fsm/state_machines"

"github.com/lidofinance/dc4bc/fsm/fsm"
Expand Down Expand Up @@ -388,16 +388,16 @@ func getOperationQRPathCommand() *cobra.Command {
return fmt.Errorf("failed to get operations: %s", operation.ErrorMessage)
}

operationQRPath := filepath.Join(qrCodeFolder, fmt.Sprintf("dc4bc_qr_%s-request", operationID))
operationQRPath := filepath.Join(qrCodeFolder, fmt.Sprintf("dc4bc_json_%s-request", operationID))

qrPath := fmt.Sprintf("%s.gif", operationQRPath)
qrPath := fmt.Sprintf("%s.json", operationQRPath)

processor := qr.NewCameraProcessor()
processor.SetChunkSize(chunkSize)
processor.SetDelay(framesDelay)

if err = processor.WriteQR(qrPath, operation.Result); err != nil {
return fmt.Errorf("failed to save QR gif: %w", err)
return fmt.Errorf("failed to save json: %w", err)
}

fmt.Printf("QR code was saved to: %s\n", qrPath)
Expand Down
9 changes: 9 additions & 0 deletions qr/qr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"image/draw"
"image/gif"
"io"
"io/ioutil"
"os"

encoder "github.com/skip2/go-qrcode"
Expand Down Expand Up @@ -71,6 +72,14 @@ func (p *CameraProcessor) SetRecoveryLevel(recoveryLevel encoder.RecoveryLevel)
}

func (p *CameraProcessor) WriteQR(path string, data []byte) error {
err := ioutil.WriteFile(path, data, 0644)
if err != nil {
return fmt.Errorf("failed to write json: %w", err)
}
return nil
}

func (p *CameraProcessor) WriteQR_(path string, data []byte) error {
chunks, err := DataToChunks(data, p.chunkSize)
if err != nil {
return fmt.Errorf("failed to divide data on chunks: %w", err)
Expand Down

0 comments on commit 1b8cc84

Please sign in to comment.