changeset 3846:cc13efdd8360

component AP gateway: return item when `item` URL is used: a request on an `item` type URL will return the suitable cached item. rel 370
author Goffi <goffi@goffi.org>
date Thu, 14 Jul 2022 12:55:30 +0200 (2022-07-14)
parents 4f9d4650eab5
children aaa4e7815ba8
files sat/plugins/plugin_comp_ap_gateway/__init__.py sat/plugins/plugin_comp_ap_gateway/constants.py sat/plugins/plugin_comp_ap_gateway/http_server.py
diffstat 3 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_comp_ap_gateway/__init__.py	Thu Jul 14 12:55:30 2022 +0200
+++ b/sat/plugins/plugin_comp_ap_gateway/__init__.py	Thu Jul 14 12:55:30 2022 +0200
@@ -70,6 +70,7 @@
     TYPE_FOLLOWERS,
     TYPE_TOMBSTONE,
     TYPE_MENTION,
+    NS_AP,
     NS_AP_PUBLIC,
     PUBLIC_TUPLE
 )
@@ -822,7 +823,7 @@
         if activity_id is None:
             activity_id = f"{actor_id}#{activity.lower()}_{shortuuid.uuid()}"
         data: Dict[str, Any] = {
-            "@context": "https://www.w3.org/ns/activitystreams",
+            "@context": NS_AP,
             "actor": actor_id,
             "id": activity_id,
             "type": activity,
--- a/sat/plugins/plugin_comp_ap_gateway/constants.py	Thu Jul 14 12:55:30 2022 +0200
+++ b/sat/plugins/plugin_comp_ap_gateway/constants.py	Thu Jul 14 12:55:30 2022 +0200
@@ -30,7 +30,8 @@
 TYPE_TOMBSTONE = "Tombstone"
 TYPE_MENTION = "Mention"
 MEDIA_TYPE_AP = "application/activity+json"
-NS_AP_PUBLIC = "https://www.w3.org/ns/activitystreams#Public"
+NS_AP = "https://www.w3.org/ns/activitystreams"
+NS_AP_PUBLIC = f"{NS_AP}#Public"
 # 3 values can be used, see https://www.w3.org/TR/activitypub/#public-addressing
 PUBLIC_TUPLE = (NS_AP_PUBLIC, "as:Public", "Public")
 AP_REQUEST_TYPES = {
--- a/sat/plugins/plugin_comp_ap_gateway/http_server.py	Thu Jul 14 12:55:30 2022 +0200
+++ b/sat/plugins/plugin_comp_ap_gateway/http_server.py	Thu Jul 14 12:55:30 2022 +0200
@@ -39,7 +39,7 @@
 from sat.memory.sqla_mapping import SubscriptionState
 
 from .constants import (
-    CONTENT_TYPE_AP, TYPE_ACTOR, TYPE_INBOX, TYPE_SHARED_INBOX, TYPE_OUTBOX,
+    NS_AP, CONTENT_TYPE_AP, TYPE_ACTOR, TYPE_INBOX, TYPE_SHARED_INBOX, TYPE_OUTBOX,
     AP_REQUEST_TYPES, PAGE_SIZE, ACTIVITY_TYPES_LOWER, ACTIVIY_NO_ACCOUNT_ALLOWED,
     SIGN_HEADERS, HS2019, SIGN_EXP, TYPE_FOLLOWERS, TYPE_FOLLOWING
 )
@@ -706,6 +706,9 @@
             avatar_filename = extra_args[0]
             avatar_path = self.apg.host.common_cache.getPath(avatar_filename)
             return static.File(str(avatar_path)).render(request)
+        elif request_type == "item":
+            ret_data = await self.apg.apGetLocalObject(ap_url)
+            ret_data["@context"] = NS_AP
         else:
             if len(extra_args) > 1:
                 log.warning(f"unexpected extra arguments: {extra_args!r}")