this repo has no description
0
fork

Configure Feed

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

fix empty util.Blob in CBOR-decoded post image embed (#67)

The `cborgen` field names were missing, and were being auto-populated
with incorrect capitalization. This is why the Cid and MimeType fields
were coming through empty.

I also added `cborgen` fields on the other structs in this file. I'm not
sure they are actually necessary, maybe they are only used for reading
JSON? But didn't seem like it would hurt to have the CBOR field names
specified as well.

authored by

Whyrusleeping and committed by
GitHub
e175912a c93363ae

+106 -14
+10 -10
lex/util/cbor_gen.go
··· 126 126 } 127 127 128 128 // t.Cid (string) (string) 129 - if len("Cid") > cbg.MaxLength { 130 - return xerrors.Errorf("Value in field \"Cid\" was too long") 129 + if len("cid") > cbg.MaxLength { 130 + return xerrors.Errorf("Value in field \"cid\" was too long") 131 131 } 132 132 133 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Cid"))); err != nil { 133 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("cid"))); err != nil { 134 134 return err 135 135 } 136 - if _, err := io.WriteString(w, string("Cid")); err != nil { 136 + if _, err := io.WriteString(w, string("cid")); err != nil { 137 137 return err 138 138 } 139 139 ··· 149 149 } 150 150 151 151 // t.MimeType (string) (string) 152 - if len("MimeType") > cbg.MaxLength { 153 - return xerrors.Errorf("Value in field \"MimeType\" was too long") 152 + if len("mimeType") > cbg.MaxLength { 153 + return xerrors.Errorf("Value in field \"mimeType\" was too long") 154 154 } 155 155 156 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("MimeType"))); err != nil { 156 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("mimeType"))); err != nil { 157 157 return err 158 158 } 159 - if _, err := io.WriteString(w, string("MimeType")); err != nil { 159 + if _, err := io.WriteString(w, string("mimeType")); err != nil { 160 160 return err 161 161 } 162 162 ··· 212 212 213 213 switch name { 214 214 // t.Cid (string) (string) 215 - case "Cid": 215 + case "cid": 216 216 217 217 { 218 218 sval, err := cbg.ReadString(cr) ··· 223 223 t.Cid = string(sval) 224 224 } 225 225 // t.MimeType (string) (string) 226 - case "MimeType": 226 + case "mimeType": 227 227 228 228 { 229 229 sval, err := cbg.ReadString(cr)
+4 -4
lex/util/util.go
··· 8 8 ) 9 9 10 10 type typeExtractor struct { 11 - Type string `json:"$type"` 11 + Type string `json:"$type" cborgen:"$type"` 12 12 } 13 13 14 14 func TypeExtract(b []byte) (string, error) { ··· 21 21 } 22 22 23 23 type Blob struct { 24 - Cid string `json:"cid"` 25 - MimeType string `json:"mimeType"` 24 + Cid string `json:"cid" cborgen:"cid"` 25 + MimeType string `json:"mimeType" cborgen:"mimeType"` 26 26 } 27 27 28 28 type CborChecker struct { 29 - Type string `cborgen:"$type"` 29 + Type string `json:"$type" cborgen:"$type"` 30 30 } 31 31 32 32 func CborTypeExtract(b []byte) (string, error) {
testing/repo_slice.car

This is a binary file and will not be displayed.

+33
testing/repo_slice_record.json
··· 1 + { 2 + "cid": "bafyreiapesxwibnujg44xphqq23ekkozgcmnenj2onnx4gkgy4uipziyc4", 3 + "indexedAt": "2023-03-14T02:48:20.484Z", 4 + "takedownId": null, 5 + "uri": "at://did:plc:6evlgoug7wwijzxhzt2riyic/app.bsky.feed.post/3jquh3emtzo2o", 6 + "value": { 7 + "$type": "app.bsky.feed.post", 8 + "createdAt": "2023-03-13T19:48:20-07:00", 9 + "embed": { 10 + "$type": "app.bsky.embed.images", 11 + "images": [ 12 + { 13 + "alt": "Sausage sandwich italian style", 14 + "image": { 15 + "cid": "bafkreiblkobl6arfg3j7eft3akdhn2hmr2qmzfkefcgu4agnswvssg4a6a", 16 + "mimeType": "image/jpeg" 17 + } 18 + } 19 + ] 20 + }, 21 + "entities": [ 22 + { 23 + "index": { 24 + "end": 19, 25 + "start": 0 26 + }, 27 + "type": "mention", 28 + "value": "did:plc:62h4kgufuxjsa4o5udp4dgdw" 29 + } 30 + ], 31 + "text": "@ledner9213-c6.test Luck yesterday in peep might were choir lastly luxury before." 32 + } 33 + }
+59
testing/repo_slice_test.go
··· 1 + package testing 2 + 3 + import ( 4 + "context" 5 + "encoding/json" 6 + "os" 7 + "fmt" 8 + "testing" 9 + 10 + "github.com/bluesky-social/indigo/repo" 11 + appbsky "github.com/bluesky-social/indigo/api/bsky" 12 + ) 13 + 14 + // ipfs dag import testing/repo_slice.car 15 + // ipfs dag get bafyreiapesxwibnujg44xphqq23ekkozgcmnenj2onnx4gkgy4uipziyc4 | jq . 16 + // ipfs dag get bafyreiapesxwibnujg44xphqq23ekkozgcmnenj2onnx4gkgy4uipziyc4 --output-codec=dag-cbor > testing/repo_record.cbor 17 + 18 + func TestRepoSliceParse(t *testing.T) { 19 + ctx := context.TODO() 20 + fi, err := os.Open("repo_slice.car") 21 + if err != nil { 22 + t.Fatal(err) 23 + } 24 + 25 + sliceRepo, err := repo.ReadRepoFromCar(ctx, fi) 26 + if err != nil { 27 + t.Fatal(err) 28 + } 29 + 30 + _, rec, err := sliceRepo.GetRecord(ctx, "app.bsky.feed.post/3jquh3emtzo2o") 31 + if err != nil { 32 + t.Fatal(err) 33 + } 34 + 35 + post, suc := rec.(*appbsky.FeedPost) 36 + if !suc { 37 + t.Fatal("failed to deserialize post") 38 + } 39 + postJson, err := json.Marshal(post) 40 + if err != nil { 41 + t.Fatal(err) 42 + } 43 + fmt.Println(string(postJson)) 44 + 45 + img := post.Embed.EmbedImages.Images[0] 46 + if img.Alt != "Sausage sandwich italian style" { 47 + t.Fatal("didn't get expected Alt text") 48 + } 49 + 50 + if img.Image.Cid == "" { 51 + t.Fatal("got nil Cid on image") 52 + } 53 + if img.Image.Cid != "bafkreiblkobl6arfg3j7eft3akdhn2hmr2qmzfkefcgu4agnswvssg4a6a" { 54 + t.Fatal("didn't get expected image blob Cid") 55 + } 56 + if img.Image.MimeType != "image/jpeg" { 57 + t.Fatal("didn't get expected image blob mimetype") 58 + } 59 + }