aijavascript22954
Dezgo AI Text-to-Image Generation Scraper
Generator gambar berbasis Artificial Intelligence (Text-to-Image) menggunakan model Stable Diffusion tanpa perlu GPU lokal.
Vamz Spectre29 Sep 2026222 baris kode
Jalankan via Terminal / CLI:
# 1. Download file script
curl -sL "https://code.vamxapi.my.id/snippet/raw/dezgo-ai-txt2img" -o dezgo-ai-txt2img.js
# 2. Jalankan script
node dezgo-ai-txt2img.js
Dependencies npm yang Dibutuhkan:
npm install axiosPanduan Penggunaan:
// Instalasi: npm install axios // Penggunaan: node dezgo-ai-txt2img.js "cyberpunk city neon rain, highly detailed 8k"
dezgo-ai-txt2img.js(222 lines)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
const crypto = require("crypto");
const fs = require("fs");
const path = require("path");
const FREE_MODELS = [
"stablediffusion_1_5",
"stablediffusion_1_4",
"stablediffusion_2_1_512px",
"waifudiffusion_1_3",
"anything_3_0",
"vintedois_diffusion_v0_1"
];
function calculateHToken(nonceUuidStr) {
const keyB64 =
"xO5LptfWq/+QLDc2zJ+dzhYE7xOTtgu09G3z6y/yuZPjQ12+K9LdcIg4raDgtpeN5MpBpnKPl+Ga\n2I4zEHRmlw==";
const keyBytes = Buffer.from(keyB64, "base64");
const hash1 = crypto.createHash("sha512").update(Buffer.alloc(0)).digest();
const hex = nonceUuidStr.replace(/-/g, "");
const nonceBytes = Buffer.alloc(16);
nonceBytes.writeUInt32LE(parseInt(hex.substring(0, 8), 16), 0);
nonceBytes.writeUInt16LE(parseInt(hex.substring(8, 12), 16), 4);
nonceBytes.writeUInt16LE(parseInt(hex.substring(12, 16), 16), 6);
Buffer.from(hex.substring(16, 32), "hex").copy(nonceBytes, 8);
for (let i = 0; i < keyBytes.length; i++) {
keyBytes[i] ^= hash1[i];
}
for (let j = 0; j < nonceBytes.length; j++) {
keyBytes[j] ^= nonceBytes[j];
}
return crypto.createHash("sha512").update(keyBytes).digest("base64");
}
async function scrapeDezgoText2Image(options = {}) {
const prompt = options.prompt?.trim();
if (!prompt) {
throw new Error("Parameter 'prompt' wajib diisi.");
}
const model = options.model || "stablediffusion_1_5";
const steps = Math.min(Math.max(Number(options.steps) || 16, 10), 16);
const guidance = Number(options.guidance) || 8;
const sampler = options.sampler || "dpm";
const width = Math.min(Math.max(Number(options.width) || 512, 256), 512);
const height = Math.min(Math.max(Number(options.height) || 512, 256), 512);
const maxSubmitTrials = options.maxTrials || 35;
const retryDelay = options.retryDelay || 3000;
let jobId = null;
for (let trial = 1; trial <= maxSubmitTrials; trial++) {
const nonce = crypto.randomUUID();
const cToken = crypto.randomBytes(16).toString("base64");
const wToken = (crypto.randomBytes(8).readBigInt64BE() & 0x7fffffffffffffffn).toString();
const hToken = calculateHToken(nonce);
const formData = new FormData();
formData.append("prompt", prompt);
formData.append("guidance", String(guidance));
formData.append("sampler", sampler);
formData.append("steps", String(steps));
formData.append("width", String(width));
formData.append("height", String(height));
if (model) formData.append("model", model);
if (options.negative_prompt) formData.append("negative_prompt", options.negative_prompt.trim());
try {
const res = await fetch("https://api.dezgo.com/text2image", {
method: "POST",
headers: {
"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",
Origin: "https://dezgo.com",
Referer: "https://dezgo.com/",
"X-CToken": cToken,
"X-WToken": wToken,
"X-HToken": hToken,
"X-NToken": nonce,
"X-D-Method": "text2image",
"X-Dezgo-Web": "1",
"X-V": "5",
"X-Dezgo-Async": "1"
},
body: formData
});
if (res.status === 200) {
const buffer = Buffer.from(await res.arrayBuffer());
return {
buffer,
contentType: "image/png",
model,
prompt,
width,
height,
steps,
guidance,
sampler
};
}
if (res.status === 202) {
const data = await res.json();
if (data?.id) {
jobId = data.id;
break;
}
}
} catch {}
await new Promise((r) => setTimeout(r, retryDelay));
}
if (!jobId) {
throw new Error("Gagal mengantrekan pembuatan gambar ke server Dezgo setelah beberapa kali percobaan.");
}
const maxPolls = options.maxPolls || 35;
for (let poll = 1; poll <= maxPolls; poll++) {
await new Promise((r) => setTimeout(r, 2000));
try {
const pollRes = await fetch(`https://api.dezgo.com/async/${jobId}`, {
headers: {
"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",
Origin: "https://dezgo.com",
Referer: "https://dezgo.com/",
"X-Dezgo-Id": jobId
}
});
if (pollRes.status === 200) {
const buffer = Buffer.from(await pollRes.arrayBuffer());
return {
buffer,
contentType: "image/png",
model,
prompt,
width,
height,
steps,
guidance,
sampler,
jobId
};
}
if (pollRes.status === 404) {
throw new Error("Pekerjaan gambar kadaluwarsa atau tidak ditemukan.");
}
} catch (err) {
if (err.message.includes("kadaluwarsa")) throw err;
}
}
throw new Error("Batas waktu menunggu render gambar dari Dezgo telah habis.");
}
if (typeof module !== "undefined" && module.exports) {
module.exports = {
scrapeDezgoText2Image,
FREE_MODELS
};
}
if (require.main === module) {
const args = process.argv.slice(2);
if (args.includes("--models") || args.includes("-m-list")) {
console.log("Model Gratis yang Tersedia di Dezgo /text2image:");
FREE_MODELS.forEach((m, idx) => console.log(` ${idx + 1}. ${m}`));
process.exit(0);
}
const promptIdx = args.indexOf("--prompt") !== -1 ? args.indexOf("--prompt") + 1 : -1;
const prompt = promptIdx !== -1 && args[promptIdx] ? args[promptIdx] : args[0];
if (!prompt || prompt.startsWith("--")) {
console.log("Penggunaan:");
console.log(" node scripts/dezgo-scraper.js \"prompt kamu di sini\" [opsi]");
console.log(" node scripts/dezgo-scraper.js --prompt \"cat astronaut\" --model stablediffusion_1_5 --out output.png");
console.log(" node scripts/dezgo-scraper.js --models");
process.exit(1);
}
function getArg(flag, def) {
const idx = args.indexOf(flag);
return idx !== -1 && args[idx + 1] ? args[idx + 1] : def;
}
const model = getArg("--model", "stablediffusion_1_5");
const outFile = getArg("--out", `dezgo_${Date.now()}.png`);
const steps = parseInt(getArg("--steps", "16"), 10);
const guidance = parseFloat(getArg("--guidance", "8"));
const negativePrompt = getArg("--neg", "");
console.log(`[Dezgo Scraper] Mengenerate gambar...`);
console.log(` Prompt : ${prompt}`);
console.log(` Model : ${model}`);
console.log(` Steps : ${steps}`);
scrapeDezgoText2Image({
prompt,
model,
steps,
guidance,
negative_prompt: negativePrompt
})
.then((res) => {
fs.writeFileSync(outFile, res.buffer);
console.log(`[Dezgo Scraper] Berhasil! Gambar disimpan ke: ${outFile} (${res.buffer.length} bytes)`);
})
.catch((err) => {
console.error(`[Dezgo Scraper] Error:`, err.message);
process.exit(1);
});
}