Skip to content

Commit

Permalink
handle bsky.app urls in get-record (#596)
Browse files Browse the repository at this point in the history
got tired of translating bsky.app links into at:// links
  • Loading branch information
whyrusleeping authored Mar 8, 2024
2 parents 72a3a35 + 2498b86 commit 06c2c15
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions cmd/gosky/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,45 @@ var getRecordCmd = &cli.Command{
return err
}

fmt.Println(string(b))
return nil
} else if strings.HasPrefix(cctx.Args().First(), "https://bsky.app") {
xrpcc, err := cliutil.GetXrpcClient(cctx, false)
if err != nil {
return err
}

parts := strings.Split(cctx.Args().First(), "/")
if len(parts) < 4 {
return fmt.Errorf("invalid post url")
}
rkey := parts[len(parts)-1]
did := parts[len(parts)-3]

var collection string
switch parts[len(parts)-2] {
case "post":
collection = "app.bsky.feed.post"
case "profile":
collection = "app.bsky.actor.profile"
did = rkey
rkey = "self"
case "feed":
collection = "app.bsky.feed.generator"
default:
return fmt.Errorf("unrecognized link")
}

out, err := comatproto.RepoGetRecord(ctx, xrpcc, "", collection, did, rkey)
if err != nil {
return err
}

b, err := json.MarshalIndent(out.Value.Val, "", " ")
if err != nil {
return err
}

fmt.Println(string(b))
return nil
} else {
Expand Down

0 comments on commit 06c2c15

Please sign in to comment.