Thumb pagination
This commit is contained in:
parent
f033d9ea8c
commit
72ace3dc09
12
tools.py
12
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": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user