Upload files to "backend/routes"

This commit is contained in:
Thierry 2026-03-26 11:43:20 +01:00
parent eb5fb040c9
commit 93e92c5ff5
3 changed files with 162 additions and 0 deletions

92
backend/routes/admin.py Normal file
View file

@ -0,0 +1,92 @@
from fastapi import APIRouter, HTTPException
from fastapi.responses import JSONResponse
from config import EPT_DIR, UPLOADS_DIR
from services.manifest import read_manifest
from services.converter import ENTWINE_AVAILABLE, ENTWINE_PATH
import shutil
router = APIRouter()
@router.get("/list")
def list_pointclouds():
pointclouds = []
for item in sorted(EPT_DIR.iterdir(), key=lambda x: x.stat().st_ctime, reverse=True):
if item.is_dir():
manifest = read_manifest(item)
total_size = 0
file_count = 0
for f in item.rglob("*"):
if f.is_file():
total_size += f.stat().st_size
file_count += 1
if file_count > 0:
pointclouds.append({
"id": item.name,
"size_mb": round(total_size / (1024 * 1024), 2),
"file_count": file_count,
"manifest": manifest,
"created": item.stat().st_ctime,
})
return {"pointclouds": pointclouds}
@router.get("/debug/{pc_id}")
def debug(pc_id: str):
out_dir = EPT_DIR / pc_id
if not out_dir.exists():
raise HTTPException(status_code=404, detail=f"ID {pc_id} non trouvé")
manifest = read_manifest(out_dir)
files = []
total_size = 0
for p in out_dir.rglob("*"):
if p.is_file():
size = p.stat().st_size
total_size += size
files.append({
"path": str(p.relative_to(out_dir)),
"size_mb": round(size / (1024 * 1024), 2),
})
entry_file = manifest.get("entry_file")
entry_exists = False
if entry_file:
entry_exists = (EPT_DIR / entry_file).exists()
return {
"pc_id": pc_id,
"exists": True,
"manifest": manifest,
"entry_exists": entry_exists,
"stats": {
"total_files": len(files),
"total_size_mb": round(total_size / (1024 * 1024), 2),
},
"files": sorted(files, key=lambda x: x["size_mb"], reverse=True)[:20],
"entwine_available": ENTWINE_AVAILABLE,
"entwine_path": ENTWINE_PATH,
}
@router.delete("/delete/{pc_id}")
def delete_pointcloud(pc_id: str):
out_dir = EPT_DIR / pc_id
if not out_dir.exists():
raise HTTPException(status_code=404, detail=f"ID {pc_id} non trouvé")
try:
for ext in [".las", ".laz", ".ply", ".xyz", ".pts"]:
original = UPLOADS_DIR / f"{pc_id}{ext}"
if original.exists():
original.unlink()
shutil.rmtree(out_dir)
return {"ok": True, "message": f"Nuage {pc_id} supprimé"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"Erreur suppression : {str(e)}")