an app.bsky.* indexer
1package main
2
3import (
4 "bytes"
5 "context"
6 "fmt"
7 "log/slog"
8 "strconv"
9 "strings"
10
11 comatproto "github.com/bluesky-social/indigo/api/atproto"
12 appbsky "github.com/bluesky-social/indigo/api/bsky"
13 "github.com/ipfs/go-cid"
14)
15
16type commitHandler func(context.Context, *comatproto.SyncSubscribeRepos_Commit) error
17
18func (b *Backend) RepoCommitHandler(
19 ctx context.Context, evt *comatproto.SyncSubscribeRepos_Commit,
20) error {
21 select {
22 case <-ctx.Done():
23 return nil
24 default:
25 //
26 }
27
28 b.firehoseLk.Lock()
29 b.firehoseSeq = strconv.Itoa(int(evt.Seq))
30 b.firehoseLk.Unlock()
31
32 return b.bf.HandleEvent(ctx, evt)
33}
34
35type handleOpCreateUpdate func(context.Context, string, string, string, *[]byte, *cid.Cid) error
36type handleOpDelete func(context.Context, string, string, string) error
37
38func (b *Backend) HandleCreateOp(ctx context.Context, repo, rev, path string, rec *[]byte, cid *cid.Cid) error {
39 if !strings.HasPrefix(path, "app.bsky.feed.generator/") {
40 return nil
41 }
42
43 sl := slog.With("source", "HandleCreateOp")
44
45 var out appbsky.FeedGenerator
46 if err := out.UnmarshalCBOR(bytes.NewReader(*rec)); err != nil {
47 sl.Error("failed to unmarshal record", "err", err)
48 return fmt.Errorf("failed to unmarshal record: %w", err)
49 }
50
51 feedgen := &FeedGenerator{
52 AtUri: fmt.Sprintf("at://%s/%s", repo, path),
53 DisplayName: out.DisplayName,
54 FeedService: out.Did,
55 CreatedAt: out.CreatedAt,
56 Description: out.Description,
57 ContentMode: out.ContentMode,
58 AcceptsInteractions: out.AcceptsInteractions,
59 }
60
61 if err := b.data.Model(&FeedGenerator{}).Create(feedgen).Error; err != nil {
62 return fmt.Errorf("error adding feedgen to database: %w", err)
63 }
64
65 return nil
66}
67
68func (b *Backend) HandleUpdateOp(ctx context.Context, repo, rev, path string, rec *[]byte, cid *cid.Cid) error {
69 return nil
70}
71
72func (b *Backend) HandleDeleteOp(ctx context.Context, repo, rev, path string) error {
73 return nil
74}