an app.bsky.* indexer
1package main
2
3import (
4 "context"
5 "fmt"
6
7 "github.com/bluesky-social/indigo/atproto/syntax"
8
9 "github.com/ipfs/go-cid"
10 "gorm.io/gorm"
11)
12
13type HandlerService struct {
14 store *gorm.DB
15}
16
17func NewHandlerService(store *gorm.DB) *HandlerService {
18 store.AutoMigrate(&Account{})
19 store.AutoMigrate(&Profile{})
20 store.AutoMigrate(&List{})
21 store.AutoMigrate(&Labeler{})
22 store.AutoMigrate(&FeedGenerator{})
23 store.AutoMigrate(&Post{})
24 store.AutoMigrate(&Like{})
25 store.AutoMigrate(&StarterPack{})
26 store.AutoMigrate(&Verification{})
27 store.AutoMigrate(&Lexicon{})
28
29 return &HandlerService{
30 store: store,
31 }
32}
33
34// handles both creates and updates
35func (hs *HandlerService) HandleUpsert(ctx context.Context, repo string, rev string, path string, rec *[]byte, cid *cid.Cid) error {
36 uri, err := syntax.ParseATURI(fmt.Sprintf("at://%s/%s", repo, path))
37 if err != nil {
38 return err
39 }
40
41 switch uri.Collection() {
42 case syntax.NSID("app.bsky.actor.profile"):
43 profile := NewProfile(*rec)
44 profile.AtUri = string(uri)
45 hs.store.Create(profile)
46
47 case syntax.NSID("app.bsky.feed.generator"):
48 feedgen := NewFeedGenerator(*rec)
49 feedgen.AtUri = string(uri)
50 hs.store.Create(feedgen)
51 }
52
53 return nil
54}
55
56func (hs *HandlerService) HandleDelete(ctx context.Context, repo string, rev string, path string) error {
57 return nil
58}