diff options
Diffstat (limited to 'backend/notes/app.bsky.feed.go')
| -rw-r--r-- | backend/notes/app.bsky.feed.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/backend/notes/app.bsky.feed.go b/backend/notes/app.bsky.feed.go index 961f8d7..3dd7b95 100644 --- a/backend/notes/app.bsky.feed.go +++ b/backend/notes/app.bsky.feed.go @@ -6,6 +6,28 @@ import ( "time" ) +type EmbedImage struct { + Alt string `json:"alt"` + Image struct { + CID string `json:"$link"` + } `json:"image"` + AspectRatio *struct { + Width int `json:"width"` + Height int `json:"height"` + } `json:"aspectRatio,omitempty"` +} + +type EmbedImages struct { + Type string `json:"$type"` + Images []EmbedImage `json:"images,omitempty"` +} + +type AppBskyFeedPostEmbed struct { + Type string `json:"$type"` + Images []EmbedImage `json:"images,omitempty"` + Media *EmbedImages `json:"media,omitempty"` +} + type AppBskyFeedPostRecord struct { URI string `json:"uri"` Value struct { @@ -28,9 +50,33 @@ type AppBskyFeedPostRecord struct { Tag string `json:"tag,omitempty"` } `json:"features"` } `json:"facets,omitempty"` + Embed *AppBskyFeedPostEmbed `json:"embed,omitempty"` } `json:"value"` } +func extractImages(embed *AppBskyFeedPostEmbed, did, pdsURL string) []Media { + if embed == nil { + return nil + } + images := embed.Images + if embed.Media != nil { + images = embed.Media.Images + } + var media []Media + for _, img := range images { + m := Media{ + URL: fmt.Sprintf("%s/xrpc/com.atproto.sync.getBlob?did=%s&cid=%s", pdsURL, did, img.Image.CID), + Alt: img.Alt, + } + if img.AspectRatio != nil { + m.Width = img.AspectRatio.Width + m.Height = img.AspectRatio.Height + } + media = append(media, m) + } + return media +} + func NoteFromAppBskyFeedPostRecord(record AppBskyFeedPostRecord, author *Author) (*Note, error) { if record.URI == "" { return nil, fmt.Errorf("missing required field: uri") @@ -99,5 +145,6 @@ func NoteFromAppBskyFeedPostRecord(record AppBskyFeedPostRecord, author *Author) Text: record.Value.Text, ReplyTo: replyTo, Facets: facets, + Media: extractImages(record.Value.Embed, did, author.PDS), }, nil } |
