this repo has no description
0
fork

Configure Feed

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

small fix to cborgen and some other cbor fixes

+162 -106
+23 -15
api/atproto/cbor_gen.go
··· 26 26 } 27 27 28 28 cw := cbg.NewCborWriter(w) 29 + fieldCount := 3 29 30 30 - if _, err := cw.Write([]byte{163}); err != nil { 31 + if t.LexiconTypeID == "" { 32 + fieldCount-- 33 + } 34 + 35 + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { 31 36 return err 32 37 } 33 38 ··· 78 83 } 79 84 80 85 // t.LexiconTypeID (string) (string) 81 - if len("$type") > cbg.MaxLength { 82 - return xerrors.Errorf("Value in field \"$type\" was too long") 83 - } 86 + if t.LexiconTypeID != "" { 84 87 85 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { 86 - return err 87 - } 88 - if _, err := io.WriteString(w, string("$type")); err != nil { 89 - return err 90 - } 88 + if len("$type") > cbg.MaxLength { 89 + return xerrors.Errorf("Value in field \"$type\" was too long") 90 + } 91 + 92 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { 93 + return err 94 + } 95 + if _, err := io.WriteString(w, string("$type")); err != nil { 96 + return err 97 + } 91 98 92 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("com.atproto.repo.strongRef"))); err != nil { 93 - return err 94 - } 95 - if _, err := io.WriteString(w, string("com.atproto.repo.strongRef")); err != nil { 96 - return err 99 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("com.atproto.repo.strongRef"))); err != nil { 100 + return err 101 + } 102 + if _, err := io.WriteString(w, string("com.atproto.repo.strongRef")); err != nil { 103 + return err 104 + } 97 105 } 98 106 return nil 99 107 }
+1 -1
api/atproto/repostrongRef.go
··· 12 12 13 13 // RECORDTYPE: RepoStrongRef 14 14 type RepoStrongRef struct { 15 - LexiconTypeID string `json:"$type" cborgen:"$type,const=com.atproto.repo.strongRef"` 15 + LexiconTypeID string `json:"$type" cborgen:"$type,const=com.atproto.repo.strongRef,omitempty"` 16 16 Cid string `json:"cid" cborgen:"cid"` 17 17 Uri string `json:"uri" cborgen:"uri"` 18 18 }
+86 -57
api/bsky/cbor_gen.go
··· 27 27 } 28 28 29 29 cw := cbg.NewCborWriter(w) 30 + fieldCount := 7 30 31 31 - if _, err := cw.Write([]byte{167}); err != nil { 32 + if t.Embed == nil { 33 + fieldCount-- 34 + } 35 + 36 + if t.Entities == nil { 37 + fieldCount-- 38 + } 39 + 40 + if t.Facets == nil { 41 + fieldCount-- 42 + } 43 + 44 + if t.Reply == nil { 45 + fieldCount-- 46 + } 47 + 48 + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { 32 49 return err 33 50 } 34 51 ··· 75 92 } 76 93 77 94 // t.Embed (bsky.FeedPost_Embed) (struct) 78 - if len("embed") > cbg.MaxLength { 79 - return xerrors.Errorf("Value in field \"embed\" was too long") 80 - } 95 + if t.Embed != nil { 81 96 82 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("embed"))); err != nil { 83 - return err 84 - } 85 - if _, err := io.WriteString(w, string("embed")); err != nil { 86 - return err 87 - } 97 + if len("embed") > cbg.MaxLength { 98 + return xerrors.Errorf("Value in field \"embed\" was too long") 99 + } 88 100 89 - if err := t.Embed.MarshalCBOR(cw); err != nil { 90 - return err 101 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("embed"))); err != nil { 102 + return err 103 + } 104 + if _, err := io.WriteString(w, string("embed")); err != nil { 105 + return err 106 + } 107 + 108 + if err := t.Embed.MarshalCBOR(cw); err != nil { 109 + return err 110 + } 91 111 } 92 112 93 113 // t.Reply (bsky.FeedPost_ReplyRef) (struct) 94 - if len("reply") > cbg.MaxLength { 95 - return xerrors.Errorf("Value in field \"reply\" was too long") 96 - } 114 + if t.Reply != nil { 97 115 98 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("reply"))); err != nil { 99 - return err 100 - } 101 - if _, err := io.WriteString(w, string("reply")); err != nil { 102 - return err 103 - } 116 + if len("reply") > cbg.MaxLength { 117 + return xerrors.Errorf("Value in field \"reply\" was too long") 118 + } 104 119 105 - if err := t.Reply.MarshalCBOR(cw); err != nil { 106 - return err 120 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("reply"))); err != nil { 121 + return err 122 + } 123 + if _, err := io.WriteString(w, string("reply")); err != nil { 124 + return err 125 + } 126 + 127 + if err := t.Reply.MarshalCBOR(cw); err != nil { 128 + return err 129 + } 107 130 } 108 131 109 132 // t.Facets ([]*bsky.RichtextFacet) (slice) 110 - if len("facets") > cbg.MaxLength { 111 - return xerrors.Errorf("Value in field \"facets\" was too long") 112 - } 133 + if t.Facets != nil { 134 + 135 + if len("facets") > cbg.MaxLength { 136 + return xerrors.Errorf("Value in field \"facets\" was too long") 137 + } 113 138 114 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("facets"))); err != nil { 115 - return err 116 - } 117 - if _, err := io.WriteString(w, string("facets")); err != nil { 118 - return err 119 - } 139 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("facets"))); err != nil { 140 + return err 141 + } 142 + if _, err := io.WriteString(w, string("facets")); err != nil { 143 + return err 144 + } 120 145 121 - if len(t.Facets) > cbg.MaxLength { 122 - return xerrors.Errorf("Slice value in field t.Facets was too long") 123 - } 146 + if len(t.Facets) > cbg.MaxLength { 147 + return xerrors.Errorf("Slice value in field t.Facets was too long") 148 + } 124 149 125 - if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Facets))); err != nil { 126 - return err 127 - } 128 - for _, v := range t.Facets { 129 - if err := v.MarshalCBOR(cw); err != nil { 150 + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Facets))); err != nil { 130 151 return err 131 152 } 153 + for _, v := range t.Facets { 154 + if err := v.MarshalCBOR(cw); err != nil { 155 + return err 156 + } 157 + } 132 158 } 133 159 134 160 // t.Entities ([]*bsky.FeedPost_Entity) (slice) 135 - if len("entities") > cbg.MaxLength { 136 - return xerrors.Errorf("Value in field \"entities\" was too long") 137 - } 161 + if t.Entities != nil { 162 + 163 + if len("entities") > cbg.MaxLength { 164 + return xerrors.Errorf("Value in field \"entities\" was too long") 165 + } 138 166 139 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("entities"))); err != nil { 140 - return err 141 - } 142 - if _, err := io.WriteString(w, string("entities")); err != nil { 143 - return err 144 - } 167 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("entities"))); err != nil { 168 + return err 169 + } 170 + if _, err := io.WriteString(w, string("entities")); err != nil { 171 + return err 172 + } 145 173 146 - if len(t.Entities) > cbg.MaxLength { 147 - return xerrors.Errorf("Slice value in field t.Entities was too long") 148 - } 174 + if len(t.Entities) > cbg.MaxLength { 175 + return xerrors.Errorf("Slice value in field t.Entities was too long") 176 + } 149 177 150 - if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Entities))); err != nil { 151 - return err 152 - } 153 - for _, v := range t.Entities { 154 - if err := v.MarshalCBOR(cw); err != nil { 178 + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Entities))); err != nil { 155 179 return err 180 + } 181 + for _, v := range t.Entities { 182 + if err := v.MarshalCBOR(cw); err != nil { 183 + return err 184 + } 156 185 } 157 186 } 158 187
+4 -4
api/bsky/feedpost.go
··· 21 21 type FeedPost struct { 22 22 LexiconTypeID string `json:"$type" cborgen:"$type,const=app.bsky.feed.post"` 23 23 CreatedAt string `json:"createdAt" cborgen:"createdAt"` 24 - Embed *FeedPost_Embed `json:"embed,omitempty" cborgen:"embed"` 25 - Entities []*FeedPost_Entity `json:"entities,omitempty" cborgen:"entities"` 26 - Facets []*RichtextFacet `json:"facets,omitempty" cborgen:"facets"` 27 - Reply *FeedPost_ReplyRef `json:"reply,omitempty" cborgen:"reply"` 24 + Embed *FeedPost_Embed `json:"embed,omitempty" cborgen:"embed,omitempty"` 25 + Entities []*FeedPost_Entity `json:"entities,omitempty" cborgen:"entities,omitempty"` 26 + Facets []*RichtextFacet `json:"facets,omitempty" cborgen:"facets,omitempty"` 27 + Reply *FeedPost_ReplyRef `json:"reply,omitempty" cborgen:"reply,omitempty"` 28 28 Text string `json:"text" cborgen:"text"` 29 29 } 30 30
+1 -1
go.mod
··· 30 30 github.com/prometheus/client_golang v1.14.0 31 31 github.com/stretchr/testify v1.8.1 32 32 github.com/urfave/cli/v2 v2.23.7 33 - github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa 33 + github.com/whyrusleeping/cbor-gen v0.0.0-20230331140348-1f892b517e70 34 34 github.com/whyrusleeping/go-did v0.0.0-20230301193428-2146016fc220 35 35 go.opentelemetry.io/otel v1.11.2 36 36 go.opentelemetry.io/otel/exporters/jaeger v1.11.2
+4
go.sum
··· 627 627 github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11 h1:5HZfQkwe0mIfyDmc1Em5GqlNRzcdtlv4HTNmdpt7XH0= 628 628 github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa h1:EyA027ZAkuaCLoxVX4r1TZMPy1d31fM6hbfQ4OU4I5o= 629 629 github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= 630 + github.com/whyrusleeping/cbor-gen v0.0.0-20230331140123-68b8a684906e h1:66UCBX90o0vfhi4olXkxlZZa0MPkhIyAsJg3YFTU3Q4= 631 + github.com/whyrusleeping/cbor-gen v0.0.0-20230331140123-68b8a684906e/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= 632 + github.com/whyrusleeping/cbor-gen v0.0.0-20230331140348-1f892b517e70 h1:iNBzUKTsJc9RqStEVX2VYgVHATTU39IuB7g0e8OPWXU= 633 + github.com/whyrusleeping/cbor-gen v0.0.0-20230331140348-1f892b517e70/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= 630 634 github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E= 631 635 github.com/whyrusleeping/go-did v0.0.0-20230301193428-2146016fc220 h1:EO/9z3yDvx1van1/0esdcqhalZZQGRj3I1BPTWr5k3A= 632 636 github.com/whyrusleeping/go-did v0.0.0-20230301193428-2146016fc220/go.mod h1:qPtRyexGM5XMHFIfjH+EiA/A/1n2JakWEdMPC53pJAE=
+24 -24
lex/util/cbor_gen.go
··· 292 292 } 293 293 } 294 294 295 - // t.MimeType (string) (string) 296 - if len("mimeType") > cbg.MaxLength { 297 - return xerrors.Errorf("Value in field \"mimeType\" was too long") 295 + // t.LexiconTypeID (string) (string) 296 + if len("$type") > cbg.MaxLength { 297 + return xerrors.Errorf("Value in field \"$type\" was too long") 298 298 } 299 299 300 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("mimeType"))); err != nil { 300 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { 301 301 return err 302 302 } 303 - if _, err := io.WriteString(w, string("mimeType")); err != nil { 303 + if _, err := io.WriteString(w, string("$type")); err != nil { 304 304 return err 305 305 } 306 306 307 - if len(t.MimeType) > cbg.MaxLength { 308 - return xerrors.Errorf("Value in field t.MimeType was too long") 307 + if len(t.LexiconTypeID) > cbg.MaxLength { 308 + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") 309 309 } 310 310 311 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.MimeType))); err != nil { 311 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { 312 312 return err 313 313 } 314 - if _, err := io.WriteString(w, string(t.MimeType)); err != nil { 314 + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { 315 315 return err 316 316 } 317 317 318 - // t.LexiconTypeID (string) (string) 319 - if len("LexiconTypeID") > cbg.MaxLength { 320 - return xerrors.Errorf("Value in field \"LexiconTypeID\" was too long") 318 + // t.MimeType (string) (string) 319 + if len("mimeType") > cbg.MaxLength { 320 + return xerrors.Errorf("Value in field \"mimeType\" was too long") 321 321 } 322 322 323 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("LexiconTypeID"))); err != nil { 323 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("mimeType"))); err != nil { 324 324 return err 325 325 } 326 - if _, err := io.WriteString(w, string("LexiconTypeID")); err != nil { 326 + if _, err := io.WriteString(w, string("mimeType")); err != nil { 327 327 return err 328 328 } 329 329 330 - if len(t.LexiconTypeID) > cbg.MaxLength { 331 - return xerrors.Errorf("Value in field t.LexiconTypeID was too long") 330 + if len(t.MimeType) > cbg.MaxLength { 331 + return xerrors.Errorf("Value in field t.MimeType was too long") 332 332 } 333 333 334 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { 334 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.MimeType))); err != nil { 335 335 return err 336 336 } 337 - if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { 337 + if _, err := io.WriteString(w, string(t.MimeType)); err != nil { 338 338 return err 339 339 } 340 340 return nil ··· 414 414 415 415 t.Size = int64(extraI) 416 416 } 417 - // t.MimeType (string) (string) 418 - case "mimeType": 417 + // t.LexiconTypeID (string) (string) 418 + case "$type": 419 419 420 420 { 421 421 sval, err := cbg.ReadString(cr) ··· 423 423 return err 424 424 } 425 425 426 - t.MimeType = string(sval) 426 + t.LexiconTypeID = string(sval) 427 427 } 428 - // t.LexiconTypeID (string) (string) 429 - case "LexiconTypeID": 428 + // t.MimeType (string) (string) 429 + case "mimeType": 430 430 431 431 { 432 432 sval, err := cbg.ReadString(cr) ··· 434 434 return err 435 435 } 436 436 437 - t.LexiconTypeID = string(sval) 437 + t.MimeType = string(sval) 438 438 } 439 439 440 440 default:
+9 -3
lex/util/lex_types.go
··· 4 4 "bytes" 5 5 "encoding/base64" 6 6 "encoding/json" 7 + "fmt" 7 8 "io" 8 9 9 10 "github.com/ipfs/go-cid" ··· 45 46 } 46 47 47 48 func (ll *LexLink) UnmarshalJSON(raw []byte) error { 49 + fmt.Println("PARSING LEX LINK: ", raw) 48 50 var jl jsonLink 49 - err := json.Unmarshal(raw, &jl) 50 - if err != nil { 51 + if err := json.Unmarshal(raw, &jl); err != nil { 51 52 return xerrors.Errorf("parsing cid-link JSON: %v", err) 52 53 } 54 + 53 55 c, err := cid.Decode(jl.Link) 54 56 if err != nil { 55 57 return xerrors.Errorf("parsing cid-link CID: %v", err) ··· 150 152 } 151 153 152 154 type BlobSchema struct { 153 - LexiconTypeID string `json:"$type,omitempty"` 155 + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type"` 154 156 Ref LexLink `json:"ref" cborgen:"ref"` 155 157 MimeType string `json:"mimeType" cborgen:"mimeType"` 156 158 Size int64 `json:"size" cborgen:"size"` ··· 221 223 } 222 224 return lb.MarshalCBOR(w) 223 225 } else { 226 + fmt.Println("MARSHAL BLOB: ", b.Ref, b.MimeType, b.Size) 224 227 bs := BlobSchema{ 225 228 LexiconTypeID: "blob", 226 229 Ref: b.Ref, ··· 236 239 if err != nil { 237 240 return xerrors.Errorf("parsing $blob CBOR type: %w", err) 238 241 } 242 + 243 + fmt.Println("LEX BLOB TYPE: ", typ) 239 244 *lb = LexBlob{} 240 245 if typ == "blob" { 241 246 var bs BlobSchema ··· 243 248 if err != nil { 244 249 return xerrors.Errorf("parsing $blob CBOR: %v", err) 245 250 } 251 + fmt.Println("BLOB SCHEMA: ", bs.Ref) 246 252 lb.Ref = bs.Ref 247 253 lb.MimeType = bs.MimeType 248 254 lb.Size = bs.Size
+10 -1
testing/feedpost_test.go
··· 3 3 import ( 4 4 "bytes" 5 5 "encoding/json" 6 + "fmt" 6 7 "io" 7 8 "os" 8 9 "testing" ··· 10 11 comatproto "github.com/bluesky-social/indigo/api/atproto" 11 12 appbsky "github.com/bluesky-social/indigo/api/bsky" 12 13 lexutil "github.com/bluesky-social/indigo/lex/util" 14 + "github.com/ipfs/go-cid" 13 15 14 16 "github.com/stretchr/testify/assert" 15 17 ) ··· 42 44 assert.NotNil(fp.Embed.EmbedRecordWithMedia) 43 45 assert.Equal("app.bsky.embed.recordWithMedia", fp.Embed.EmbedRecordWithMedia.LexiconTypeID) 44 46 47 + cc, err := cid.Decode("bafkreieqq463374bbcbeq7gpmet5rvrpeqow6t4rtjzrkhnlumdylagaqa") 48 + if err != nil { 49 + t.Fatal(err) 50 + } 51 + 45 52 assert.Equal( 46 53 &appbsky.EmbedRecordWithMedia{ 47 54 LexiconTypeID: "app.bsky.embed.recordWithMedia", ··· 52 59 &appbsky.EmbedImages_Image{ 53 60 Image: &lexutil.LexBlob{ 54 61 //LexiconTypeID: "blob", 55 - //Ref: lexutil.LexLink(cid.Undef), // 000155122090873DBDFF810882487CCF6127D8D62F241D6F4F919A73151DABA3078580C080 62 + Ref: lexutil.LexLink(cc), // 000155122090873DBDFF810882487CCF6127D8D62F241D6F4F919A73151DABA3078580C080 56 63 Size: 751473, 57 64 MimeType: "image/jpeg", 58 65 }, ··· 75 82 outCborBytes := new(bytes.Buffer) 76 83 assert.NoError(fp.MarshalCBOR(outCborBytes)) 77 84 assert.Equal(cborBytes, outCborBytes.Bytes()) 85 + 86 + fmt.Printf("OUTPUT: %x\n", outCborBytes.Bytes()) 78 87 79 88 // marshal as JSON 80 89 outJsonBytes, err := json.Marshal(fp)