Skip to content

Commit

Permalink
automod: refactor out RelayClient, connect to account's PDS directly
Browse files Browse the repository at this point in the history
getRecord from Relay (BGS) wasn't working 🤷
  • Loading branch information
bnewbold committed Nov 20, 2023
1 parent 6aee771 commit 4e599db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
11 changes: 7 additions & 4 deletions automod/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,18 @@ func (e *Engine) FetchAndProcessRecord(ctx context.Context, uri string) error {
if aturi.RecordKey() == "" {
return fmt.Errorf("need a full, not partial, AT-URI: %s", uri)
}
if e.RelayClient == nil {
return fmt.Errorf("can't fetch record without relay client configured")
}
ident, err := e.Directory.Lookup(ctx, aturi.Authority())
if err != nil {
return fmt.Errorf("resolving AT-URI authority: %v", err)
}
pdsURL := ident.PDSEndpoint()
if pdsURL == "" {
return fmt.Errorf("could not resolve PDS endpoint for AT-URI account: %s", ident.DID.String())
}
pdsClient := xrpc.Client{Host: ident.PDSEndpoint()}

e.Logger.Info("fetching record", "did", ident.DID.String(), "collection", aturi.Collection().String(), "rkey", aturi.RecordKey().String())
out, err := comatproto.RepoGetRecord(ctx, e.RelayClient, "", aturi.Collection().String(), ident.DID.String(), aturi.RecordKey().String())
out, err := comatproto.RepoGetRecord(ctx, &pdsClient, "", aturi.Collection().String(), ident.DID.String(), aturi.RecordKey().String())
if err != nil {
return fmt.Errorf("fetching record from Relay (%s): %v", aturi, err)
}
Expand Down
11 changes: 0 additions & 11 deletions cmd/hepa/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,6 @@ func NewServer(dir identity.Directory, config Config) (*Server, error) {
cache = automod.NewMemCacheStore(5_000, 30*time.Minute)
}

relayURL := config.BGSHost
if strings.HasPrefix(relayURL, "ws") {
relayURL = "http" + relayURL[2:]
}
// XXX:
relayURL = "https://bsky.social"

engine := automod.Engine{
Logger: logger,
Directory: dir,
Expand All @@ -136,10 +129,6 @@ func NewServer(dir identity.Directory, config Config) (*Server, error) {
Client: util.RobustHTTPClient(),
Host: config.BskyHost,
},
RelayClient: &xrpc.Client{
Client: util.RobustHTTPClient(),
Host: relayURL,
},
}

s := &Server{
Expand Down

0 comments on commit 4e599db

Please sign in to comment.