fix: await stream read, don't pass bare mxids

This commit is contained in:
əlemi 2024-01-29 22:26:37 +01:00
parent 091906683a
commit 1bc88cc48f
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -115,7 +115,6 @@ class AppService:
return doc["user_id"] return doc["user_id"]
async def set_avatar(self, mxid: str, avatar_url: str) -> None: async def set_avatar(self, mxid: str, avatar_url: str) -> None:
bare_mxid = fmt_mxid(mxid, full=False)
async with self._client.get(avatar_url) as res: async with self._client.get(avatar_url) as res:
res.raise_for_status() res.raise_for_status()
async with self._client.request( async with self._client.request(
@ -125,7 +124,7 @@ class AppService:
"Authorization": f"Bearer {self.as_token}", "Authorization": f"Bearer {self.as_token}",
"Content-Type": res.content_type, "Content-Type": res.content_type,
}, },
chunked=res.content.read(), chunked=await res.content.read(),
params={"filename":str(uuid.uuid4())}, params={"filename":str(uuid.uuid4())},
) as res: ) as res:
res.raise_for_status() res.raise_for_status()
@ -133,7 +132,7 @@ class AppService:
avatar_uri = doc["content_uri"] avatar_uri = doc["content_uri"]
async with self._client.request( async with self._client.request(
method="PUT", method="PUT",
url=f"{self.client_api}/profile/{bare_mxid}/avatar_url", url=f"{self.client_api}/profile/{mxid}/avatar_url",
headers=self.api_headers, headers=self.api_headers,
json={"avatar_url": avatar_uri}, json={"avatar_url": avatar_uri},
params={"user_id": mxid}, params={"user_id": mxid},
@ -142,10 +141,9 @@ class AppService:
self.logger.debug("updated avatar of %s to %s", mxid, avatar_url) self.logger.debug("updated avatar of %s to %s", mxid, avatar_url)
async def set_nick(self, mxid: str, nick: str) -> None: async def set_nick(self, mxid: str, nick: str) -> None:
bare_mxid = fmt_mxid(mxid, full=False)
async with self._client.request( async with self._client.request(
method="PUT", method="PUT",
url=f"{self.client_api}/profile/{bare_mxid}/displayname", url=f"{self.client_api}/profile/{mxid}/displayname",
headers=self.api_headers, headers=self.api_headers,
json={"displayname": nick}, json={"displayname": nick},
params={"user_id": mxid}, params={"user_id": mxid},