this repo has no description
0
fork

Configure Feed

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

implement sync.GetRecord correctly

+116 -5
+16 -5
bgs/handlers.go
··· 13 13 atproto "github.com/bluesky-social/indigo/api/atproto" 14 14 comatprototypes "github.com/bluesky-social/indigo/api/atproto" 15 15 "github.com/bluesky-social/indigo/blobs" 16 + "github.com/bluesky-social/indigo/carstore" 16 17 "github.com/bluesky-social/indigo/mst" 17 18 "gorm.io/gorm" 18 19 19 20 "github.com/bluesky-social/indigo/util" 20 21 "github.com/bluesky-social/indigo/xrpc" 21 22 "github.com/ipfs/go-cid" 23 + cbor "github.com/ipfs/go-ipld-cbor" 24 + "github.com/ipld/go-car" 22 25 "github.com/labstack/echo/v4" 23 26 ) 24 27 ··· 40 43 return nil, fmt.Errorf("account was taken down") 41 44 } 42 45 43 - _, record, err := s.repoman.GetRecord(ctx, u.ID, collection, rkey, cid.Undef) 46 + root, blocks, err := s.repoman.GetRecordProof(ctx, u.ID, collection, rkey) 44 47 if err != nil { 45 48 if errors.Is(err, mst.ErrNotFound) { 46 49 return nil, echo.NewHTTPError(http.StatusNotFound, "record not found in repo") ··· 50 53 } 51 54 52 55 buf := new(bytes.Buffer) 53 - err = record.MarshalCBOR(buf) 54 - if err != nil { 55 - log.Errorw("failed to marshal record to CBOR", "err", err, "did", did, "collection", collection, "rkey", rkey) 56 - return nil, echo.NewHTTPError(http.StatusInternalServerError, "failed to marshal record to CBOR") 56 + hb, err := cbor.DumpObject(&car.CarHeader{ 57 + Roots: []cid.Cid{root}, 58 + Version: 1, 59 + }) 60 + if _, err := carstore.LdWrite(buf, hb); err != nil { 61 + return nil, err 62 + } 63 + 64 + for _, blk := range blocks { 65 + if _, err := carstore.LdWrite(buf, blk.Cid().Bytes(), blk.RawData()); err != nil { 66 + return nil, err 67 + } 57 68 } 58 69 59 70 return buf, nil
+28
repomgr/repomgr.go
··· 16 16 "github.com/bluesky-social/indigo/models" 17 17 "github.com/bluesky-social/indigo/mst" 18 18 "github.com/bluesky-social/indigo/repo" 19 + "github.com/bluesky-social/indigo/util" 19 20 21 + blocks "github.com/ipfs/go-block-format" 20 22 "github.com/ipfs/go-cid" 21 23 "github.com/ipfs/go-datastore" 22 24 blockstore "github.com/ipfs/go-ipfs-blockstore" ··· 445 447 } 446 448 447 449 return ocid, val, nil 450 + } 451 + 452 + func (rm *RepoManager) GetRecordProof(ctx context.Context, user models.Uid, collection string, rkey string) (cid.Cid, []blocks.Block, error) { 453 + robs, err := rm.cs.ReadOnlySession(user) 454 + if err != nil { 455 + return cid.Undef, nil, err 456 + } 457 + 458 + bs := util.NewReadRecordBstore(robs) 459 + 460 + head, err := rm.cs.GetUserRepoHead(ctx, user) 461 + if err != nil { 462 + return cid.Undef, nil, err 463 + } 464 + 465 + r, err := repo.OpenRepo(ctx, bs, head, true) 466 + if err != nil { 467 + return cid.Undef, nil, err 468 + } 469 + 470 + _, _, err = r.GetRecord(ctx, collection+"/"+rkey) 471 + if err != nil { 472 + return cid.Undef, nil, err 473 + } 474 + 475 + return head, bs.AllReadBlocks(), nil 448 476 } 449 477 450 478 func (rm *RepoManager) GetProfile(ctx context.Context, uid models.Uid) (*bsky.ActorProfile, error) {
+72
util/readrecordbs.go
··· 1 + package util 2 + 3 + import ( 4 + "context" 5 + "fmt" 6 + 7 + blockformat "github.com/ipfs/go-block-format" 8 + "github.com/ipfs/go-cid" 9 + blockstore "github.com/ipfs/go-ipfs-blockstore" 10 + ) 11 + 12 + type ReadRecordBstore struct { 13 + base blockstore.Blockstore 14 + 15 + set map[cid.Cid]blockformat.Block 16 + } 17 + 18 + func NewReadRecordBstore(base blockstore.Blockstore) *ReadRecordBstore { 19 + return &ReadRecordBstore{ 20 + base: base, 21 + set: make(map[cid.Cid]blockformat.Block), 22 + } 23 + } 24 + 25 + var _ blockstore.Blockstore = (*ReadRecordBstore)(nil) 26 + 27 + func (bs *ReadRecordBstore) AllReadBlocks() []blockformat.Block { 28 + var out []blockformat.Block 29 + for _, v := range bs.set { 30 + out = append(out, v) 31 + } 32 + return out 33 + } 34 + 35 + func (bs *ReadRecordBstore) Has(ctx context.Context, c cid.Cid) (bool, error) { 36 + return bs.base.Has(ctx, c) 37 + } 38 + 39 + func (bs *ReadRecordBstore) Get(ctx context.Context, c cid.Cid) (blockformat.Block, error) { 40 + blk, err := bs.base.Get(ctx, c) 41 + if err != nil { 42 + return nil, err 43 + } 44 + 45 + bs.set[c] = blk 46 + 47 + return blk, nil 48 + } 49 + 50 + func (bs *ReadRecordBstore) GetSize(ctx context.Context, c cid.Cid) (int, error) { 51 + return bs.base.GetSize(ctx, c) 52 + } 53 + 54 + func (bs *ReadRecordBstore) DeleteBlock(ctx context.Context, c cid.Cid) error { 55 + return fmt.Errorf("deletes not supported") 56 + } 57 + 58 + func (bs *ReadRecordBstore) Put(context.Context, blockformat.Block) error { 59 + return fmt.Errorf("writes not allows on read-record blockstore") 60 + } 61 + 62 + func (bs *ReadRecordBstore) PutMany(context.Context, []blockformat.Block) error { 63 + return fmt.Errorf("writes not allows on read-record blockstore") 64 + } 65 + 66 + func (bs *ReadRecordBstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { 67 + return nil, fmt.Errorf("iteration not supported on read-record blockstore") 68 + } 69 + 70 + func (bs *ReadRecordBstore) HashOnRead(enabled bool) { 71 + 72 + }