94 lines
No EOL
3.1 KiB
Python
94 lines
No EOL
3.1 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.responses import HTMLResponse, RedirectResponse
|
|
from config import EPT_DIR
|
|
from routes import upload, viewer, admin
|
|
from utils.disk import get_disk_usage, get_entwine_path
|
|
import subprocess
|
|
|
|
ENTWINE_PATH = get_entwine_path()
|
|
|
|
app = FastAPI(title="PointCloud Backend")
|
|
app.mount("/ept_data", StaticFiles(directory=str(EPT_DIR)), name="ept_data")
|
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
app.mount("/potree", StaticFiles(directory="static/potree"), name="potree")
|
|
|
|
# ── Fichiers Potree dans /static ─────────────────────────────────────────────
|
|
app.mount("/static/potree", StaticFiles(directory="static/potree"), name="static_potree")
|
|
|
|
app.include_router(upload.router)
|
|
app.include_router(viewer.router)
|
|
app.include_router(admin.router)
|
|
|
|
@app.get("/api")
|
|
def home():
|
|
return RedirectResponse(url="/docs")
|
|
|
|
@app.get("/health")
|
|
def health():
|
|
return {
|
|
"ok": True,
|
|
"entwine_available": ENTWINE_PATH is not None,
|
|
"entwine_path": ENTWINE_PATH,
|
|
"disk_free_gb": get_disk_usage(),
|
|
}
|
|
|
|
def get_pdal_info() -> dict:
|
|
"""Retourne version et path de pdal via subprocess."""
|
|
info = {"path": None, "version": None}
|
|
|
|
try:
|
|
result = subprocess.run(
|
|
["which", "pdal"],
|
|
capture_output=True, text=True, check=False
|
|
)
|
|
if result.returncode == 0:
|
|
info["path"] = result.stdout.strip()
|
|
except Exception:
|
|
pass
|
|
|
|
try:
|
|
result = subprocess.run(
|
|
["pdal", "--version"],
|
|
capture_output=True, text=True, check=False
|
|
)
|
|
if result.returncode == 0:
|
|
# Sortie : "---\npdal 2.10.0 (git-version: 22e6b2)\n---"
|
|
lines = [l.strip() for l in result.stdout.strip().splitlines()
|
|
if l.strip() and not l.startswith("-")]
|
|
if lines:
|
|
info["version"] = lines[0]
|
|
except Exception:
|
|
pass
|
|
|
|
return info
|
|
|
|
|
|
@app.get("/", response_class=HTMLResponse)
|
|
def home():
|
|
entwine_path = get_entwine_path()
|
|
pdal = get_pdal_info()
|
|
|
|
return f"""<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Backend - PointCloud</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/daisyui@4.12.10/dist/full.min.css" rel="stylesheet">
|
|
</head>
|
|
<body class="min-h-screen bg-base-100 p-4">
|
|
<h2>Backend PointCloud OK ✅</h2>
|
|
<ul>
|
|
<li><a href="/docs">/docs</a> — Documentation API</li>
|
|
<li><a href="/health">/health</a> — État du service</li>
|
|
</ul>
|
|
<h3>Configuration</h3>
|
|
<ul>
|
|
<li>entwine : {"✅ " + entwine_path if entwine_path else "❌ Non trouvé"}</li>
|
|
<li>pdal path : {"✅ " + pdal["path"] if pdal["path"] else "❌ Non trouvé"}</li>
|
|
<li>pdal version : {pdal["version"] if pdal["version"] else "❌ Inconnue"}</li>
|
|
<li>Espace disque : {get_disk_usage()} GB libres</li>
|
|
</ul>
|
|
</body>
|
|
</html>""" |