changeset 3843:17c757bd74bc

component AP gateway: `getAPAccountFromId` now works with local IDs: rel 370
author Goffi <goffi@goffi.org>
date Thu, 14 Jul 2022 12:55:30 +0200
parents 943901372eba
children 65e5718e7710
files sat/plugins/plugin_comp_ap_gateway/__init__.py
diffstat 1 files changed, 21 insertions(+), 0 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
@@ -1051,8 +1051,29 @@
     async def getAPAccountFromId(self, actor_id: str) -> str:
         """Retrieve AP account from the ID URL
 
+        Works with external or local actor IDs.
         @param actor_id: AP ID of the actor (URL to the actor data)
+        @return: AP handle
         """
+        if self.isLocalURL(actor_id):
+            url_type, url_args = self.parseAPURL(actor_id)
+            if url_type != "actor" or not url_args:
+                raise exceptions.DataError(
+                    f"invalid local actor ID: {actor_id}"
+                )
+            account = url_args[0]
+            try:
+                account_user, account_host = account.split('@')
+            except ValueError:
+                raise exceptions.DataError(
+                    f"invalid account from url: {actor_id}"
+                )
+            if not account_user or account_host != self.public_url:
+                raise exceptions.DataError(
+                    f"{account!r} is not a valid local account (from {actor_id})"
+                )
+            return account
+
         url_parsed = parse.urlparse(actor_id)
         actor_data = await self.getActorData(actor_id)
         username = actor_data.get("preferredUsername")