From 2498b86329113c4ac47be7796a433a3c831f0bf2 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Mon, 26 Feb 2024 09:47:14 -0800 Subject: [PATCH] handle bsky.app urls in get-record --- cmd/gosky/main.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/cmd/gosky/main.go b/cmd/gosky/main.go index 81b85738e..028cd0196 100644 --- a/cmd/gosky/main.go +++ b/cmd/gosky/main.go @@ -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 {