from fastapi import FastAPI from playwright.async_api import async_playwright import base64 app = FastAPI() BEARER = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY5M2NmYTBkMGU4YzlmMzdiZTA4Y2IyMCIsImlhdCI6MTczMjM5NTc5OSwiZXhwIjoxNzczMDAwNTk5fQ.Mc-LS_NMe0lpBQrQE4DEGs83iVBHIp8LvzBdeaUbmHo" @app.get("/") def home(): return {"status": "Silent Auto-React API is Running 🟢"} @app.get("/api/react") async def do_react(url: str, emojis: str): try: async with async_playwright() as p: browser = await p.chromium.launch(headless=True) context = await browser.new_context( user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" ) await context.add_cookies([{ "name": "ain", "value": BEARER, "domain": "asitha.top", "path": "/" }]) page = await context.new_page() await page.goto("https://asitha.top/channel-react", wait_until="networkidle") try: # Wait for the button. If it doesn't appear in 10 seconds, it will fail and jump to the 'except' block to take a screenshot. await page.wait_for_selector("button:has-text('Pay 1 COIN')", timeout=10000) except Exception as e: # 📸 TAKE SCREENSHOT IF IT FAILS screenshot_bytes = await page.screenshot(full_page=True) screenshot_b64 = base64.b64encode(screenshot_bytes).decode('utf-8') await browser.close() return {"success": False, "error": "Stuck on login screen.", "image": screenshot_b64} inputs = await page.locator("input").all() if len(inputs) >= 2: await inputs[0].fill(url) await inputs[1].fill(emojis) await page.locator("button:has-text('Pay 1 COIN')").click() await page.wait_for_timeout(4000) await browser.close() return {"success": True, "message": "Reaction injected successfully!"} else: # 📸 TAKE SCREENSHOT IF BOXES ARE MISSING screenshot_bytes = await page.screenshot(full_page=True) screenshot_b64 = base64.b64encode(screenshot_bytes).decode('utf-8') await browser.close() return {"success": False, "error": "Could not find text boxes.", "image": screenshot_b64} except Exception as e: return {"success": False, "error": str(e)}