this repo has no description
0
fork

Configure Feed

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

allow custom headers in xrpc client, better feedgen cli tool (#186)

authored by

Whyrusleeping and committed by
GitHub
cc5f4522 cf3da8ac

+55 -16
+47 -15
cmd/gosky/main.go
··· 1245 1245 Name: "did", 1246 1246 Required: true, 1247 1247 }, 1248 + &cli.StringFlag{ 1249 + Name: "description", 1250 + }, 1251 + &cli.StringFlag{ 1252 + Name: "display-name", 1253 + }, 1248 1254 }, 1249 1255 Action: func(cctx *cli.Context) error { 1250 1256 xrpcc, err := cliutil.GetXrpcClient(cctx, true) ··· 1252 1258 return err 1253 1259 } 1254 1260 1255 - name := cctx.String("name") 1261 + rkey := cctx.String("name") 1262 + name := rkey 1263 + if dn := cctx.String("display-name"); dn != "" { 1264 + name = dn 1265 + } 1266 + 1256 1267 did := cctx.String("did") 1257 1268 1258 1269 var desc *string ··· 1260 1271 desc = &d 1261 1272 } 1262 1273 1263 - resp, err := atproto.RepoCreateRecord(context.TODO(), xrpcc, &atproto.RepoCreateRecord_Input{ 1264 - Collection: "app.bsky.feed.generator", 1265 - Repo: xrpcc.Auth.Did, 1266 - Record: &lexutil.LexiconTypeDecoder{&bsky.FeedGenerator{ 1267 - CreatedAt: time.Now().Format(util.ISO8601), 1268 - Description: desc, 1269 - Did: did, 1270 - DisplayName: name, 1271 - }}, 1272 - }) 1273 - if err != nil { 1274 - return err 1275 - } 1274 + ctx := context.TODO() 1276 1275 1277 - fmt.Println(resp.Uri) 1276 + rec := &lexutil.LexiconTypeDecoder{&bsky.FeedGenerator{ 1277 + CreatedAt: time.Now().Format(util.ISO8601), 1278 + Description: desc, 1279 + Did: did, 1280 + DisplayName: name, 1281 + }} 1282 + 1283 + ex, err := atproto.RepoGetRecord(ctx, xrpcc, "", "app.bsky.feed.generator", xrpcc.Auth.Did, rkey) 1284 + if err == nil { 1285 + resp, err := atproto.RepoPutRecord(ctx, xrpcc, &atproto.RepoPutRecord_Input{ 1286 + SwapRecord: ex.Cid, 1287 + Collection: "app.bsky.feed.generator", 1288 + Repo: xrpcc.Auth.Did, 1289 + Rkey: rkey, 1290 + Record: rec, 1291 + }) 1292 + if err != nil { 1293 + return err 1294 + } 1295 + 1296 + fmt.Println(resp.Uri) 1297 + } else { 1298 + resp, err := atproto.RepoCreateRecord(ctx, xrpcc, &atproto.RepoCreateRecord_Input{ 1299 + Collection: "app.bsky.feed.generator", 1300 + Repo: xrpcc.Auth.Did, 1301 + Rkey: &rkey, 1302 + Record: rec, 1303 + }) 1304 + if err != nil { 1305 + return err 1306 + } 1307 + 1308 + fmt.Println(resp.Uri) 1309 + } 1278 1310 1279 1311 return nil 1280 1312 },
+8 -1
xrpc/xrpc.go
··· 21 21 AdminToken *string 22 22 Host string 23 23 UserAgent *string 24 + Headers map[string]string 24 25 } 25 26 26 27 func (c *Client) getClient() *http.Client { ··· 104 105 req.Header.Set("User-Agent", "indigo/"+version.Version) 105 106 } 106 107 108 + if c.Headers != nil { 109 + for k, v := range c.Headers { 110 + req.Header.Set(k, v) 111 + } 112 + } 113 + 107 114 // use admin auth if we have it configured and are doing a request that requires it 108 115 if c.AdminToken != nil && (strings.HasPrefix(method, "com.atproto.admin.") || method == "com.atproto.account.createInviteCode" || method == "com.atproto.server.createInviteCodes") { 109 116 req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:"+*c.AdminToken))) ··· 121 128 if resp.StatusCode != 200 { 122 129 var i interface{} 123 130 _ = json.NewDecoder(resp.Body).Decode(&i) 124 - //fmt.Println(i) 131 + fmt.Println(i) 125 132 return fmt.Errorf("XRPC ERROR %d: %s", resp.StatusCode, resp.Status) 126 133 } 127 134