package main import ( "bytes" "context" "errors" "fmt" "log/slog" "strconv" "strings" comatproto "github.com/bluesky-social/indigo/api/atproto" appbsky "github.com/bluesky-social/indigo/api/bsky" "github.com/bluesky-social/indigo/backfill" "github.com/ipfs/go-cid" ) type commitHandler func(context.Context, *comatproto.SyncSubscribeRepos_Commit) error func (b *Backend) RepoCommitHandler( ctx context.Context, evt *comatproto.SyncSubscribeRepos_Commit, ) error { select { case <-ctx.Done(): return nil default: // } b.firehoseLk.Lock() b.firehoseSeq = strconv.Itoa(int(evt.Seq)) b.firehoseLk.Unlock() if b.backfillComplete { return b.bf.HandleEvent(ctx, evt) } job, err := b.bf.Store.GetJob(ctx, evt.Repo) if job == nil { if errors.Is(err, backfill.ErrJobNotFound) { return nil } else { return fmt.Errorf("error getting job: %w", err) } } else { return b.bf.HandleEvent(ctx, evt) } } type handleOpCreateUpdate func(context.Context, string, string, string, *[]byte, *cid.Cid) error type handleOpDelete func(context.Context, string, string, string) error func (b *Backend) HandleCreateOp(ctx context.Context, repo, rev, path string, rec *[]byte, cid *cid.Cid) error { if !strings.HasPrefix(path, "app.bsky.feed.generator/") { return nil } sl := slog.With("source", "commitHandler") var out appbsky.FeedGenerator if err := out.UnmarshalCBOR(bytes.NewReader(*rec)); err != nil { sl.Error("failed to unmarshal record", "err", err) return fmt.Errorf("failed to unmarshal record: %w", err) } feedgen := &FeedGenerator{ AtUri: fmt.Sprintf("at://%s/%s", repo, path), DisplayName: out.DisplayName, FeedService: out.Did, CreatedAt: out.CreatedAt, Description: out.Description, ContentMode: out.ContentMode, AcceptsInteractions: out.AcceptsInteractions, } if err := b.data.Model(&FeedGenerator{}).Create(feedgen).Error; err != nil { return fmt.Errorf("error adding feedgen to database: %w", err) } return nil } func (b *Backend) HandleUpdateOp(ctx context.Context, repo, rev, path string, rec *[]byte, cid *cid.Cid) error { return nil } func (b *Backend) HandleDeleteOp(ctx context.Context, repo, rev, path string) error { return nil }