CieLZ commited on
Commit
22f71cf
·
verified ·
1 Parent(s): 8f6fabc

Update plugins/wai.js

Browse files
Files changed (1) hide show
  1. plugins/wai.js +98 -85
plugins/wai.js CHANGED
@@ -1,86 +1,99 @@
1
- const puppeteer = require('puppeteer');
2
- const fetch = require('node-fetch');
3
-
4
- module.exports = {
5
- path: '/wai',
6
- method: 'GET',
7
- description: 'Generate gambar menggunakan model Illustrious-v140 via CroxyProxy bypass.',
8
- handler: async (request, reply) => {
9
- const { prompt } = request.query;
10
- if (!prompt) return { error: "Prompt kosong!" };
11
-
12
- const browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox'] });
13
- const page = await browser.newPage();
14
-
15
- return new Promise(async (resolve) => {
16
- try {
17
- await page.goto('https://www.croxyproxy.com/', { waitUntil: 'networkidle2' });
18
- await page.type('#url', 'https://nech-c-wainsfwillustrious-v140.hf.space/');
19
- await Promise.all([page.click('#requestSubmit'), page.waitForNavigation({ waitUntil: 'networkidle0' })]);
20
- await new Promise(r => setTimeout(r, 5000));
21
-
22
- const currentUrl = page.url();
23
- const urlObj = new URL(currentUrl);
24
- const proxyBase = `${urlObj.protocol}//${urlObj.host}`;
25
- const cpoToken = urlObj.searchParams.get('__cpo');
26
- const cookies = await page.cookies();
27
- const cookieString = cookies.map(c => `${c.name}=${c.value}`).join('; ');
28
- const session_hash = Math.random().toString(36).substring(2);
29
-
30
- const headers = { "content-type": "application/json", "cookie": cookieString, "referer": currentUrl };
31
-
32
- const joinRes = await fetch(`${proxyBase}/gradio_api/queue/join?__cpo=${cpoToken}`, {
33
- method: "POST",
34
- headers,
35
- body: JSON.stringify({
36
- "data": ["v160", prompt, "masterpiece, best quality", "low quality", Math.floor(Math.random() * 2000000000), true, 1024, 1024, 6, 30, 1, null, true, null],
37
- "fn_index": 12,
38
- "session_hash": session_hash
39
- })
40
- });
41
-
42
- const streamRes = await fetch(`${proxyBase}/gradio_api/queue/data?session_hash=${session_hash}&__cpo=${cpoToken}`, { headers });
43
-
44
- streamRes.body.on('data', (chunk) => {
45
- const dataStr = chunk.toString();
46
- // Pisahkan berdasarkan baris karena satu chunk bisa berisi beberapa event data
47
- const lines = dataStr.split("\n");
48
-
49
- for (let line of lines) {
50
- if (!line.startsWith("data: ")) continue;
51
-
52
- try {
53
- // Membersihkan string "data: " untuk mendapatkan JSON murni
54
- const rawJson = line.replace("data: ", "").trim();
55
- if (!rawJson || rawJson === "[DONE]") continue;
56
-
57
- const json = JSON.parse(rawJson);
58
-
59
- // Pastikan pesan adalah process_completed dan data yang dicari ada
60
- if (json.msg === "process_completed" && json.output && json.output.data) {
61
- const gallery = json.output.data.find(item => Array.isArray(item));
62
-
63
- if (gallery) {
64
- const results = gallery.map(img => {
65
- const rawUrl = img.image?.url || img.url;
66
- const pathOnly = rawUrl.split('gradio_api')[1].split('&')[0];
67
- return `https://nech-c-wainsfwillustrious-v140.hf.space/gradio_api${pathOnly}`;
68
- });
69
-
70
- browser.close();
71
- resolve({ status: "success", images: results });
72
- }
73
- }
74
- } catch (e) {
75
- // Abaikan error parsing jika chunk terpotong di tengah jalan
76
- continue;
77
- }
78
- }
79
- });
80
- } catch (e) {
81
- browser.close();
82
- resolve({ error: e.message });
83
- }
84
- });
85
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  };
 
1
+ const puppeteer = require('puppeteer');
2
+ const fetch = require('node-fetch');
3
+
4
+ module.exports = {
5
+ path: '/wai',
6
+ method: 'GET',
7
+ description: 'Generate gambar menggunakan model Illustrious-v140 via CroxyProxy bypass.',
8
+ handler: async (request, reply) => {
9
+ const { prompt } = request.query;
10
+ if (!prompt) return { error: "Prompt kosong!" };
11
+
12
+ const browser = await puppeteer.launch({
13
+ headless: true,
14
+ executablePath: '/usr/bin/google-chrome-stable', // Path default di linux
15
+ args: [
16
+ '--no-sandbox',
17
+ '--disable-setuid-sandbox',
18
+ '--disable-dev-shm-usage',
19
+ '--disable-accelerated-2d-canvas',
20
+ '--no-first-run',
21
+ '--no-zygote',
22
+ '--single-process', // Penting untuk menghemat RAM di Space gratisan
23
+ '--disable-gpu'
24
+ ]
25
+ });
26
+ const page = await browser.newPage();
27
+
28
+ return new Promise(async (resolve) => {
29
+ try {
30
+ await page.goto('https://www.croxyproxy.com/', { waitUntil: 'networkidle2' });
31
+ await page.type('#url', 'https://nech-c-wainsfwillustrious-v140.hf.space/');
32
+ await Promise.all([page.click('#requestSubmit'), page.waitForNavigation({ waitUntil: 'networkidle0' })]);
33
+ await new Promise(r => setTimeout(r, 5000));
34
+
35
+ const currentUrl = page.url();
36
+ const urlObj = new URL(currentUrl);
37
+ const proxyBase = `${urlObj.protocol}//${urlObj.host}`;
38
+ const cpoToken = urlObj.searchParams.get('__cpo');
39
+ const cookies = await page.cookies();
40
+ const cookieString = cookies.map(c => `${c.name}=${c.value}`).join('; ');
41
+ const session_hash = Math.random().toString(36).substring(2);
42
+
43
+ const headers = { "content-type": "application/json", "cookie": cookieString, "referer": currentUrl };
44
+
45
+ const joinRes = await fetch(`${proxyBase}/gradio_api/queue/join?__cpo=${cpoToken}`, {
46
+ method: "POST",
47
+ headers,
48
+ body: JSON.stringify({
49
+ "data": ["v160", prompt, "masterpiece, best quality", "low quality", Math.floor(Math.random() * 2000000000), true, 1024, 1024, 6, 30, 1, null, true, null],
50
+ "fn_index": 12,
51
+ "session_hash": session_hash
52
+ })
53
+ });
54
+
55
+ const streamRes = await fetch(`${proxyBase}/gradio_api/queue/data?session_hash=${session_hash}&__cpo=${cpoToken}`, { headers });
56
+
57
+ streamRes.body.on('data', (chunk) => {
58
+ const dataStr = chunk.toString();
59
+ // Pisahkan berdasarkan baris karena satu chunk bisa berisi beberapa event data
60
+ const lines = dataStr.split("\n");
61
+
62
+ for (let line of lines) {
63
+ if (!line.startsWith("data: ")) continue;
64
+
65
+ try {
66
+ // Membersihkan string "data: " untuk mendapatkan JSON murni
67
+ const rawJson = line.replace("data: ", "").trim();
68
+ if (!rawJson || rawJson === "[DONE]") continue;
69
+
70
+ const json = JSON.parse(rawJson);
71
+
72
+ // Pastikan pesan adalah process_completed dan data yang dicari ada
73
+ if (json.msg === "process_completed" && json.output && json.output.data) {
74
+ const gallery = json.output.data.find(item => Array.isArray(item));
75
+
76
+ if (gallery) {
77
+ const results = gallery.map(img => {
78
+ const rawUrl = img.image?.url || img.url;
79
+ const pathOnly = rawUrl.split('gradio_api')[1].split('&')[0];
80
+ return `https://nech-c-wainsfwillustrious-v140.hf.space/gradio_api${pathOnly}`;
81
+ });
82
+
83
+ browser.close();
84
+ resolve({ status: "success", images: results });
85
+ }
86
+ }
87
+ } catch (e) {
88
+ // Abaikan error parsing jika chunk terpotong di tengah jalan
89
+ continue;
90
+ }
91
+ }
92
+ });
93
+ } catch (e) {
94
+ browser.close();
95
+ resolve({ error: e.message });
96
+ }
97
+ });
98
+ }
99
  };