Spaces:
Running
Running
Tu Nombre commited on
Commit ·
42d6567
1
Parent(s): a8d90b2
sistema multicanal completo
Browse files
main.py
CHANGED
|
@@ -541,19 +541,24 @@ input:focus,select:focus{border-color:#ff2d2d;}
|
|
| 541 |
<script>
|
| 542 |
async function activar(){
|
| 543 |
const email = document.getElementById('email').value.trim();
|
| 544 |
-
const nicho = document.getElementById("nicho").value;
|
| 545 |
-
const tipo = document.getElementById("tipo").value;
|
| 546 |
if(!email){alert('Por favor pon tu email');return;}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 547 |
document.getElementById('btn').disabled = true;
|
| 548 |
document.getElementById('loading').style.display = 'block';
|
| 549 |
try{
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
headers:{'Content-Type':'application/json'},
|
| 556 |
-
body: JSON.stringify({email,
|
| 557 |
});
|
| 558 |
const d = await r.json();
|
| 559 |
if(d.url){
|
|
@@ -599,18 +604,54 @@ async def activar_canal(token: str = "", plan: str = ""):
|
|
| 599 |
|
| 600 |
@app.post("/crear")
|
| 601 |
async def crear(request: Request):
|
| 602 |
-
data
|
| 603 |
email = data.get("email","")
|
| 604 |
-
|
| 605 |
-
tipo = data.get("tipo","largo")
|
| 606 |
token = data.get("token","")
|
| 607 |
if not token or token not in TOKENS_VALIDOS:
|
| 608 |
return JSONResponse({"error": "Token invalido"}, status_code=403)
|
| 609 |
-
|
| 610 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 611 |
del TOKENS_VALIDOS[token]
|
| 612 |
-
|
| 613 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 614 |
|
| 615 |
|
| 616 |
@app.get("/check-space")
|
|
|
|
| 541 |
<script>
|
| 542 |
async function activar(){
|
| 543 |
const email = document.getElementById('email').value.trim();
|
|
|
|
|
|
|
| 544 |
if(!email){alert('Por favor pon tu email');return;}
|
| 545 |
+
const numCanales = parseInt("CANALES_PLACEHOLDER") || 1;
|
| 546 |
+
const canales = [];
|
| 547 |
+
for(let i=1; i<=numCanales; i++){
|
| 548 |
+
const n = document.getElementById('nicho'+i);
|
| 549 |
+
const t = document.getElementById('tipo'+i);
|
| 550 |
+
if(n && t) canales.push({nicho: n.value, tipo: t.value});
|
| 551 |
+
}
|
| 552 |
document.getElementById('btn').disabled = true;
|
| 553 |
document.getElementById('loading').style.display = 'block';
|
| 554 |
try{
|
| 555 |
+
const ctrl = new AbortController();
|
| 556 |
+
setTimeout(() => ctrl.abort(), 300000);
|
| 557 |
+
const r = await fetch('/crear', {
|
| 558 |
+
method:'POST',
|
| 559 |
+
signal: ctrl.signal,
|
| 560 |
headers:{'Content-Type':'application/json'},
|
| 561 |
+
body: JSON.stringify({email, canales, token: "TOKEN_PLACEHOLDER"})
|
| 562 |
});
|
| 563 |
const d = await r.json();
|
| 564 |
if(d.url){
|
|
|
|
| 604 |
|
| 605 |
@app.post("/crear")
|
| 606 |
async def crear(request: Request):
|
| 607 |
+
data = await request.json()
|
| 608 |
email = data.get("email","")
|
| 609 |
+
canales = data.get("canales", []) # lista de {nicho, tipo}
|
|
|
|
| 610 |
token = data.get("token","")
|
| 611 |
if not token or token not in TOKENS_VALIDOS:
|
| 612 |
return JSONResponse({"error": "Token invalido"}, status_code=403)
|
| 613 |
+
if not canales:
|
| 614 |
+
return JSONResponse({"error": "Sin canales"}, status_code=400)
|
| 615 |
+
urls = []
|
| 616 |
+
for canal in canales:
|
| 617 |
+
nicho = canal.get("nicho", "tecnologia")
|
| 618 |
+
tipo = canal.get("tipo", "largo")
|
| 619 |
+
u = await crear_space(nicho, email, tipo)
|
| 620 |
+
if u:
|
| 621 |
+
urls.append(u)
|
| 622 |
+
if urls:
|
| 623 |
del TOKENS_VALIDOS[token]
|
| 624 |
+
# Enviar email con todas las URLs
|
| 625 |
+
try:
|
| 626 |
+
enviar_email_multi(email, urls)
|
| 627 |
+
except Exception as e:
|
| 628 |
+
print(f"Error email multi: {e}", flush=True)
|
| 629 |
+
return {"success": True, "urls": urls, "url": urls[0]}
|
| 630 |
+
return JSONResponse({"error": "No se pudo crear ningun Space"}, status_code=500)
|
| 631 |
+
|
| 632 |
+
|
| 633 |
+
def enviar_email_multi(email, urls):
|
| 634 |
+
try:
|
| 635 |
+
import requests
|
| 636 |
+
lista_urls = "".join([f'<li style="margin:8px 0"><a href="{u}" style="color:#ff2d2d">{u}</a></li>' for u in urls])
|
| 637 |
+
html = f"""
|
| 638 |
+
<div style="background:#0a0a0a;color:#fff;padding:40px;font-family:sans-serif;max-width:600px;margin:0 auto;">
|
| 639 |
+
<h1 style="color:#ff2d2d;">TubeBot activado</h1>
|
| 640 |
+
<p>Tus <strong>{len(urls)} canales</strong> ya estan funcionando.</p>
|
| 641 |
+
<ul style="list-style:none;padding:0;">{lista_urls}</ul>
|
| 642 |
+
<p style="color:#666;font-size:.85rem;">Si tienes dudas responde este email.</p>
|
| 643 |
+
</div>"""
|
| 644 |
+
requests.post("https://api.brevo.com/v3/smtp/email",
|
| 645 |
+
headers={"api-key": os.environ.get("BREVO_KEY",""), "Content-Type": "application/json", "accept": "application/json"},
|
| 646 |
+
json={
|
| 647 |
+
"sender": {"name": "TubeBot", "email": "dayron100813@gmail.com"},
|
| 648 |
+
"to": [{"email": email}],
|
| 649 |
+
"subject": f"Tus {len(urls)} canales estan listos",
|
| 650 |
+
"htmlContent": html
|
| 651 |
+
}
|
| 652 |
+
)
|
| 653 |
+
except Exception as e:
|
| 654 |
+
print(f"Error email: {e}", flush=True)
|
| 655 |
|
| 656 |
|
| 657 |
@app.get("/check-space")
|