this repo has no description
1package server 2 3import ( 4 "bytes" 5 6 "github.com/bluesky-social/indigo/carstore" 7 "github.com/haileyok/cocoon/internal/helpers" 8 "github.com/haileyok/cocoon/models" 9 "github.com/ipfs/go-cid" 10 cbor "github.com/ipfs/go-ipld-cbor" 11 "github.com/ipld/go-car" 12 "github.com/labstack/echo/v4" 13) 14 15func (s *Server) handleSyncGetRepo(e echo.Context) error { 16 ctx := e.Request().Context() 17 18 did := e.QueryParam("did") 19 if did == "" { 20 return helpers.InputError(e, nil) 21 } 22 23 urepo, err := s.getRepoActorByDid(ctx, did) 24 if err != nil { 25 return err 26 } 27 28 rc, err := cid.Cast(urepo.Root) 29 if err != nil { 30 return err 31 } 32 33 hb, err := cbor.DumpObject(&car.CarHeader{ 34 Roots: []cid.Cid{rc}, 35 Version: 1, 36 }) 37 38 buf := new(bytes.Buffer) 39 40 if _, err := carstore.LdWrite(buf, hb); err != nil { 41 s.logger.Error("error writing to car", "error", err) 42 return helpers.ServerError(e, nil) 43 } 44 45 var blocks []models.Block 46 if err := s.db.Raw(ctx, "SELECT * FROM blocks WHERE did = ? ORDER BY rev ASC", nil, urepo.Repo.Did).Scan(&blocks).Error; err != nil { 47 return err 48 } 49 50 for _, block := range blocks { 51 if _, err := carstore.LdWrite(buf, block.Cid, block.Value); err != nil { 52 return err 53 } 54 } 55 56 return e.Stream(200, "application/vnd.ipld.car", bytes.NewReader(buf.Bytes())) 57}