Skip to content

Commit

Permalink
cmd/bsky-webhook: check the correct timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Nov 20, 2024
1 parent 3b39b37 commit a11ba29
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 12 additions & 1 deletion cmd/bsky-webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,18 @@ func readJetstreamMessage(ctx context.Context, jetstreamMessageEncoded []byte, b
}

// we can ignore these messages
if bskyMessage.Time < (time.Now().UnixMicro()-86400000000) || bskyMessage.Kind != "commit" || bskyMessage.Commit == nil || bskyMessage.Commit.Operation != "create" || bskyMessage.Commit.Record == nil || bskyMessage.Commit.Rkey == "" {
if bskyMessage.Kind != "commit" || bskyMessage.Commit == nil || bskyMessage.Commit.Operation != "create" || bskyMessage.Commit.Record == nil || bskyMessage.Commit.Rkey == "" {
return nil
}

// parse timestamp user provided when posting
postTime, err := time.Parse(time.RFC3339, bskyMessage.Commit.Record.CreatedAtString)
if err != nil {
return err
}

// if too old, ignore
if time.Since(postTime) > time.Hour*24 {
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/bsky-webhook/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type BskyCommit struct {
}

type BskyRecord struct {
Text string `json:"text"`
Embed BskyEmbed `json:"embed"`
Text string `json:"text"`
Embed BskyEmbed `json:"embed"`
CreatedAtString string `json:"createdAt"`
}

type BskyEmbed struct {
Expand Down

0 comments on commit a11ba29

Please sign in to comment.