an app.bsky.* indexer
1package main 2 3import ( 4 "bytes" 5 "context" 6 "fmt" 7 "strings" 8 9 appbsky "github.com/bluesky-social/indigo/api/bsky" 10 "github.com/ipfs/go-cid" 11 "gorm.io/gorm" 12) 13 14type HandlerService struct { 15 store *gorm.DB 16} 17 18func NewHandlerService(store *gorm.DB) *HandlerService { 19 store.AutoMigrate(&Profile{}) 20 store.AutoMigrate(&Feedgen{}) 21 // TODO the rest 22 23 return &HandlerService{ 24 store: store, 25 } 26} 27 28func (hs *HandlerService) HandleCreate(ctx context.Context, repo string, rev string, path string, rec *[]byte, cid *cid.Cid) error { 29 if !strings.HasPrefix(path, "app.bsky.feed.generator/") { 30 return nil 31 } 32 33 var out appbsky.FeedGenerator 34 if err := out.UnmarshalCBOR(bytes.NewReader(*rec)); err != nil { 35 return fmt.Errorf("error unmarshalling record: %w", err) 36 } 37 38 feedgen := Feedgen{ 39 DisplayName: out.DisplayName, 40 } 41 42 if err := hs.store.Create(&feedgen).Error; err != nil { 43 return fmt.Errorf("error saving feedgen: %w", err) 44 } 45 46 return nil 47} 48 49func (hs *HandlerService) HandleUpdate(ctx context.Context, repo string, rev string, path string, rec *[]byte, cid *cid.Cid) error { 50 return nil 51} 52 53func (hs *HandlerService) HandleDelete(ctx context.Context, repo string, rev string, path string) error { 54 return nil 55}