Skip to content

Commit

Permalink
chore(worker): add null pointer judgment
Browse files Browse the repository at this point in the history
  • Loading branch information
polebug committed Dec 2, 2024
1 parent 096929e commit 71a4ca8
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions internal/engine/worker/atproto/core/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,24 @@ func (w *worker) transformProfile(_ context.Context, message at.Message, activit

// buildPostMetadata constructs metadata for a post message.
func (w *worker) buildPostMetadata(message at.Message) *metadata.SocialPost {
return &metadata.SocialPost{
post := &metadata.SocialPost{
Handle: message.Handle,
Body: message.Feed.Text,
Media: w.buildPostMedia(message.Feed),
ProfileID: message.Did.String(),
PublicationID: message.Rkey,
ContentURI: message.URI,
Tags: message.Feed.Tags,
Timestamp: uint64(message.CreatedAt.Unix()),
}

if message.Feed != nil {
post.Body = message.Feed.Text
post.Tags = message.Feed.Tags

if message.Feed.Embed != nil {
post.Media = w.buildPostMedia(message.Feed.Embed)
}
}

return post
}

// buildProfileMetadata constructs metadata for a profile message.
Expand Down Expand Up @@ -234,12 +242,7 @@ func (w *worker) buildPostAction(from string, to string, typex schema.Type, post
}

// buildPostMedia will build post media from embeds.
func (w *worker) buildPostMedia(post *bsky.FeedPost) []metadata.Media {
if post == nil || post.Embed == nil {
return nil
}

embed := post.Embed
func (w *worker) buildPostMedia(embed *bsky.FeedPost_Embed) []metadata.Media {
media := make([]metadata.Media, 0)

if embed.EmbedImages != nil && embed.EmbedImages.Images != nil {
Expand Down

0 comments on commit 71a4ca8

Please sign in to comment.