Spaces:
Paused
Paused
File size: 3,155 Bytes
c092c2f 5df0611 c092c2f f6848fa 2b715e9 f6848fa c092c2f 2b715e9 f6848fa c092c2f 2b715e9 c092c2f 2b715e9 c092c2f f6848fa 2b715e9 c092c2f 2b715e9 c092c2f 2b715e9 c092c2f 2b715e9 c092c2f 2b715e9 c092c2f 2b715e9 c092c2f 5df0611 2b715e9 5df0611 2b715e9 c092c2f 2b715e9 c092c2f f6848fa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | const express = require('express');
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
const path = require('path');
puppeteer.use(StealthPlugin());
const app = express();
app.use(express.json());
app.use(express.static(path.join(__dirname, 'public')));
app.post('/api/generate', async (req, res) => {
const { prompt } = req.body;
if (!prompt) return res.status(400).json({ success: false, error: "Prompt is required." });
let browser;
try {
// Notice we removed executablePath, it will use the one NPM installs!
browser = await puppeteer.launch({
headless: "new",
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--window-size=1280,720'
]
});
const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 720 });
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
let mediaUrl = null;
page.on('response', async (response) => {
if (response.url().includes('/nextjs-api/stream/create-evaluation') && response.status() === 200) {
try {
const text = await response.text();
const match = text.match(/https:\/\/[^\s"'<>\\]+\.(mp4|png|webp|jpg|jpeg)/i);
if (match) mediaUrl = match[0];
} catch (e) {}
}
});
// 1. Go to site
await page.goto('https://arena.ai/', { waitUntil: 'networkidle2' });
// Give Cloudflare 5 extra seconds to clear
await new Promise(r => setTimeout(r, 5000));
// 2. Wait for textarea and type
await page.waitForSelector('textarea', { timeout: 15000 });
await page.type('textarea', prompt, { delay: 50 });
await new Promise(r => setTimeout(r, 500));
// 3. Press Enter
await page.keyboard.press('Enter');
// 4. Wait for media (up to 45 seconds)
let attempts = 0;
while (!mediaUrl && attempts < 45) {
await new Promise(r => setTimeout(r, 1000));
attempts++;
}
if (mediaUrl) {
res.json({ success: true, creator: "Silent Tech", prompt: prompt, url: mediaUrl });
} else {
// 👁️ TAKE A SCREENSHOT OF THE BLOCK!
const base64Screenshot = await page.screenshot({ encoding: "base64" });
res.status(500).json({
success: false,
error: "Generation Timeout. See debug screenshot to find out why.",
debug_image: `data:image/png;base64,${base64Screenshot}`
});
}
} catch (err) {
res.status(500).json({ success: false, error: err.message });
} finally {
if (browser) await browser.close();
}
});
app.listen(7860, "0.0.0.0", () => {
console.log('Silent Tech API Proxy running on port 7860');
}); |