Public Access
This commit is contained in:
1 parent
1424cb7ab4
commit
1eb619a50b
3 files changed
+185
-55
No files matched your search
@@ -26,6 +26,112 @@ 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) ---
|
||||
def render_paypal_recharge_widget(montant_usd: float = 10.00):
|
||||
client_id = os.getenv("PAYPAL_CLIENT_ID", "test")
|
||||
|
||||
script_paypal = Script(src=f"https://www.paypal.com/sdk/js?client-id={client_id}¤cy=USD")
|
||||
container_id = f"paypal-button-container-{str(montant_usd).replace('.', '')}"
|
||||
|
||||
script_logique = Script(f"""
|
||||
function chargerBoutonPayPal() {{
|
||||
if (typeof paypal !== 'undefined') {{
|
||||
paypal.Buttons({{
|
||||
style: {{ layout: 'vertical', height: 35, shape: 'rect', label: 'paypal' }},
|
||||
createOrder: function(data, actions) {{
|
||||
return actions.order.create({{
|
||||
purchase_units: [{{ amount: {{ value: '{montant_usd}' }} }}]
|
||||
}});
|
||||
}},
|
||||
onApprove: function(data, actions) {{
|
||||
return actions.order.capture().then(function(details) {{
|
||||
alert('Paiement validé par ' + details.payer.name.given_name + ' ! Vos crédits vont être ajoutés.');
|
||||
|
||||
fetch('/api/paypal/success', {{
|
||||
method: 'POST',
|
||||
headers: {{ 'Content-Type': 'application/json' }},
|
||||
body: JSON.stringify({{ orderID: data.orderID }})
|
||||
}}).then(res => {{
|
||||
if(res.ok) {{
|
||||
document.getElementById('modal-recharge-paypal').style.display = 'none';
|
||||
window.location.reload();
|
||||
}} else {{
|
||||
alert("Erreur lors de la validation serveur.");
|
||||
}}
|
||||
}});
|
||||
}});
|
||||
}}
|
||||
}}).render('#{container_id}');
|
||||
}} else {{
|
||||
setTimeout(chargerBoutonPayPal, 100);
|
||||
}}
|
||||
}}
|
||||
chargerBoutonPayPal();
|
||||
""")
|
||||
|
||||
paypal_box = Div(
|
||||
H4(f"Recharge : {montant_usd} $", style="color: #fff; margin: 0 0 10px 0; font-size: 1.1em; text-align: center;"),
|
||||
Div(id=container_id, style="min-height: 100px; width: 100%;"),
|
||||
Button("Annuler", type="button", onclick="document.getElementById('modal-recharge-paypal').style.display='none'",
|
||||
style="background: transparent; border: 1px solid #555; color: #aaa; width: 100%; margin-top: 5px; padding: 6px; border-radius: 6px; font-size: 0.85em; cursor: pointer;"),
|
||||
style="background: #1a1a1a; padding: 20px; border-radius: 10px; border: 1px solid #333; width: 320px; max-width: 90vw; box-shadow: 0 8px 24px rgba(0,0,0,0.9);"
|
||||
)
|
||||
|
||||
modal_overlay = Div(
|
||||
script_paypal, paypal_box, script_logique,
|
||||
id="modal-recharge-paypal",
|
||||
style="display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.6); backdrop-filter: blur(3px); align-items: center; justify-content: center; z-index: 10000;"
|
||||
)
|
||||
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):
|
||||
@@ -98,7 +204,16 @@ def get(session, request):
|
||||
session['user'] = utilisateur
|
||||
if 'current_chat_id' not in session or not session['current_chat_id']:
|
||||
session['current_chat_id'] = str(uuid.uuid4())
|
||||
return render_main_page(session['current_chat_id'], utilisateur_nom=session['user'])
|
||||
|
||||
# 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
|
||||
nav_sidebar = render_sidebar_menu()
|
||||
paypal_modal = render_paypal_recharge_widget(10.00)
|
||||
|
||||
# Renvoi combiné (les éléments fixed/absolute s'afficheront par-dessus)
|
||||
return nav_sidebar, paypal_modal, main_page
|
||||
|
||||
@rt('/chat')
|
||||
async def post(request, session):
|
||||
@@ -147,6 +262,14 @@ 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()
|
||||
order_id = data.get("orderID")
|
||||
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):
|
||||
|
||||
Reference in new issue
Block a user