add(core): open filesystem while adding library path

This commit is contained in:
Steppenstreuner
2026-08-28 13:21:32 +02:00
parent 3b617a910a
commit 262700ee45
4 changed files with 196 additions and 109 deletions
+28
View File
@@ -0,0 +1,28 @@
from pathlib import Path
from fastapi import APIRouter
router = APIRouter(prefix="/api/fs", tags=["fs"])
@router.get("/browse")
def browse(path: str = "/"):
"""List subdirectories for path autocompletion in the library form.
If `path` ends with '/', its children are listed; otherwise the children
of the parent that match the typed last segment.
"""
p = Path(path)
if path.endswith("/"):
base, prefix = p, ""
else:
base, prefix = p.parent, p.name.lower()
try:
dirs = sorted(
str(d) for d in base.iterdir()
if d.is_dir() and not d.name.startswith(".")
and d.name.lower().startswith(prefix)
)
except OSError:
dirs = []
return {"dirs": dirs[:50]}