""" Routes API pour l'aide et la documentation. Source unique: app/static/help.md """ from pathlib import Path from fastapi import APIRouter, Depends from fastapi.responses import JSONResponse, Response from app.core.config import settings from app.core.dependencies import verify_api_key from app.utils.help_renderer import render_help_page, get_raw_markdown from app.utils.pdf_generator import markdown_to_pdf_bytes router = APIRouter() # Chemin vers le fichier source Markdown HELP_MD_PATH = settings.base_dir / "static" / "help.md" @router.get("/content") async def get_help_content(api_key_valid: bool = Depends(verify_api_key)): """ Retourne le contenu HTML de la page d'aide généré depuis help.md. Utilisé pour le chargement dynamique de la page d'aide. """ html_content, toc_html = render_help_page(HELP_MD_PATH) return JSONResponse({ "content": html_content, "toc": toc_html }) @router.get("/documentation.md") async def download_help_markdown(api_key_valid: bool = Depends(verify_api_key)): """Télécharge la documentation d'aide en format Markdown.""" markdown_content = get_raw_markdown(HELP_MD_PATH) return Response( content=markdown_content, media_type="text/markdown; charset=utf-8", headers={ "Content-Disposition": "attachment; filename=homelab-automation-help.md" } ) @router.get("/documentation.pdf") async def download_help_pdf(api_key_valid: bool = Depends(verify_api_key)): """Télécharge la documentation d'aide en format PDF.""" markdown_content = get_raw_markdown(HELP_MD_PATH) pdf_bytes = markdown_to_pdf_bytes( markdown_content, title="Homelab Automation - Documentation" ) return Response( content=pdf_bytes, media_type="application/pdf", headers={ "Content-Disposition": "attachment; filename=homelab-automation-help.pdf" } )