Download plugins/wai.js from CieLZ/testing: direct link, hf CLI and curl.
- Browser
- Download file 3.92 kB
-
https://huggingface.co/spaces/CieLZ/testing/resolve/main/plugins/wai.js
- Command line
-
hf download hf://spaces/CieLZ/testing/plugins/wai.js
-
curl -L -o wai.js https://huggingface.co/spaces/CieLZ/testing/resolve/main/plugins/wai.js
3.92 kB
| const puppeteer = require('puppeteer'); | |
| const fetch = require('node-fetch'); | |
| module.exports = { | |
| path: '/wai', | |
| method: 'GET', | |
| description: 'Generate gambar menggunakan model Illustrious-v140 via CroxyProxy bypass.', | |
| handler: async (request, reply) => { | |
| const { prompt } = request.query; | |
| if (!prompt) return { error: "Prompt kosong!" }; | |
| const browser = await puppeteer.launch({ | |
| headless: true, | |
| executablePath: '/usr/bin/google-chrome-stable', // Path default di linux | |
| args: [ | |
| '--no-sandbox', | |
| '--disable-setuid-sandbox', | |
| '--disable-dev-shm-usage', | |
| '--disable-accelerated-2d-canvas', | |
| '--no-first-run', | |
| '--no-zygote', | |
| '--single-process', // Penting untuk menghemat RAM di Space gratisan | |
| '--disable-gpu' | |
| ] | |
| }); | |
| const page = await browser.newPage(); | |
| return new Promise(async (resolve) => { | |
| try { | |
| await page.goto('https://www.croxyproxy.com/', { waitUntil: 'networkidle2' }); | |
| await page.type('#url', 'https://nech-c-wainsfwillustrious-v140.hf.space/'); | |
| await Promise.all([page.click('#requestSubmit'), page.waitForNavigation({ waitUntil: 'networkidle0' })]); | |
| await new Promise(r => setTimeout(r, 5000)); | |
| const currentUrl = page.url(); | |
| const urlObj = new URL(currentUrl); | |
| const proxyBase = `${urlObj.protocol}//${urlObj.host}`; | |
| const cpoToken = urlObj.searchParams.get('__cpo'); | |
| const cookies = await page.cookies(); | |
| const cookieString = cookies.map(c => `${c.name}=${c.value}`).join('; '); | |
| const session_hash = Math.random().toString(36).substring(2); | |
| const headers = { "content-type": "application/json", "cookie": cookieString, "referer": currentUrl }; | |
| const joinRes = await fetch(`${proxyBase}/gradio_api/queue/join?__cpo=${cpoToken}`, { | |
| method: "POST", | |
| headers, | |
| body: JSON.stringify({ | |
| "data": ["v160", prompt, "masterpiece, best quality", "low quality", Math.floor(Math.random() * 2000000000), true, 1024, 1024, 6, 30, 1, null, true, null], | |
| "fn_index": 12, | |
| "session_hash": session_hash | |
| }) | |
| }); | |
| const streamRes = await fetch(`${proxyBase}/gradio_api/queue/data?session_hash=${session_hash}&__cpo=${cpoToken}`, { headers }); | |
| streamRes.body.on('data', (chunk) => { | |
| const dataStr = chunk.toString(); | |
| // Pisahkan berdasarkan baris karena satu chunk bisa berisi beberapa event data | |
| const lines = dataStr.split("\n"); | |
| for (let line of lines) { | |
| if (!line.startsWith("data: ")) continue; | |
| try { | |
| // Membersihkan string "data: " untuk mendapatkan JSON murni | |
| const rawJson = line.replace("data: ", "").trim(); | |
| if (!rawJson || rawJson === "[DONE]") continue; | |
| const json = JSON.parse(rawJson); | |
| // Pastikan pesan adalah process_completed dan data yang dicari ada | |
| if (json.msg === "process_completed" && json.output && json.output.data) { | |
| const gallery = json.output.data.find(item => Array.isArray(item)); | |
| if (gallery) { | |
| const results = gallery.map(img => { | |
| const rawUrl = img.image?.url || img.url; | |
| const pathOnly = rawUrl.split('gradio_api')[1].split('&')[0]; | |
| return `https://nech-c-wainsfwillustrious-v140.hf.space/gradio_api${pathOnly}`; | |
| }); | |
| browser.close(); | |
| resolve({ status: "success", images: results }); | |
| } | |
| } | |
| } catch (e) { | |
| // Abaikan error parsing jika chunk terpotong di tengah jalan | |
| continue; | |
| } | |
| } | |
| }); | |
| } catch (e) { | |
| browser.close(); | |
| resolve({ error: e.message }); | |
| } | |
| }); | |
| } | |
| }; |