This commit is contained in:
Timothy Jaeryang Baek committed 2026-02-19 14:41:05 -06:00
1 parent c51cffb590
commit 13bcd6ab46
1 file changed
+24 -16
+24 -16
View File
@@ -316,28 +316,36 @@ async def health():
)
async def list_files(
directory: str = Query(".", description="Directory path to list."),
max_entries: int = Query(500, description="Maximum entries to return.", ge=1, le=5000),
):
target = os.path.abspath(directory)
if not os.path.isdir(target):
raise HTTPException(status_code=404, detail="Directory not found")
entries = []
for name in sorted(os.listdir(target)):
full_path = os.path.join(target, name)
try:
file_stat = os.stat(full_path)
entries.append(
{
"name": name,
"type": "directory" if os.path.isdir(full_path) else "file",
"size": file_stat.st_size,
"modified": file_stat.st_mtime,
}
)
except OSError:
continue
def _list_sync():
entries = []
truncated = False
for name in sorted(os.listdir(target)):
if len(entries) >= max_entries:
truncated = True
break
full_path = os.path.join(target, name)
try:
file_stat = os.stat(full_path)
entries.append(
{
"name": name,
"type": "directory" if os.path.isdir(full_path) else "file",
"size": file_stat.st_size,
"modified": file_stat.st_mtime,
}
)
except OSError:
continue
return entries, truncated
return {"dir": target, "entries": entries}
entries, truncated = await asyncio.to_thread(_list_sync)
return {"dir": target, "entries": entries, "truncated": truncated}
@app.get(