forked from hailey.at/cocoon
An atproto PDS written in Go

fix

Changed files
+12 -27
recording_blockstore
server
sqlite_blockstore
+1
recording_blockstore/recording_blockstore.go
··· 20 return &RecordingBlockstore{ 21 base: base, 22 inserts: make(map[cid.Cid]blockformat.Block), 23 } 24 } 25
··· 20 return &RecordingBlockstore{ 21 base: base, 22 inserts: make(map[cid.Cid]blockformat.Block), 23 + reads: make(map[cid.Cid]blockformat.Block), 24 } 25 } 26
+10 -8
server/handle_sync_get_blocks.go
··· 11 "github.com/labstack/echo/v4" 12 ) 13 14 func (s *Server) handleGetBlocks(e echo.Context) error { 15 ctx := e.Request().Context() 16 - did := e.QueryParam("did") 17 - if did == "" { 18 - return helpers.InputError(e, nil) 19 - } 20 21 - cidstrs, ok := e.QueryParams()["cids"] 22 - if !ok { 23 return helpers.InputError(e, nil) 24 } 25 var cids []cid.Cid 26 27 - for _, cs := range cidstrs { 28 c, err := cid.Cast([]byte(cs)) 29 if err != nil { 30 return err ··· 33 cids = append(cids, c) 34 } 35 36 - urepo, err := s.getRepoActorByDid(did) 37 if err != nil { 38 return helpers.ServerError(e, nil) 39 }
··· 11 "github.com/labstack/echo/v4" 12 ) 13 14 + type ComAtprotoSyncGetBlocksRequest struct { 15 + Did string `query:"did"` 16 + Cids []string `query:"cids"` 17 + } 18 + 19 func (s *Server) handleGetBlocks(e echo.Context) error { 20 ctx := e.Request().Context() 21 22 + var req ComAtprotoSyncGetBlocksRequest 23 + if err := e.Bind(&req); err != nil { 24 return helpers.InputError(e, nil) 25 } 26 + 27 var cids []cid.Cid 28 29 + for _, cs := range req.Cids { 30 c, err := cid.Cast([]byte(cs)) 31 if err != nil { 32 return err ··· 35 cids = append(cids, c) 36 } 37 38 + urepo, err := s.getRepoActorByDid(req.Did) 39 if err != nil { 40 return helpers.ServerError(e, nil) 41 }
+1 -1
server/repo.go
··· 104 105 dbs := rm.s.getBlockstore(urepo.Did) 106 bs := recording_blockstore.New(dbs) 107 - r, err := repo.OpenRepo(context.TODO(), dbs, rootcid) 108 109 entries := []models.Record{} 110 var results []ApplyWriteResult
··· 104 105 dbs := rm.s.getBlockstore(urepo.Did) 106 bs := recording_blockstore.New(dbs) 107 + r, err := repo.OpenRepo(context.TODO(), bs, rootcid) 108 109 entries := []models.Record{} 110 var results []ApplyWriteResult
-18
sqlite_blockstore/sqlite_blockstore.go
··· 135 func (bs *SqliteBlockstore) HashOnRead(enabled bool) { 136 panic("not implemented") 137 } 138 - 139 - func (bs *SqliteBlockstore) Execute(ctx context.Context) error { 140 - if !bs.readonly { 141 - return fmt.Errorf("blockstore was not readonly") 142 - } 143 - 144 - bs.readonly = false 145 - for _, b := range bs.inserts { 146 - bs.Put(ctx, b) 147 - } 148 - bs.readonly = true 149 - 150 - return nil 151 - } 152 - 153 - func (bs *SqliteBlockstore) GetLog() map[cid.Cid]blocks.Block { 154 - return bs.inserts 155 - }
··· 135 func (bs *SqliteBlockstore) HashOnRead(enabled bool) { 136 panic("not implemented") 137 }