v3
> it looks like the GET /bookmarks/labels/{name} returns a JSON data that includes a "href_bookmarks" key that has the value of a URI endpoint that needs to be called to actually get all the bookmarks of a label v3 > it looks like the GET /bookmarks/labels/{name} returns a JSON data that includes a "href_bookmarks" key that has the value of a URI endpoint that needs to be called to actually get all the bookmarks of a label
This commit is contained in:
parent
6b537ae76a
commit
bd55899a1e
1 changed files with 35 additions and 8 deletions
41
main.py
41
main.py
|
@ -326,21 +326,43 @@ class Tools:
|
|||
if not label_name:
|
||||
return "Error: label_name is required."
|
||||
|
||||
# Build query parameters
|
||||
# First, get the label metadata to retrieve the href_bookmarks URI
|
||||
label_result = self._make_request(f"/bookmarks/labels/{label_name}")
|
||||
|
||||
if "error" in label_result:
|
||||
return f"Error fetching label '{label_name}': {label_result['error']}"
|
||||
|
||||
# Extract the href_bookmarks URI
|
||||
href_bookmarks = label_result.get("href_bookmarks")
|
||||
if not href_bookmarks:
|
||||
return f"No href_bookmarks found for label '{label_name}'. Label may not exist or have no bookmarks."
|
||||
|
||||
# Build query parameters for the bookmarks request
|
||||
params = {
|
||||
"limit": min(limit, 100), # Cap at 100 to prevent excessive requests
|
||||
"offset": offset
|
||||
}
|
||||
|
||||
# Make request to Readeck API
|
||||
result = self._make_request(f"/bookmarks/labels/{label_name}", params)
|
||||
# Extract the endpoint path from href_bookmarks (remove the base URL if present)
|
||||
if href_bookmarks.startswith(self.valves.readeck_url):
|
||||
endpoint_path = href_bookmarks[len(self.valves.readeck_url):]
|
||||
if endpoint_path.startswith("/api"):
|
||||
endpoint_path = endpoint_path[4:] # Remove /api prefix
|
||||
else:
|
||||
# Assume it's a relative path
|
||||
endpoint_path = href_bookmarks
|
||||
if endpoint_path.startswith("/api"):
|
||||
endpoint_path = endpoint_path[4:] # Remove /api prefix
|
||||
|
||||
if "error" in result:
|
||||
return f"Error fetching bookmarks for label '{label_name}': {result['error']}"
|
||||
# Make request to get the actual bookmarks
|
||||
bookmarks_result = self._make_request(endpoint_path, params)
|
||||
|
||||
if "error" in bookmarks_result:
|
||||
return f"Error fetching bookmarks for label '{label_name}': {bookmarks_result['error']}"
|
||||
|
||||
# Format the response
|
||||
bookmarks = result.get("bookmarks", [])
|
||||
total = result.get("total", len(bookmarks))
|
||||
bookmarks = bookmarks_result.get("bookmarks", [])
|
||||
total = bookmarks_result.get("total", len(bookmarks))
|
||||
|
||||
if not bookmarks:
|
||||
return f"No bookmarks found with label '{label_name}'."
|
||||
|
@ -363,6 +385,11 @@ class Tools:
|
|||
|
||||
return json.dumps({
|
||||
"label": label_name,
|
||||
"label_info": {
|
||||
"name": label_result.get("name"),
|
||||
"bookmark_count": label_result.get("bookmark_count"),
|
||||
"href_bookmarks": href_bookmarks
|
||||
},
|
||||
"bookmarks": formatted_bookmarks,
|
||||
"total": total,
|
||||
"limit": params["limit"],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue