48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
from fastapi import APIRouter, HTTPException, Query
|
|
|
|
from app.services.file_discovery_service import FileDiscoveryService
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/roots")
|
|
def get_roots():
|
|
service = FileDiscoveryService()
|
|
return {"items": service.list_roots()}
|
|
|
|
|
|
@router.get("/discover")
|
|
def discover_files(
|
|
root_id: str = Query(..., min_length=1),
|
|
subpath: str = Query(""),
|
|
recursive: bool = Query(False),
|
|
limit: int = Query(200, ge=1, le=1000),
|
|
):
|
|
service = FileDiscoveryService()
|
|
try:
|
|
return service.discover(
|
|
root_id=root_id,
|
|
subpath=subpath,
|
|
recursive=recursive,
|
|
limit=limit,
|
|
)
|
|
except ValueError as exc:
|
|
raise HTTPException(status_code=400, detail=str(exc))
|
|
|
|
|
|
@router.get("/folders")
|
|
def discover_folders(
|
|
root_id: str = Query(..., min_length=1),
|
|
subpath: str = Query(""),
|
|
limit: int = Query(5000, ge=1, le=20000),
|
|
):
|
|
service = FileDiscoveryService()
|
|
try:
|
|
return service.list_folders(
|
|
root_id=root_id,
|
|
subpath=subpath,
|
|
limit=limit,
|
|
)
|
|
except ValueError as exc:
|
|
raise HTTPException(status_code=400, detail=str(exc))
|