* feat(ap): add support for shared inboxes to reduce outbound load * feat(db): refactor ap followers db into followers repository * fix(ap): use the updated activity library to pull out the shared inbox endpoint * chore(deps): point at updated build of owncast/activity * fix(ap): typeless endpoints * feat(test): update ActivityPub test to support shared inboxes * chore(test): remove unused variable * fix: feedback from review. Guard against SSRF/non-HTTPS/local and handle transaction errors
60 lines
1.9 KiB
Go
60 lines
1.9 KiB
Go
package resolvers
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/go-fed/activity/streams/vocab"
|
|
"github.com/owncast/owncast/activitypub/apmodels"
|
|
"github.com/pkg/errors"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func getPersonFromFollow(activity vocab.ActivityStreamsFollow) (apmodels.ActivityPubActor, error) {
|
|
return GetResolvedActorFromActorProperty(activity.GetActivityStreamsActor())
|
|
}
|
|
|
|
// MakeFollowRequest will convert an inbound Follow request to our internal actor model.
|
|
func MakeFollowRequest(c context.Context, activity vocab.ActivityStreamsFollow) (*apmodels.ActivityPubActor, error) {
|
|
person, err := getPersonFromFollow(activity)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "unable to resolve person from follow request")
|
|
}
|
|
|
|
hostname := person.ActorIriHostname()
|
|
username := person.Username
|
|
fullUsername := fmt.Sprintf("%s@%s", username, hostname)
|
|
|
|
followRequest := apmodels.ActivityPubActor{
|
|
ActorIri: person.ActorIri,
|
|
FollowRequestIri: activity.GetJSONLDId().Get(),
|
|
Inbox: person.Inbox,
|
|
SharedInbox: person.SharedInbox,
|
|
Name: person.Name,
|
|
Username: fullUsername,
|
|
Image: person.Image,
|
|
RequestObject: activity,
|
|
}
|
|
|
|
return &followRequest, nil
|
|
}
|
|
|
|
// MakeUnFollowRequest will convert an inbound Unfollow request to our internal actor model.
|
|
func MakeUnFollowRequest(c context.Context, activity vocab.ActivityStreamsUndo) *apmodels.ActivityPubActor {
|
|
person, err := GetResolvedActorFromActorProperty(activity.GetActivityStreamsActor())
|
|
if err != nil {
|
|
log.Errorln("unable to resolve person from actor iri", person.ActorIri, err)
|
|
return nil
|
|
}
|
|
|
|
unfollowRequest := apmodels.ActivityPubActor{
|
|
ActorIri: person.ActorIri,
|
|
FollowRequestIri: activity.GetJSONLDId().Get(),
|
|
Inbox: person.Inbox,
|
|
Name: person.Name,
|
|
Image: person.Image,
|
|
}
|
|
|
|
return &unfollowRequest
|
|
}
|