An atproto PDS written in Go
103
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 0.3.1 55 lines 1.2 kB view raw
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 did := e.QueryParam("did") 17 if did == "" { 18 return helpers.InputError(e, nil) 19 } 20 21 urepo, err := s.getRepoActorByDid(did) 22 if err != nil { 23 return err 24 } 25 26 rc, err := cid.Cast(urepo.Root) 27 if err != nil { 28 return err 29 } 30 31 hb, err := cbor.DumpObject(&car.CarHeader{ 32 Roots: []cid.Cid{rc}, 33 Version: 1, 34 }) 35 36 buf := new(bytes.Buffer) 37 38 if _, err := carstore.LdWrite(buf, hb); err != nil { 39 s.logger.Error("error writing to car", "error", err) 40 return helpers.ServerError(e, nil) 41 } 42 43 var blocks []models.Block 44 if err := s.db.Raw("SELECT * FROM blocks WHERE did = ? ORDER BY rev ASC", nil, urepo.Repo.Did).Scan(&blocks).Error; err != nil { 45 return err 46 } 47 48 for _, block := range blocks { 49 if _, err := carstore.LdWrite(buf, block.Cid, block.Value); err != nil { 50 return err 51 } 52 } 53 54 return e.Stream(200, "application/vnd.ipld.car", bytes.NewReader(buf.Bytes())) 55}