Spaces:
Sleeping
Sleeping
File size: 14,095 Bytes
28cb6f0 | 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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | const axios = require('axios');
const crypto = require('crypto');
class LightXBot {
constructor() {
this.tempMailHeaders = {
'Content-Type': 'application/json',
'Application-Name': 'web',
'Application-Version': '4.0.0',
'X-CORS-Header': 'iaWg3pchvFx48fY'
};
this.lightxHeaders = {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
};
this.authPayload = {
clientHash: '78e7841d9f1891ced5b260c455ea99f3',
accessToken: '',
version: '0.1',
deviceId: '',
model: '',
os: 24,
platform: 'web',
appname: 'lightx',
locale: 'en-GB',
appVersion: 3,
apiHash: 'fb194c698ecca6bc73d649c3fabee629cfe0e2ccc9805ef5a91b0374e52fe4969cd62e2b9abe8bb3d55738914fedcd50ffbe225740ae84c9e2b1aa5081c511fc'
};
this.zombieStyles = {
1: {
name: "Classic Zombie",
prompt: "A man dressed as a zombie male costume features torn, bloodstained clothes, creating a creepy, haunted house with a creepy butler for a spooky and pumpkin, halloween night background",
productId: 10103796,
productImageId: 123663
},
2: {
name: "Walking Dead Zombie",
prompt: "Transform into a decaying walking dead zombie with rotting flesh, pale grey skin, sunken eyes, and tattered bloody clothing in a post-apocalyptic setting",
productId: 10103796,
productImageId: 123663
},
3: {
name: "Horror Zombie",
prompt: "Become a terrifying horror movie zombie with gruesome makeup, exposed bones, blood dripping, vacant stare, and decomposed skin in a dark spooky graveyard",
productId: 10103796,
productImageId: 123663
},
4: {
name: "Undead Creature",
prompt: "Transform into an undead zombie creature with greenish rotting skin, missing chunks of flesh, empty soulless eyes, torn clothes covered in dirt and blood",
productId: 10103796,
productImageId: 123663
},
5: {
name: "Nightmare Zombie",
prompt: "Become a nightmarish zombie with horrifying scars, decaying face, bloodshot eyes, ripped and stained clothing in a foggy haunted cemetery at midnight",
productId: 10103796,
productImageId: 123663
}
};
this.email = '';
this.token = '';
this.password = '';
this.bearerToken = '';
this.systemRefKey = '';
}
hashPassword(password) {
return crypto.createHash('sha512').update(password).digest('hex');
}
generateRandomString(length) {
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;
}
async createTempEmail() {
const response = await axios.post(
'https://api.internal.temp-mail.io/api/v3/email/new',
{ min_name_length: 10, max_name_length: 10 },
{ headers: this.tempMailHeaders }
);
this.email = response.data.email;
this.token = response.data.token;
return { email: this.email, token: this.token };
}
async registerAccount(name, password) {
this.password = password;
const hashedPassword = this.hashPassword(password);
const response = await axios.post(
'https://www.instagraphe.mobi/andor-login-1.0/mobile/emailSignup',
{
name: name,
email: this.email,
password: hashedPassword
},
{ headers: { ...this.lightxHeaders, auth: JSON.stringify(this.authPayload) } }
);
return response.data;
}
async waitForVerificationEmail(maxRetries = 20, interval = 5000) {
for (let i = 0; i < maxRetries; i++) {
const response = await axios.get(
`https://api.internal.temp-mail.io/api/v3/email/${this.email}/messages`,
{ headers: this.tempMailHeaders }
);
if (response.data && response.data.length > 0) {
const verificationEmail = response.data.find(msg =>
msg.subject === 'Welcome to LightX' && msg.body_text.includes('validate-email')
);
if (verificationEmail) {
const linkMatch = verificationEmail.body_text.match(/https:\/\/www\.lightxeditor\.com\/validate-email\?[^\s)]+/);
if (linkMatch) {
return linkMatch[0];
}
}
}
await new Promise(resolve => setTimeout(resolve, interval));
}
throw new Error('Email verifikasi tidak diterima');
}
async verifyEmail(verificationLink) {
try {
await axios.get(verificationLink, {
maxRedirects: 5,
timeout: 10000
});
return 'Success';
} catch (error) {
return 'Success';
}
}
async login() {
const hashedPassword = this.hashPassword(this.password);
const response = await axios.post(
'https://www.instagraphe.mobi/andor-login-1.0/mobile/login',
{
password: hashedPassword,
type: 'EMAIL',
value: this.email
},
{ headers: { ...this.lightxHeaders, auth: JSON.stringify(this.authPayload) } }
);
this.bearerToken = response.data.body.token.accessToken;
this.systemRefKey = response.data.body.user.systemRefKey;
return response.data;
}
async checkCredits() {
const authWithToken = {
...this.authPayload,
accessToken: this.bearerToken,
systemRefKey: this.systemRefKey
};
const response = await axios.get(
'https://www.instagraphe.mobi/andor-login-1.0/user/getAPIUsageDetails?apiId=1',
{ headers: { ...this.lightxHeaders, auth: JSON.stringify(authWithToken) } }
);
return response.data.body;
}
async uploadImage(imageBuffer, fileName, size) {
const authWithToken = {
...this.authPayload,
accessToken: this.bearerToken,
systemRefKey: this.systemRefKey
};
const presignResponse = await axios.post(
'https://www.instagraphe.mobi/andor-media-1.0/content/generatePresignedUrls',
{
featureType: 'selfie',
contents: [{
size: size,
contentType: 'image/jpeg',
assetType: 'IMG',
assetRefId: '1',
name: fileName
}]
},
{ headers: { ...this.lightxHeaders, auth: JSON.stringify(authWithToken) } }
);
const uploadData = presignResponse.data.body.contents[0];
const presignedUrl = uploadData.presignedUrl;
const imageUrl = uploadData.contentUrl;
await axios.put(presignedUrl, imageBuffer, {
headers: {
'Content-Type': 'image/jpeg',
'Content-Length': size
}
});
return imageUrl;
}
async convertToZombie(imageUrl, styleId) {
const style = this.zombieStyles[styleId];
if (!style) {
throw new Error(`Invalid style ID: ${styleId}. Valid IDs are 1-5`);
}
const authWithToken = {
...this.authPayload,
accessToken: this.bearerToken,
systemRefKey: this.systemRefKey
};
try {
const response = await axios.post(
'https://www.instagraphe.mobi/andor-media-1.0/aiartweb/generateImage',
{
featureType: 'selfie',
isCustomPrompt: 0,
quality: 1,
imageUrl: imageUrl,
productId: style.productId,
model: 58,
textPrompt: style.prompt,
productImageId: style.productImageId
},
{ headers: { ...this.lightxHeaders, auth: JSON.stringify(authWithToken) } }
);
if (!response.data || !response.data.body || !response.data.body.assetId) {
throw new Error(`Invalid response: ${JSON.stringify(response.data)}`);
}
const assetId = response.data.body.assetId;
return await this.checkGenerationStatus(assetId);
} catch (error) {
if (error.response) {
throw new Error(`API Error: ${JSON.stringify(error.response.data)}`);
}
throw error;
}
}
async checkGenerationStatus(assetId, maxRetries = 30, interval = 3000) {
const authWithToken = {
...this.authPayload,
accessToken: this.bearerToken,
systemRefKey: this.systemRefKey
};
for (let i = 0; i < maxRetries; i++) {
const response = await axios.post(
'https://www.instagraphe.mobi/andor-media-1.0/aiart/checkStatus',
{ assetId: assetId },
{ headers: { ...this.lightxHeaders, auth: JSON.stringify(authWithToken) } }
);
const status = response.data.body.status;
if (status === 'active') {
return response.data.body;
}
await new Promise(resolve => setTimeout(resolve, interval));
}
throw new Error('Generation timeout');
}
}
async function img2zombie(imageUrl, styleId = 1, maxRetries = 3) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
const bot = new LightXBot();
try {
await bot.createTempEmail();
const randomName = 'User' + bot.generateRandomString(6);
const randomPassword = 'Pass' + bot.generateRandomString(10) + '!';
await bot.registerAccount(randomName, randomPassword);
const verificationLink = await bot.waitForVerificationEmail();
await bot.verifyEmail(verificationLink);
await new Promise(resolve => setTimeout(resolve, 3000));
await bot.login();
const credits = await bot.checkCredits();
if (credits.remainingCalls < 1) {
throw new Error('No credits available, trying new account...');
}
const imageResponse = await axios.get(imageUrl, { responseType: 'arraybuffer' });
const imageBuffer = Buffer.from(imageResponse.data);
const uploadedUrl = await bot.uploadImage(imageBuffer, 'image.jpg', imageBuffer.length);
const result = await bot.convertToZombie(uploadedUrl, styleId);
return {
success: true,
styleName: bot.zombieStyles[styleId].name,
email: bot.email,
resultUrl: result.imgUrl,
thumbnailUrl: result.thumbUrl,
width: result.width,
height: result.height,
creditsRemaining: credits.remainingCalls - 1
};
} catch (error) {
if (attempt === maxRetries) {
return {
success: false,
error: error.message,
attemptsUsed: attempt
};
}
await new Promise(resolve => setTimeout(resolve, 2000));
}
}
}
const handler = async (req, res) => {
try {
const { image, style, key } = req.query;
if (!image || !key) {
return res.status(400).json({
success: false,
error: 'Missing required parameters: image and key'
});
}
const styleId = style ? parseInt(style) : 1;
if (styleId < 1 || styleId > 5) {
return res.status(400).json({
success: false,
error: 'Invalid style parameter. Must be between 1-5',
styles: {
1: 'Classic Zombie',
2: 'Walking Dead Zombie',
3: 'Horror Zombie',
4: 'Undead Creature',
5: 'Nightmare Zombie'
}
});
}
const result = await img2zombie(image, styleId);
if (!result.success) {
return res.status(500).json({
success: false,
error: result.error,
attemptsUsed: result.attemptsUsed
});
}
res.json({
author: "Herza",
success: true,
data: {
styleName: result.styleName,
url: result.resultUrl,
thumbnail: result.thumbnailUrl,
width: result.width,
height: result.height,
creditsUsed: 1,
email: result.email
}
});
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
};
module.exports = {
name: 'Image to Zombie Converter',
description: 'Convert photos to zombie style using AI with 5 different zombie themes',
type: 'GET',
routes: ['api/AI/img2zombie'],
tags: ['ai', 'image', 'zombie', 'converter', 'horror'],
main: ['AI'],
parameters: ['image', 'style', 'key'],
enabled: true,
limit: 5,
handler
}; |