fixes 404 for own private profile

This commit is contained in:
Christian Beutel
2025-06-24 15:15:35 +02:00
parent 8e3eea6216
commit cb4f4f8125
2 changed files with 15 additions and 6 deletions

View File

@@ -122,6 +122,7 @@ func assembleActor(dbActor *core.Record, app core.App, includeFollows bool) (*co
return nil, fmt.Errorf("ORIGIN environment variable not set")
}
private := false
if dbActor.GetBool("isLocal") {
user, err := app.FindRecordById("users", dbActor.GetString("user"))
if err != nil {
@@ -153,11 +154,7 @@ func assembleActor(dbActor *core.Record, app core.App, includeFollows bool) (*co
result := make(map[string]interface{})
json.Unmarshal([]byte(privacy), &result)
private := result["account"] == "private"
if private {
return nil, fmt.Errorf("profile is private")
}
private = result["account"] == "private"
} else {
@@ -219,6 +216,10 @@ func assembleActor(dbActor *core.Record, app core.App, includeFollows bool) (*co
return nil, err
}
if private {
return dbActor, fmt.Errorf("profile is private")
}
return dbActor, nil
}

View File

@@ -1050,11 +1050,19 @@ func registerRoutes(se *core.ServeEvent, client meilisearch.ServiceManager) {
actor, err = federation.GetActorByIRI(e.App, iri, follows)
}
if err != nil && actor == nil {
if strings.HasPrefix(err.Error(), "webfinger") || err.Error() == "profile is private" {
if strings.HasPrefix(err.Error(), "webfinger") {
return e.NotFoundError("Not found", err)
}
return err
} else if err != nil && actor != nil {
if err.Error() == "profile is private" {
// this is our own profile
if 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"})
}
}
// we could not fetch the remote actor so we return our local cached copy
return e.JSON(http.StatusOK, map[string]any{"actor": actor, "error": err.Error()})
}