From 37e00a3ee1db1c9dd8eee60bf8aa40b55f9fe08b Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Wed, 25 Sep 2024 11:43:41 +0200 Subject: [PATCH] DMED-119 - use synchronous requests for setting node --- converter/es_connector.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/converter/es_connector.py b/converter/es_connector.py index b2b251da..3a6c86ee 100644 --- a/converter/es_connector.py +++ b/converter/es_connector.py @@ -224,20 +224,16 @@ async def set_node_binary_data(self, uuid, item) -> bool: else: return False - async def set_node_preview(self, uuid, item) -> bool: + def set_node_preview(self, uuid, item) -> bool: if "thumbnail" in item: key = "large" if "large" in item["thumbnail"] else "small" if "small" in item["thumbnail"] else None if key: files = {"image": base64.b64decode(item["thumbnail"][key])} - response = await self._client_async.post( - get_project_settings().get("EDU_SHARING_BASE_URL") - + "rest/node/v1/nodes/-home-/" - + uuid - + "/preview?mimetype=" - + item["thumbnail"]["mimetype"], - headers=self.get_headers(None), - files=files, - timeout=None, + response = requests.post( + url=f"{get_project_settings().get('EDU_SHARING_BASE_URL')}" + f"rest/node/v1/nodes/-home-/{uuid}" + f"/content?mimetype={item['thumbnail']['mimetype']}", + data=files ) return response.status_code == 200 else: @@ -759,7 +755,7 @@ async def insert_item(self, spider, uuid, item): # temporary burst of items that need to be inserted node = self.sync_node(spider, "ccm:io", self.transform_item(uuid, spider, item)) self.set_node_permissions(node["ref"]["id"], item) - await self.set_node_preview(node["ref"]["id"], item) + self.set_node_preview(node["ref"]["id"], item) if not await self.set_node_binary_data(node["ref"]["id"], item): await self.set_node_text(node["ref"]["id"], item)