diff options
| -rw-r--r-- | backend/fetchers/app.bsky.feed.go | 7 | ||||
| -rw-r--r-- | backend/general/records.go | 28 |
2 files changed, 6 insertions, 29 deletions
diff --git a/backend/fetchers/app.bsky.feed.go b/backend/fetchers/app.bsky.feed.go index 4c6b92f..16e93c5 100644 --- a/backend/fetchers/app.bsky.feed.go +++ b/backend/fetchers/app.bsky.feed.go @@ -40,12 +40,16 @@ func FetchAppBskyFeedPosts(logger *slog.Logger, did, pdsURL, slingshotURL string func GetAppBskyFeedPostByURI(logger *slog.Logger, uri, slingshotURL string, session *auth.OAuthState, cache *Cache) (*notes.Note, error) { // check cache, return if it was cached without auth or if it was cached with auth and we have auth + logger.Debug("Getting app.bsky.feed.post", "uri", uri) if cached, found := cache.Get(uri); found { + logger.Debug("Found in the cache", "public", !cached.AuthorNoUnauth) if !cached.AuthorNoUnauth { return cached, nil } - if general.IsValidSession(session) { + // author requires auth - if we have a session, serve it + // if the token was invalid, trust that it would have been caught by the "refresh token" call in main + if session != nil { return cached, nil } } @@ -61,6 +65,7 @@ func FetchAppBskyFeedPostByURI(logger *slog.Logger, uri, slingshotURL string, se if err != nil { return nil, err } + logger.Debug("fetched origin PDS", "did", repo, "pdsURL", pdsURL) // get author of the note author, found := cache.GetProfile(repo) diff --git a/backend/general/records.go b/backend/general/records.go index ff37785..ea2b308 100644 --- a/backend/general/records.go +++ b/backend/general/records.go @@ -99,31 +99,3 @@ func FetchRawRecordByURI(logger *slog.Logger, uri, baseURL string, session *auth return &result, nil } - -func IsValidSession(session *auth.OAuthState) bool { - if session == nil { - return false - } - - url := fmt.Sprintf("%s/xrpc/com.atproto.server.getSession", session.PDS) - - dpopProof, err := session.KeyPair.GenerateDPoPProof("GET", url, "") - if err != nil { - return false - } - - req, err := http.NewRequest("GET", url, nil) - if err != nil { - return false - } - req.Header.Set("Authorization", "Bearer "+session.AccessToken) - req.Header.Set("DPoP", dpopProof) - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return false - } - defer resp.Body.Close() - - return resp.StatusCode == 200 -} |
