Compare commits

...

2 commits

Author SHA1 Message Date
Vyacheslav1557
c9c4fc65e7 Merge remote-tracking branch 'origin/develop' into develop 2024-08-21 03:01:19 +05:00
Vyacheslav1557
eb1a2e6df7 feat: add file saving 2024-08-21 03:01:06 +05:00

View file

@ -9,6 +9,7 @@ import (
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
"io"
"os"
)
func (s *TesterServer) CreateProblem(server problemv1.ProblemService_CreateProblemServer) error {
@ -36,7 +37,12 @@ func (s *TesterServer) CreateProblem(server problemv1.ProblemService_CreateProbl
ch := readChunks(ctx, server)
id, err := s.problemService.CreateProblem(ctx, p, ch)
err = writeChunks(ctx, ch) // temp stub
if err != nil {
return err // FIXME
}
id, err := s.problemService.CreateProblem(ctx, p, nil) // FIXME
if err != nil {
return status.Errorf(codes.Unknown, "") // FIXME
}
@ -51,6 +57,28 @@ func (s *TesterServer) CreateProblem(server problemv1.ProblemService_CreateProbl
return nil
}
func writeChunks(ctx context.Context, chunks <-chan []byte) error {
// FIXME: use ctx?
f, err := os.Create("out.txt") // FIXME: uuidv4 as initial temp name?
if err != nil {
return err
}
defer f.Close()
var off int64 = 0
for chunk := range chunks {
_, err = f.WriteAt(chunk, off)
if err != nil {
return err
}
off += int64(len(chunk))
}
// TODO: rename file to its hash
return nil
}
func readChunks(ctx context.Context, server problemv1.ProblemService_CreateProblemServer) <-chan []byte {
ch := make(chan []byte)