- On first start (no users in DB), show a setup page in the web UI to create the admin account instead of reading credentials from .env - New public endpoints: GET /api/setup/status, POST /api/setup - New admin endpoint: GET /api/filebrowser?path=... for directory listing - FileBrowser modal component with navigation, used in Admin > Libraries - Remove _seed_admin / _seed_default_library from server startup Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import os
|
|
from fastapi import APIRouter, Depends, HTTPException, Query
|
|
from ..dependencies import require_admin
|
|
from ..models.user import User
|
|
|
|
router = APIRouter(prefix="/api/filebrowser", tags=["filebrowser"])
|
|
|
|
|
|
@router.get("")
|
|
async def browse(
|
|
path: str = Query("/"),
|
|
_admin: User = Depends(require_admin),
|
|
):
|
|
path = os.path.normpath(path)
|
|
if not os.path.isdir(path):
|
|
raise HTTPException(status_code=404, detail="Pfad nicht gefunden")
|
|
|
|
try:
|
|
names = sorted(os.listdir(path), key=lambda n: n.lower())
|
|
except PermissionError:
|
|
raise HTTPException(status_code=403, detail="Zugriff verweigert")
|
|
|
|
entries = []
|
|
for name in names:
|
|
if name.startswith("."):
|
|
continue
|
|
full = os.path.join(path, name)
|
|
try:
|
|
is_dir = os.path.isdir(full)
|
|
except OSError:
|
|
continue
|
|
entries.append({"name": name, "path": full, "isDir": is_dir})
|
|
|
|
parent_path = os.path.dirname(path)
|
|
parent = parent_path if parent_path != path else None
|
|
|
|
return {"path": path, "parent": parent, "entries": entries}
|