File size: 6,992 Bytes
7e9ddb1 |
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 |
const axios = require('axios');
const FormData = require('form-data');
const aiLabs = {
api: {
base: 'https://text2video.aritek.app',
endpoints: {
text2img: '/text2img',
generate: '/txt2videov3',
video: '/video'
}
},
headers: {
'user-agent': 'NB Android/1.0.0',
'accept-encoding': 'gzip',
'content-type': 'application/json',
authorization: ''
},
state: {
token: null
},
setup: {
cipher: 'hbMcgZLlzvghRlLbPcTbCpfcQKM0PcU0zhPcTlOFMxBZ1oLmruzlVp9remPgi0QWP0QW',
shiftValue: 3,
dec(text, shift) {
return [...text].map(c =>
/[a-z]/.test(c)
? String.fromCharCode((c.charCodeAt(0) - 97 - shift + 26) % 26 + 97)
: /[A-Z]/.test(c)
? String.fromCharCode((c.charCodeAt(0) - 65 - shift + 26) % 26 + 65)
: c
).join('');
},
decrypt: async () => {
if (aiLabs.state.token) return aiLabs.state.token;
const input = aiLabs.setup.cipher;
const shift = aiLabs.setup.shiftValue;
const decrypted = aiLabs.setup.dec(input, shift);
aiLabs.state.token = decrypted;
aiLabs.headers.authorization = decrypted;
return decrypted;
}
},
deviceId() {
return Array.from({ length: 16 }, () =>
Math.floor(Math.random() * 16).toString(16)
).join('');
},
text2img: async (prompt) => {
if (!prompt?.trim()) {
return {
success: false,
code: 400,
result: {
error: 'Yang bener aja anjirr, inputnya kosong begitu πΏ'
}
};
}
const token = await aiLabs.setup.decrypt();
const form = new FormData();
form.append('prompt', prompt);
form.append('token', token);
try {
const url = aiLabs.api.base + aiLabs.api.endpoints.text2img;
const res = await axios.post(url, form, {
headers: {
...aiLabs.headers,
...form.getHeaders()
}
});
const { code, url: imageUrl } = res.data;
if (code !== 0 || !imageUrl) {
return {
success: false,
code: res.status,
result: {
error: 'Error bree π'
}
};
}
return {
success: true,
code: res.status,
result: {
url: imageUrl.trim(),
prompt
}
};
} catch (err) {
return {
success: false,
code: err.response?.status || 500,
result: {
error: err.message || 'Error bree π'
}
};
}
},
generate: async ({ prompt = '', type = 'video', isPremium = 1 } = {}) => {
if (!prompt?.trim() || !/^[a-zA-Z0-9\s.,!?'-]+$/.test(prompt)) {
return {
success: false,
code: 400,
result: {
error: 'Promptnya kagak boleh kosong bree.. apalagi ada karakternya aneh begitu :v kagak boleh yak π'
}
};
}
if (!/^(image|video)$/.test(type)) {
return {
success: false,
code: 400,
result: {
error: 'Tipenya kagak valid.. lu bisa pake image atau video yak.. βΊοΈ'
}
};
}
if (type === 'image') {
return await aiLabs.text2img(prompt);
} else {
await aiLabs.setup.decrypt();
const payload = {
deviceID: aiLabs.deviceId(),
isPremium,
prompt,
used: [],
versionCode: 59
};
try {
const url = aiLabs.api.base + aiLabs.api.endpoints.generate;
const res = await axios.post(url, payload, { headers: aiLabs.headers });
const { code, key } = res.data;
if (code !== 0 || !key || typeof key !== 'string') {
return {
success: false,
code: res.status,
result: {
error: 'Heumm.. Gagal bree ngambil Keynya π«΅π»π·'
}
};
}
return await aiLabs.video(key);
} catch (err) {
return {
success: false,
code: err.response?.status || 500,
result: {
error: err.message || 'Error bree... π'
}
};
}
}
},
video: async (key) => {
if (!key || typeof key !== 'string') {
return {
success: false,
code: 400,
result: {
error: 'Keynya kagak valid bree... ππ'
}
};
}
await aiLabs.setup.decrypt();
const payload = { keys: [key] };
const url = aiLabs.api.base + aiLabs.api.endpoints.video;
const maxAttempts = 100;
const delay = 2000;
let attempt = 0;
while (attempt < maxAttempts) {
attempt++;
try {
const res = await axios.post(url, payload, {
headers: aiLabs.headers,
timeout: 15000
});
const { code, datas } = res.data;
if (code === 0 && Array.isArray(datas) && datas.length > 0) {
const data = datas[0];
if (!data.url || data.url.trim() === '') {
await new Promise(r => setTimeout(r, delay));
continue;
}
return {
success: true,
code: res.status,
result: {
url: data.url.trim(),
safe: data.safe === 'true',
key: data.key,
progress: '100%'
}
};
}
} catch (err) {
const retry = ['ECONNRESET', 'ECONNABORTED', 'ETIMEDOUT'].includes(err.code);
if (retry && attempt < maxAttempts) {
await new Promise(r => setTimeout(r, delay));
continue;
}
return {
success: false,
code: err.response?.status || 500,
result: {
error: 'Error bree...',
attempt
}
};
}
}
return {
success: false,
code: 504,
result: {
error: 'Proses videonya kelamaan, keknya lagi ngambek tuh Server AI nya wkwk... ',
attempt
}
};
}
};
const handler = async (req, res) => {
try {
const { prompt } = req.query;
if (!prompt) {
return res.status(400).json({
success: false,
error: 'Missing required parameter: prompt'
});
}
const result = await aiLabs.generate({
prompt: prompt,
type: 'video',
isPremium: 1
});
if (!result.success) {
return res.status(result.code).json({
author: "Herza",
success: false,
error: result.result.error
});
}
res.json({
author: "Herza",
success: true,
result: result.result
});
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
};
module.exports = {
name: 'AI Labs Text to Video',
description: 'Generate video from text prompt using AI Labs',
type: 'GET',
routes: ['api/AI/text2video'],
tags: ['ai', 'video', 'text-to-video', 'generator'],
main: ['AI'],
parameters: ['prompt', 'key'],
enabled: true,
handler
}; |