this repo has no description
0
fork

Configure Feed

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

delete post and list posts commands

why dc8f3031 d7816ea5

+87 -6
+14
api/atproto.go
··· 166 166 167 167 return &out, nil 168 168 } 169 + 170 + func (atp *ATProto) RepoDeleteRecord(ctx context.Context, did, collection, rkey string) error { 171 + body := map[string]interface{}{ 172 + "did": did, 173 + "collection": collection, 174 + "rkey": rkey, 175 + } 176 + 177 + if err := atp.C.Do(ctx, xrpc.Procedure, encJson, "com.atproto.repo.deleteRecord", nil, body, nil); err != nil { 178 + return err 179 + } 180 + 181 + return nil 182 + }
+68 -5
cmd/gosky/main.go
··· 1 1 package main 2 2 3 3 import ( 4 + "bytes" 4 5 "context" 5 6 "encoding/json" 6 7 "fmt" ··· 8 9 "strings" 9 10 "time" 10 11 12 + "github.com/ipfs/go-cid" 11 13 cli "github.com/urfave/cli/v2" 12 14 api "github.com/whyrusleeping/gosky/api" 13 15 cliutil "github.com/whyrusleeping/gosky/cmd/gosky/util" 16 + "github.com/whyrusleeping/gosky/repo" 14 17 ) 15 18 16 19 func main() { ··· 26 29 }, 27 30 } 28 31 app.Commands = []*cli.Command{ 32 + actorGetSuggestionsCmd, 29 33 createSessionCmd, 30 - newAccountCmd, 31 - postCmd, 34 + deletePostCmd, 32 35 didCmd, 33 - syncCmd, 34 - feedGetCmd, 35 36 feedGetAuthorCmd, 36 - actorGetSuggestionsCmd, 37 + feedGetCmd, 37 38 feedSetVoteCmd, 38 39 graphGetFollowsCmd, 40 + newAccountCmd, 41 + postCmd, 39 42 refreshAuthTokenCmd, 43 + syncCmd, 44 + listAllPostsCmd, 45 + deletePostCmd, 40 46 } 41 47 42 48 app.RunAndExitOnError() ··· 406 412 return nil 407 413 }, 408 414 } 415 + 416 + var deletePostCmd = &cli.Command{ 417 + Name: "delete", 418 + Action: func(cctx *cli.Context) error { 419 + atpc, err := cliutil.GetATPClient(cctx, true) 420 + if err != nil { 421 + return err 422 + } 423 + 424 + rkey := cctx.Args().First() 425 + 426 + if rkey == "" { 427 + return fmt.Errorf("must specify rkey of post to delete") 428 + } 429 + 430 + return atpc.RepoDeleteRecord(context.TODO(), atpc.C.Auth.Did, "app.bsky.feed.post", rkey) 431 + }, 432 + } 433 + 434 + var listAllPostsCmd = &cli.Command{ 435 + Name: "list", 436 + Action: func(cctx *cli.Context) error { 437 + atpc, err := cliutil.GetATPClient(cctx, true) 438 + if err != nil { 439 + return err 440 + } 441 + 442 + did := cctx.Args().First() 443 + if did == "" { 444 + did = atpc.C.Auth.Did 445 + } 446 + 447 + ctx := context.TODO() 448 + repob, err := atpc.SyncGetRepo(ctx, did, nil) 449 + if err != nil { 450 + return err 451 + } 452 + 453 + rr, err := repo.ReadRepoFromCar(ctx, bytes.NewReader(repob)) 454 + if err != nil { 455 + return err 456 + } 457 + 458 + if err := rr.ForEach(ctx, "app.bsky.feed.post", func(k string, v cid.Cid) error { 459 + if !strings.HasPrefix(k, "app.bsky.feed.post/") { 460 + return repo.ErrDoneIterating 461 + } 462 + 463 + fmt.Println(k) 464 + return nil 465 + }); err != nil { 466 + return err 467 + } 468 + 469 + return nil 470 + }, 471 + }
+5 -1
repo/repo.go
··· 193 193 return t, nil 194 194 } 195 195 196 + var ErrDoneIterating = fmt.Errorf("done iterating") 197 + 196 198 func (r *Repo) ForEach(ctx context.Context, prefix string, cb func(k string, v cid.Cid) error) error { 197 199 var com Commit 198 200 if err := r.cst.Get(ctx, r.sr.Root, &com); err != nil { ··· 204 206 if err := t.WalkLeavesFrom(ctx, prefix, func(e mst.NodeEntry) error { 205 207 return cb(e.Key, e.Val) 206 208 }); err != nil { 207 - return err 209 + if err != ErrDoneIterating { 210 + return err 211 + } 208 212 } 209 213 210 214 return nil