fixes private profile issues

This commit is contained in:
Christian Beutel
2025-06-26 21:19:53 +02:00
parent 65c04781cc
commit 277b435c65
10 changed files with 54 additions and 24 deletions

View File

@@ -247,8 +247,9 @@ func fetchRemoteActor(actor *core.Record, iri string, includeFollows bool) (*pub
req.Header.Add(k, v)
}
dbPrivateKey := actor.GetString("private_key")
if dbPrivateKey != "" {
if actor != nil && actor.GetString("private_key") != "" {
dbPrivateKey := actor.GetString("private_key")
algs := []httpsig.Algorithm{httpsig.RSA_SHA256}
postHeaders := []string{"(request-target)", "Date", "Digest", "Content-Type", "Host"}
expiresIn := 60
@@ -311,7 +312,6 @@ func FetchCollection(actor *core.Record, url string) (*pub.OrderedCollection, er
if len(encryptionKey) == 0 {
return nil, fmt.Errorf("POCKETBASE_ENCRYPTION_KEY not set")
}
req, _ := http.NewRequest("GET", url, nil)
headers := map[string]string{
@@ -354,9 +354,15 @@ func FetchCollection(actor *core.Record, url string) (*pub.OrderedCollection, er
}
resp, err := http.DefaultClient.Do(req)
if err != nil || resp.StatusCode != http.StatusOK {
if err != nil {
return nil, fmt.Errorf("collection fetch failed for %s: %v", url, err)
}
if resp.StatusCode != http.StatusOK {
if resp.StatusCode == http.StatusNotFound {
return nil, fmt.Errorf("profile is private")
}
return nil, fmt.Errorf("collection fetch %s returned: %v", url, resp.StatusCode)
}
defer resp.Body.Close()
var collection pub.OrderedCollection

View File

@@ -1069,9 +1069,13 @@ func registerRoutes(se *core.ServeEvent, client meilisearch.ServiceManager) {
iri := e.Request.URL.Query().Get("iri")
follows := e.Request.URL.Query().Get("follows") == "true"
userActor, err := e.App.FindFirstRecordByData("activitypub_actors", "user", e.Auth.Id)
if err != nil {
return err
var userActor *core.Record
var err error
if e.Auth != nil {
userActor, err = e.App.FindFirstRecordByData("activitypub_actors", "user", e.Auth.Id)
if err != nil {
return err
}
}
var actor *core.Record
@@ -1088,7 +1092,7 @@ func registerRoutes(se *core.ServeEvent, client meilisearch.ServiceManager) {
} else if err != nil && actor != nil {
if err.Error() == "profile is private" {
// this is our own profile
if actor.GetString("user") == e.Auth.Id {
if e.Auth != nil && actor.GetString("user") == e.Auth.Id {
return e.JSON(http.StatusOK, map[string]any{"actor": actor, "error": nil})
} else {
return e.JSON(http.StatusNotFound, map[string]any{"error": "profile is private"})
@@ -1119,9 +1123,12 @@ func registerRoutes(se *core.ServeEvent, client meilisearch.ServiceManager) {
return err
}
userActor, err := e.App.FindFirstRecordByData("activitypub_actors", "user", e.Auth.Id)
if err != nil {
return err
var userActor *core.Record
if e.Auth != nil {
userActor, err = e.App.FindFirstRecordByData("activitypub_actors", "user", e.Auth.Id)
if err != nil {
return err
}
}
url := actor.GetString(followType)
@@ -1131,6 +1138,9 @@ func registerRoutes(se *core.ServeEvent, client meilisearch.ServiceManager) {
}
collection, err := federation.FetchCollection(userActor, fmt.Sprintf("%s?page=%d", url, intPage))
if err != nil {
if err.Error() == "profile is private" {
return e.JSON(http.StatusNotFound, map[string]any{"error": "profile is private"})
}
return err
}
return e.JSON(http.StatusOK, collection)