this repo has no description
0
fork

Configure Feed

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

fixup auth for invites command

+108 -10
+104 -9
cmd/gosky/main.go
··· 10 10 "os" 11 11 "os/signal" 12 12 "strings" 13 + "sync" 13 14 "syscall" 14 15 "time" 15 16 ··· 276 277 Subcommands: []*cli.Command{ 277 278 syncGetRepoCmd, 278 279 syncGetRootCmd, 280 + syncListReposCmd, 279 281 }, 280 282 } 281 283 ··· 1011 1013 } 1012 1014 1013 1015 var createInviteCmd = &cli.Command{ 1014 - Name: "createInvite", 1016 + Name: "createInvites", 1015 1017 Flags: []cli.Flag{ 1016 1018 &cli.StringFlag{ 1017 1019 Name: "admin-password", ··· 1026 1028 Name: "num", 1027 1029 Value: 1, 1028 1030 }, 1031 + &cli.StringFlag{ 1032 + Name: "bulk-dids", 1033 + }, 1029 1034 }, 1030 1035 Action: func(cctx *cli.Context) error { 1031 1036 xrpcc, err := cliutil.GetXrpcClient(cctx, false) 1032 1037 if err != nil { 1033 1038 return err 1034 1039 } 1040 + 1041 + adminKey := cctx.String("admin-password") 1035 1042 1036 1043 count := cctx.Int("useCount") 1037 1044 num := cctx.Int("num") 1038 1045 1046 + if bulkfi := cctx.String("bulk-dids"); bulkfi != "" { 1047 + xrpcc.AdminToken = &adminKey 1048 + dids, err := readDids(bulkfi) 1049 + if err != nil { 1050 + return err 1051 + } 1052 + 1053 + feeder := make(chan string) 1054 + var wg sync.WaitGroup 1055 + for i := 0; i < 20; i++ { 1056 + wg.Add(1) 1057 + go func() { 1058 + defer wg.Done() 1059 + for d := range feeder { 1060 + did := d 1061 + resp, err := comatproto.ServerCreateInviteCodes(context.TODO(), xrpcc, &comatproto.ServerCreateInviteCodes_Input{ 1062 + UseCount: int64(count), 1063 + ForAccount: &did, 1064 + CodeCount: int64(num), 1065 + }) 1066 + if err != nil { 1067 + log.Error(err) 1068 + } 1069 + _ = resp 1070 + } 1071 + }() 1072 + } 1073 + 1074 + for _, d := range dids { 1075 + feeder <- d 1076 + } 1077 + 1078 + close(feeder) 1079 + 1080 + wg.Wait() 1081 + return nil 1082 + } 1083 + 1039 1084 var usrdid *string 1040 1085 if forUser := cctx.Args().Get(0); forUser != "" { 1041 1086 resp, err := comatproto.IdentityResolveHandle(context.TODO(), xrpcc, forUser) 1042 1087 if err != nil { 1043 - return err 1088 + return fmt.Errorf("resolving handle: %w", err) 1044 1089 } 1045 1090 1046 1091 usrdid = &resp.Did 1047 1092 } 1048 1093 1049 - adminKey := cctx.String("admin-password") 1050 1094 xrpcc.AdminToken = &adminKey 1095 + resp, err := comatproto.ServerCreateInviteCodes(context.TODO(), xrpcc, &comatproto.ServerCreateInviteCodes_Input{ 1096 + UseCount: int64(count), 1097 + ForAccount: usrdid, 1098 + CodeCount: int64(num), 1099 + }) 1100 + if err != nil { 1101 + return fmt.Errorf("creating codes: %w", err) 1102 + } 1051 1103 1052 - for i := 0; i < num; i++ { 1053 - resp, err := comatproto.ServerCreateInviteCode(context.TODO(), xrpcc, &comatproto.ServerCreateInviteCode_Input{ 1054 - UseCount: int64(count), 1055 - ForAccount: usrdid, 1056 - }) 1104 + for _, c := range resp.Codes { 1105 + fmt.Println(c) 1106 + } 1107 + 1108 + return nil 1109 + }, 1110 + } 1111 + 1112 + func readDids(f string) ([]string, error) { 1113 + fi, err := os.Open(f) 1114 + if err != nil { 1115 + return nil, err 1116 + } 1117 + 1118 + defer fi.Close() 1119 + 1120 + scan := bufio.NewScanner(fi) 1121 + var out []string 1122 + for scan.Scan() { 1123 + out = append(out, scan.Text()) 1124 + } 1125 + 1126 + return out, nil 1127 + } 1128 + 1129 + var syncListReposCmd = &cli.Command{ 1130 + Name: "listRepos", 1131 + Action: func(cctx *cli.Context) error { 1132 + xrpcc, err := cliutil.GetXrpcClient(cctx, false) 1133 + if err != nil { 1134 + return err 1135 + } 1136 + 1137 + var curs string 1138 + for { 1139 + out, err := comatproto.SyncListRepos(context.TODO(), xrpcc, curs, 1000) 1057 1140 if err != nil { 1058 1141 return err 1059 1142 } 1060 1143 1061 - fmt.Println(resp.Code) 1144 + if len(out.Repos) == 0 { 1145 + break 1146 + } 1147 + 1148 + for _, r := range out.Repos { 1149 + fmt.Println(r.Did) 1150 + } 1151 + 1152 + if out.Cursor == nil { 1153 + break 1154 + } 1155 + 1156 + curs = *out.Cursor 1062 1157 } 1063 1158 1064 1159 return nil
+1
go.mod
··· 105 105 github.com/prometheus/procfs v0.9.0 // indirect 106 106 github.com/prometheus/statsd_exporter v0.23.1 // indirect 107 107 github.com/russross/blackfriday/v2 v2.1.0 // indirect 108 + github.com/sashabaranov/go-openai v1.7.0 // indirect 108 109 github.com/spaolacci/murmur3 v1.1.0 // indirect 109 110 github.com/valyala/bytebufferpool v1.0.0 // indirect 110 111 github.com/valyala/fasttemplate v1.2.2 // indirect
+2
go.sum
··· 586 586 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 587 587 github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= 588 588 github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 589 + github.com/sashabaranov/go-openai v1.7.0 h1:D1dBXoZhtf/aKNu6WFf0c7Ah2NM30PZ/3Mqly6cZ7fk= 590 + github.com/sashabaranov/go-openai v1.7.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg= 589 591 github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 590 592 github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 591 593 github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
+1 -1
xrpc/xrpc.go
··· 98 98 } 99 99 100 100 // use admin auth if we have it configured and are doing a request that requires it 101 - if c.AdminToken != nil && (strings.HasPrefix(method, "com.atproto.admin.") || method == "com.atproto.account.createInviteCode") { 101 + if c.AdminToken != nil && (strings.HasPrefix(method, "com.atproto.admin.") || method == "com.atproto.account.createInviteCode" || method == "com.atproto.server.createInviteCodes") { 102 102 req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:"+*c.AdminToken))) 103 103 } else if c.Auth != nil { 104 104 req.Header.Set("Authorization", "Bearer "+c.Auth.AccessJwt)