From 72ace3dc09b3771d7141cce6aa26a9a5bfb1cf9f Mon Sep 17 00:00:00 2001 From: moosecrap Date: Tue, 21 Jul 2026 04:36:16 -0700 Subject: [PATCH] Thumb pagination --- tools.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools.py b/tools.py index cd87b88..5a769df 100644 --- a/tools.py +++ b/tools.py @@ -166,6 +166,9 @@ async def list_thumbnails_handler(args: Dict[str, Any]): x = padding + col * (thumb_size + padding) y = padding + row * (thumb_size + label_height + padding) + # Continuous numbering across pages + global_index = start_idx + i + 1 + try: with Image.open(full_path) as img: width, height = img.size @@ -176,15 +179,15 @@ async def list_thumbnails_handler(args: Dict[str, Any]): mod_time_rel = format_relative_time(info["mtime"]) size_kb = info["size"] / 1024 - file_details.append(f"{i+1}. {filename} | {width}x{height} | {size_kb:.1f}KB | {mod_time_rel}") + file_details.append(f"{global_index}. {filename} | {width}x{height} | {size_kb:.1f}KB | {mod_time_rel}") - text = str(i + 1) + text = str(global_index) draw.text((x + 2, y + thumb_size + 2), text, fill=(255, 255, 255), font=font) except Exception as e: logger.error(f"Failed to process {filename}: {e}") draw.text((x, y + thumb_size // 2), "Error", fill=(255, 0, 0), font=font) - file_details.append(f"{i+1}. {filename} | ERROR") + file_details.append(f"{global_index}. {filename} | ERROR") buf = io.BytesIO() canvas.save(buf, format='PNG') @@ -244,7 +247,6 @@ async def list_directory_details_handler(args: Dict[str, Any]): except Exception as e: logger.error(f"Could not stat {entry}: {e}") - # Sort: Directories first, then files, then alphabetical all_items.sort(key=lambda x: (x["type"] == "file", x["name"].lower())) total_items = len(all_items) @@ -305,7 +307,7 @@ TOOL_REGISTRY = [ ), Tool( name="list_directory", - description="Lists the contents of a directory in a Nemo-like format. Directories first, then files. Supports pagination.", + description="Lists the contents of a directory in a file browser format. Directories first, then files. Supports pagination.", schema={ "type": "object", "properties": {