From f91f0d229aadf0b8e5bfa9d7b8e95b7055f0bc74 Mon Sep 17 00:00:00 2001 From: MrRaph_ Date: Tue, 3 Dec 2024 14:21:18 +0100 Subject: [PATCH] feat: ajout du lien dans la liste --- hoarder.py | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/hoarder.py b/hoarder.py index 0954bc8..d4924f7 100644 --- a/hoarder.py +++ b/hoarder.py @@ -78,25 +78,16 @@ class HoarderForwarder(Plugin): hoarder_url = self.config["hoarder_url"] api_key = self.config["hoarder_api_key"] - create_endpoint = f"{hoarder_url}/api/trpc/bookmarks.createBookmark" + create_endpoint = f"{hoarder_url}/api/v1/bookmarks" - self.log.info(hoarder_url) - #title = await self.get_page_title(url) # Récupère le titre de la page - - if not hoarder_url or not api_key: - self.log.warning("L'URL ou la clé API de Hoarder n'est pas configurée.") - return - headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json", "Accept": "application/json", } payload = { - "json": { - "type": "link", - "url": url - } + "type": "link", + "url": url } try: @@ -104,9 +95,9 @@ class HoarderForwarder(Plugin): async with session.post(create_endpoint, json=payload, headers=headers) as response: if response.status == 200 or response.status == 201 or response.status == 204: data = await response.json() - bookmark_id = data[0]["result"]["data"]["json"]["id"] + bookmark_id = data["id"] await self.send_message(evt, f"Bookmark créé avec succès : {bookmark_id}", in_thread=False) - self.add_bookmark_to_list(bookmark_id, hoarder_list) + await self.add_bookmark_to_list(evt, bookmark_id) return bookmark_id else: await self.send_message(evt, f"Erreur lors de la création du bookmark : {response.status}", in_thread=False) @@ -202,18 +193,14 @@ class HoarderForwarder(Plugin): api_key = self.config["hoarder_api_key"] list_id = await self.ensure_list_exists(evt, self.config["hoarder_list_name"]) - add_to_list_endpoint = f"{hoarder_url}/api/v1/lists/{list_id}/bookmarks" + add_to_list_endpoint = f"{hoarder_url}/api/v1/lists/{list_id}/bookmarks/{bookmark_id}" headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json", "Accept": "application/json", } - - payload = { - "bookmarkId": bookmark_id - } - + try: async with aiohttp.ClientSession() as session: async with session.put(add_to_list_endpoint, headers=headers) as response: