From b5926633a3cc7b460e83773cb19806e3c644faf7 Mon Sep 17 00:00:00 2001 From: Xavier Date: Sat, 29 Aug 2026 10:05:48 +0200 Subject: [PATCH] on test --- main.py | 62 +--------------------------------------- modules/ui_components.py | 6 ++-- 2 files changed, 5 insertions(+), 63 deletions(-) diff --git a/main.py b/main.py index 8a79a14..4eee3d4 100644 --- a/main.py +++ b/main.py @@ -26,7 +26,7 @@ import modules.model_updater dossier_media = "/DATA/AppData/MULTI-IA-AETHAS38/RAG/Media" os.makedirs(dossier_media, exist_ok=True) -# --- NOUVEAUX COMPOSANTS UI (SIDEBAR & PAYPAL) --- +# --- WIDGET PAYPAL (RECHARGE DE CRÉDITS) --- def render_paypal_recharge_widget(montant_usd: float = 10.00): client_id = os.getenv("PAYPAL_CLIENT_ID", "test") @@ -84,61 +84,12 @@ def render_paypal_recharge_widget(montant_usd: float = 10.00): ) return modal_overlay -def render_sidebar_menu(): - sidebar_style = Style(""" - :root { --nav-sidebar-width: 260px; } - #nav-app-sidebar { - position: fixed; top: 0; left: 0; width: var(--nav-sidebar-width); height: 100vh; - background: rgba(17, 17, 17, 0.95); backdrop-filter: blur(5px); border-right: 1px solid #333; overflow-y: auto; - transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); - z-index: 9000; padding: 60px 20px 20px 20px; - } - #nav-app-sidebar.collapsed { transform: translateX(-100%); } - #nav-app-sidebar::-webkit-scrollbar { width: 6px; } - #nav-app-sidebar::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; } - - #nav-sidebar-toggle { - position: fixed; top: 15px; left: 15px; z-index: 9001; - background: rgba(0, 0, 0, 0.5); border: 1px solid #333; color: #fff; font-size: 1.2em; - cursor: pointer; padding: 5px 10px; border-radius: 5px; - transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1); - } - body:has(#nav-app-sidebar:not(.collapsed)) #nav-sidebar-toggle { - left: calc(var(--nav-sidebar-width) - 50px); - } - """) - - sidebar_js = Script(""" - function toggleNavSidebar() { - document.getElementById('nav-app-sidebar').classList.toggle('collapsed'); - } - """) - - toggle_btn = Button("☰ Menu", id="nav-sidebar-toggle", onclick="toggleNavSidebar()") - - sidebar_content = Div( - H3("Interface Multi-IA", style="color: #888; font-size: 0.9em; text-transform: uppercase; margin-bottom: 15px;"), - Div("Comptabilité (Export)", style="padding: 10px; color: #ddd; cursor: pointer; border-radius: 5px; margin-bottom: 5px; background: #222;", onclick="window.location.href='/admin/export_comptable'"), - Div("Gestion RAG", style="padding: 10px; color: #ddd; cursor: pointer; border-radius: 5px; margin-bottom: 5px;", onclick="window.location.href='/admin/rag_modal'"), - Hr(style="border-color: #333; margin: 20px 0;"), - Button( - "Recharger des crédits", - onclick="document.getElementById('modal-recharge-paypal').style.display='flex'", - style="width: 100%; padding: 10px; background: #00e5ff; color: #000; border: none; border-radius: 6px; font-weight: bold; cursor: pointer;" - ), - id="nav-app-sidebar", - cls="collapsed" - ) - - return Div(sidebar_style, sidebar_js, toggle_btn, sidebar_content) - # --- MIDDLEWARE DE SÉCURITÉ & SERVEUR MÉDIA UNIFIÉ --- class SecurityMiddleware(BaseHTTPMiddleware): async def dispatch(self, request, call_next): ip = request.headers.get("X-Forwarded-For", request.client.host).split(",")[0].strip() utilisateur = request.cookies.get("aethas_user", "visiteur") - # --- LECTURE EN RAM ULTRA-DIRECTE PAR LE MIDDLEWARE --- if request.url.path.startswith("/Media/"): fname = request.url.path.replace("/Media/", "", 1) chemin = os.path.join(dossier_media, fname) @@ -150,12 +101,10 @@ class SecurityMiddleware(BaseHTTPMiddleware): return HTMLResponse(f"Erreur : {e}", status_code=500) return HTMLResponse("Fichier introuvable", status_code=404) - # EXCLUSION DE /Media POUR NE PAS BLOQUER LE RESTE if not request.url.path.startswith(("/Logo", "/login", "/Media")): if verifier_et_bloquer_vpn(ip, utilisateur): return HTMLResponse("

Accès refusé

VPN ou Proxy strictement interdit.

", status_code=403) - # Exclusion stricte du spam de logs (Silence pour /ping et /favicon) if request.url.path not in ["/ping", "/favicon.ico"]: journaliser_ip(ip, f"Accès à {request.url.path}") @@ -205,13 +154,9 @@ def get(session, request): if 'current_chat_id' not in session or not session['current_chat_id']: session['current_chat_id'] = str(uuid.uuid4()) - # Génération de la page principale existante main_page = render_main_page(session['current_chat_id'], utilisateur_nom=session['user']) - - # Génération des nouveaux composants paypal_modal = render_paypal_recharge_widget(10.00) - # Renvoi combiné (les éléments fixed/absolute s'afficheront par-dessus) return paypal_modal, main_page @rt('/chat') @@ -261,7 +206,6 @@ def post(cid: str): if cid_str in h: del h[cid_str]; save_history(h) return render_sidebar() -# --- NOUVELLE ROUTE WEBHOOK PAYPAL --- @rt('/api/paypal/success') async def post(request): data = await request.json() @@ -269,14 +213,11 @@ async def post(request): log_event("INFO", "FINANCE", f"Recharge PayPal validée - OrderID: {order_id}") return {"status": "success"} -# --- NOUVELLE ROUTE POUR LE RAG (BOUTON MANUEL) --- @rt('/api/forcer_rag') def post(prompt: str, reponse: str, theme: str): - """Intercepte la demande manuelle, lance l'indexation et renvoie un badge vert.""" auto_apprendre_rag(prompt, reponse, theme) return Span("✅ Indexé", cls="msg-action-btn", style="background-color: #4caf50; color: white; border: none; cursor: default;") -# --- NOUVELLES ROUTES POUR L'UPLOAD MODAL DU RAG --- @rt('/admin/rag_modal') def get(session): if session.get('user', '') != 'xavier': @@ -315,7 +256,6 @@ async def post(request, session): from modules.export_utils import generer_export_comptable -# --- NOUVELLE ROUTE POUR L'EXPORT COMPTABLE EXCEL --- @rt('/admin/export_comptable') def get(session): if session.get('user', '') != 'xavier': diff --git a/modules/ui_components.py b/modules/ui_components.py index 47d0068..717a235 100644 --- a/modules/ui_components.py +++ b/modules/ui_components.py @@ -153,9 +153,12 @@ def render_main_page(chat_id, utilisateur_nom="xavier", role="Super Admin"): A("+ Nouvelle discussion", href="/new_chat", cls="new-chat-btn"), A("💾 Exporter JSON", href="/export_json", target="_blank", cls="export-btn"), - # --- NOUVEAU BOUTON PAYPAL INTÉGRÉ ICI --- + # Bouton de recharger les crédits Button("💳 Recharger des crédits", onclick="document.getElementById('modal-recharge-paypal').style.display='flex'", cls="export-btn", style="background-color: #00e5ff; color: black; border: none; margin-top: 5px; font-weight: bold; cursor: pointer;"), + # Lien de don direct basé sur le .env + A("❤️ Faire un don", href=os.getenv("PAYPAL_DONATION_LINK", "#"), target="_blank", cls="export-btn", style="background-color: #ff4081; color: white; border-color: #ff4081; margin-top: 5px; text-decoration: none; text-align: center; font-weight: bold;"), + Button("📚 Gestion RAG", hx_get="/admin/rag_modal", hx_target="body", hx_swap="beforeend", cls="export-btn", style="background-color: #2196f3; color: white; border-color: #2196f3; margin-top: 5px; cursor: pointer;") if role.lower() in ["super admin", "admin"] else "", A("📊 Export URSSAF (Excel)", href="/admin/export_comptable", cls="export-btn", style="background-color: #4caf50; color: white; border-color: #4caf50; margin-top: 5px; text-decoration: none; text-align: center;") if role.lower() in ["super admin", "admin"] else "", A("🚪 Déconnexion", href="/logout", cls="export-btn", style="background-color: #8b0000; color: white; border-color: #8b0000; margin-top: 5px;"), @@ -258,7 +261,6 @@ def render_popup_paiement(cout_estime, prompt_sauvegarde, chat_id, multi_ia_stat ) def render_rag_upload_modal(): - """Génère la fenêtre pop-up pour téléverser des documents dans le RAG.""" themes = [ "Minecraft_KubeJS", "Juridique_Loi_Francaise", "Serveur_Debian", "Bureautique_Excel", "Regles_Aethas38", "Education_Nationale", "Connaissances_Generales"