# HG changeset patch # User Goffi # Date 1657796130 -7200 # Node ID 17c757bd74bc6b43ab707d143e8313d976f33c76 # Parent 943901372eba70c7b0a65d135a34838923b9bee8 component AP gateway: `getAPAccountFromId` now works with local IDs: rel 370 diff -r 943901372eba -r 17c757bd74bc sat/plugins/plugin_comp_ap_gateway/__init__.py --- 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")