aboutsummaryrefslogtreecommitdiff
path: root/backend/fetchers/app.bsky.feed.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/fetchers/app.bsky.feed.go')
-rw-r--r--backend/fetchers/app.bsky.feed.go31
1 files changed, 21 insertions, 10 deletions
diff --git a/backend/fetchers/app.bsky.feed.go b/backend/fetchers/app.bsky.feed.go
index 10c08e7..2a38d5a 100644
--- a/backend/fetchers/app.bsky.feed.go
+++ b/backend/fetchers/app.bsky.feed.go
@@ -3,17 +3,18 @@ package fetchers
import (
"encoding/json"
"fmt"
+ "llostre/backend/auth"
"llostre/backend/general"
"llostre/backend/notes"
"log/slog"
)
-func FetchAppBskyFeedPosts(logger *slog.Logger, did, pdsURL, slingshotURL string, cache *Cache) ([]notes.Note, error) {
+func FetchAppBskyFeedPosts(logger *slog.Logger, did, pdsURL, slingshotURL string, session *auth.OAuthState, cache *Cache) ([]notes.Note, error) {
// get author of the note
author, found := cache.GetProfile(did)
var err error
if !found {
- author, err = FetchAppBskyActorProfile(logger, did, pdsURL, slingshotURL, cache)
+ author, err = FetchAppBskyActorProfile(logger, did, pdsURL, slingshotURL, session, cache)
}
if err != nil {
return nil, err
@@ -21,7 +22,7 @@ func FetchAppBskyFeedPosts(logger *slog.Logger, did, pdsURL, slingshotURL string
// try slingshot first if given
if slingshotURL != "" {
- records, err := general.FetchRawRecordCollection(logger, did, "app.bsky.feed.post", slingshotURL)
+ records, err := general.FetchRawRecordCollection(logger, did, "app.bsky.feed.post", slingshotURL, session)
if err != nil {
logger.Error("Fetching from slingshot failed")
} else {
@@ -29,7 +30,7 @@ func FetchAppBskyFeedPosts(logger *slog.Logger, did, pdsURL, slingshotURL string
}
}
- records, err := general.FetchRawRecordCollection(logger, did, "app.bsky.feed.post", pdsURL)
+ records, err := general.FetchRawRecordCollection(logger, did, "app.bsky.feed.post", pdsURL, session)
if err != nil {
return nil, err
}
@@ -37,12 +38,22 @@ func FetchAppBskyFeedPosts(logger *slog.Logger, did, pdsURL, slingshotURL string
return parseAppBskyFeedPostCollection(logger, records, author, cache)
}
-func FetchAppBskyFeedPostByURI(logger *slog.Logger, uri, slingshotURL string, cache *Cache) (*notes.Note, error) {
- // check cache
+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
if cached, found := cache.Get(uri); found {
- return cached, nil
+ if !cached.AuthorNoUnauth {
+ return cached, nil
+ }
+
+ if general.IsValidSession(session) {
+ return cached, nil
+ }
}
+ return FetchAppBskyFeedPostByURI(logger, uri, slingshotURL, session, cache)
+}
+
+func FetchAppBskyFeedPostByURI(logger *slog.Logger, uri, slingshotURL string, session *auth.OAuthState, cache *Cache) (*notes.Note, error) {
repo, _, _, err := general.ParseURI(uri)
// need to resolve DID to PDS
@@ -54,7 +65,7 @@ func FetchAppBskyFeedPostByURI(logger *slog.Logger, uri, slingshotURL string, ca
// get author of the note
author, found := cache.GetProfile(repo)
if !found {
- author, err = FetchAppBskyActorProfile(logger, repo, pdsURL, slingshotURL, cache)
+ author, err = FetchAppBskyActorProfile(logger, repo, pdsURL, slingshotURL, session, cache)
}
if err != nil {
return nil, err
@@ -62,7 +73,7 @@ func FetchAppBskyFeedPostByURI(logger *slog.Logger, uri, slingshotURL string, ca
// try slingshot first if given
if slingshotURL != "" {
- rawRecord, err := general.FetchRawRecordByURI(logger, uri, slingshotURL)
+ rawRecord, err := general.FetchRawRecordByURI(logger, uri, slingshotURL, session)
if err != nil {
logger.Error("fetching from slingshot failed", "error", err)
} else {
@@ -70,7 +81,7 @@ func FetchAppBskyFeedPostByURI(logger *slog.Logger, uri, slingshotURL string, ca
}
}
- rawRecord, err := general.FetchRawRecordByURI(logger, uri, pdsURL)
+ rawRecord, err := general.FetchRawRecordByURI(logger, uri, pdsURL, session)
if err != nil {
logger.Error("Fetching from PDS failed")
return nil, err