From 0d50215fc1f3453b4a76fe0782e97cde97d13344 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Wed, 12 Jun 2024 13:23:53 -0400 Subject: [PATCH] add missing AP routes Adds routes for "/outbox", "/following", and "/followers" --- relay/misc.py | 1 + relay/views/activitypub.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/relay/misc.py b/relay/misc.py index 729cfd7..feee97c 100644 --- a/relay/misc.py +++ b/relay/misc.py @@ -148,6 +148,7 @@ class Message(aputils.Message): 'followers': f'https://{host}/followers', 'following': f'https://{host}/following', 'inbox': f'https://{host}/inbox', + 'outbox': f'https://{host}/outbox', 'url': f'https://{host}/', 'endpoints': { 'sharedInbox': f'https://{host}/inbox' diff --git a/relay/views/activitypub.py b/relay/views/activitypub.py index f2eff48..b19b7e1 100644 --- a/relay/views/activitypub.py +++ b/relay/views/activitypub.py @@ -125,6 +125,39 @@ class ActorView(View): return None +@register_route('/outbox') +class OutboxView(View): + async def get(self, request: Request) -> Response: + msg = aputils.Message.new( + aputils.ObjectType.ORDERED_COLLECTION, + { + "id": f'https://{self.config.domain}/outbox', + "totalItems": 0, + "orderedItems": [] + } + ) + + return Response.new(msg, ctype = 'activity') + + +@register_route('/following', '/followers') +class RelationshipView(View): + async def get(self, request: Request) -> Response: + with self.database.session(False) as s: + inboxes = [row['actor'] for row in s.get_inboxes()] + + msg = aputils.Message.new( + aputils.ObjectType.COLLECTION, + { + "id": f'https://{self.config.domain}{request.path}', + "totalItems": len(inboxes), + "items": inboxes + } + ) + + return Response.new(msg, ctype = 'activity') + + @register_route('/.well-known/webfinger') class WebfingerView(View): async def get(self, request: Request) -> Response: