this repo has no description
0
fork

Configure Feed

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

Add avatar to `AccountMeta` (#779)

smol change. couple of new rules need avatar cids. currently have to
fetch from public api before the rule processes in a separate request
which is meh, since we have the info here already.

authored by

bnewbold and committed by
GitHub
fc4b12c1 6ac14ce9

+70
+2
automod/engine/account_meta.go
··· 32 32 33 33 type ProfileSummary struct { 34 34 HasAvatar bool 35 + AvatarCid *string 36 + BannerCid *string 35 37 Description *string 36 38 DisplayName *string 37 39 }
+42
automod/engine/cid_from_cdn_test.go
··· 1 + package engine 2 + 3 + import ( 4 + "github.com/stretchr/testify/assert" 5 + "testing" 6 + ) 7 + 8 + func TestCidFromCdnUrl(t *testing.T) { 9 + assert := assert.New(t) 10 + 11 + fixCid := "abcdefghijk" 12 + 13 + fixtures := []struct { 14 + url string 15 + cid *string 16 + }{ 17 + { 18 + url: "https://cdn.bsky.app/img/avatar/plain/did:plc:abc123/abcdefghijk@jpeg", 19 + cid: &fixCid, 20 + }, 21 + { 22 + url: "https://cdn.bsky.app/img/feed_fullsize/plain/did:plc:abc123/abcdefghijk@jpeg", 23 + cid: &fixCid, 24 + }, 25 + { 26 + url: "https://cdn.bsky.app/img/feed_fullsize", 27 + cid: nil, 28 + }, 29 + { 30 + url: "https://cdn.bsky.app/img/feed_fullsize/plain/did:plc:abc123/abcdefghijk", 31 + cid: &fixCid, 32 + }, 33 + { 34 + url: "https://cdn.asky.app/img/feed_fullsize/plain/did:plc:abc123/abcdefghijk@jpeg", 35 + cid: nil, 36 + }, 37 + } 38 + 39 + for _, fix := range fixtures { 40 + assert.Equal(fix.cid, cidFromCdnUrl(&fix.url)) 41 + } 42 + }
+2
automod/engine/fetch_account_meta.go
··· 75 75 76 76 am.Profile = ProfileSummary{ 77 77 HasAvatar: pv.Avatar != nil, 78 + AvatarCid: cidFromCdnUrl(pv.Avatar), 79 + BannerCid: cidFromCdnUrl(pv.Banner), 78 80 Description: pv.Description, 79 81 DisplayName: pv.DisplayName, 80 82 }
+24
automod/engine/util.go
··· 1 1 package engine 2 2 3 + import ( 4 + "net/url" 5 + "strings" 6 + ) 7 + 3 8 func dedupeStrings(in []string) []string { 4 9 var out []string 5 10 seen := make(map[string]bool) ··· 11 16 } 12 17 return out 13 18 } 19 + 20 + // get the cid from a bluesky cdn url 21 + func cidFromCdnUrl(str *string) *string { 22 + if str == nil { 23 + return nil 24 + } 25 + 26 + u, err := url.Parse(*str) 27 + if err != nil || u.Host != "cdn.bsky.app" { 28 + return nil 29 + } 30 + 31 + parts := strings.Split(u.Path, "/") 32 + if len(parts) != 6 { 33 + return nil 34 + } 35 + 36 + return &strings.Split(parts[5], "@")[0] 37 + }