HerzaJ commited on
Commit
6893e4d
·
verified ·
1 Parent(s): 7235248

Update plugins/sora2-img2vid.js

Browse files
Files changed (1) hide show
  1. plugins/sora2-img2vid.js +102 -16
plugins/sora2-img2vid.js CHANGED
@@ -63,6 +63,13 @@ async function proxyRequest(url, options = {}) {
63
  axiosConfig.url = PROXY_URL;
64
  const response = await axios(axiosConfig);
65
 
 
 
 
 
 
 
 
66
  if (response.status === 403) {
67
  await randomDelay(3000, 5000);
68
  throw new Error('API Bylo returned 403 Forbidden');
@@ -87,6 +94,12 @@ async function proxyRequest(url, options = {}) {
87
  if (attempt < 3) await randomDelay(2000, 4000);
88
 
89
  } catch (error) {
 
 
 
 
 
 
90
  lastError = error;
91
  if (attempt < 3) {
92
  const waitTime = 3000 * attempt;
@@ -213,15 +226,8 @@ async function registerAccount(email, password, verificationCode) {
213
  async function createVideoFromImage(prompt, imageUrl, ratio, duration, authToken, email) {
214
  await randomDelay(2000, 3000);
215
 
216
- const { data } = await proxyRequest('/aimodels/api/v1/ai/video/create', {
217
- method: 'POST',
218
- headers: {
219
- 'Content-Type': 'application/json',
220
- 'uniqueid': generateUniqueId(),
221
- 'verify': '',
222
- 'authorization': authToken
223
- },
224
- data: {
225
  prompt: prompt,
226
  channel: 'SORA2',
227
  pageId: 536,
@@ -235,14 +241,71 @@ async function createVideoFromImage(prompt, imageUrl, ratio, duration, authToken
235
  aspectRatio: ratio,
236
  imageUrls: [imageUrl],
237
  email: email
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  }
239
- });
240
 
241
- if (data.code !== 200) {
242
- throw new Error(`Failed to create video: ${data.message || 'Unknown error'}`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  }
244
 
245
- return data.data;
246
  }
247
 
248
  async function getTaskStatus(taskId, authToken) {
@@ -272,6 +335,8 @@ async function waitForVideoCompletion(taskId, authToken) {
272
  await randomDelay(5000, 7000);
273
  const taskData = await getTaskStatus(taskId, authToken);
274
 
 
 
275
  if (taskData.state === 1 && taskData.completeData) {
276
  const completeData = JSON.parse(taskData.completeData);
277
  return completeData.data.result_urls[0];
@@ -288,15 +353,30 @@ async function waitForVideoCompletion(taskId, authToken) {
288
  }
289
 
290
  async function sora2ImageToVideo(prompt, imageUrl, ratio = 'portrait', duration = 10) {
 
291
  const tempMail = await createTempEmail();
292
  const email = tempMail.email;
293
  const password = generatePassword();
 
294
 
 
295
  await sendVerificationEmail(email);
 
 
296
  const verificationCode = await getVerificationCode(email);
 
 
 
297
  const authToken = await registerAccount(email, password, verificationCode);
 
 
 
298
  const taskId = await createVideoFromImage(prompt, imageUrl, ratio, duration, authToken, email);
 
 
 
299
  const videoUrl = await waitForVideoCompletion(taskId, authToken);
 
300
 
301
  return {
302
  success: true,
@@ -386,14 +466,20 @@ const handler = async (req, res) => {
386
 
387
  const processingTime = ((Date.now() - startTime) / 1000).toFixed(2);
388
 
389
- res.status(500).json({
 
 
 
 
 
390
  author: 'Herza',
391
  success: false,
392
- msg: error.message || 'Terjadi kesalahan saat generate video.',
393
  processingTime: `${processingTime}s`,
394
  error: {
395
  code: error.code || 'UNKNOWN',
396
- details: error.response?.data || null
 
397
  }
398
  });
399
  }
 
63
  axiosConfig.url = PROXY_URL;
64
  const response = await axios(axiosConfig);
65
 
66
+ console.log(`[Proxy] Status: ${response.status}, URL: ${targetPath}`);
67
+
68
+ if (response.status === 500) {
69
+ console.error('[Proxy] 500 Error Details:', JSON.stringify(response.data));
70
+ throw new Error(`Proxy server error: ${JSON.stringify(response.data)}`);
71
+ }
72
+
73
  if (response.status === 403) {
74
  await randomDelay(3000, 5000);
75
  throw new Error('API Bylo returned 403 Forbidden');
 
94
  if (attempt < 3) await randomDelay(2000, 4000);
95
 
96
  } catch (error) {
97
+ console.error('[Proxy] Request failed:', {
98
+ url: targetPath,
99
+ status: error.response?.status,
100
+ data: error.response?.data,
101
+ message: error.message
102
+ });
103
  lastError = error;
104
  if (attempt < 3) {
105
  const waitTime = 3000 * attempt;
 
226
  async function createVideoFromImage(prompt, imageUrl, ratio, duration, authToken, email) {
227
  await randomDelay(2000, 3000);
228
 
229
+ const payloadVariants = [
230
+ {
 
 
 
 
 
 
 
231
  prompt: prompt,
232
  channel: 'SORA2',
233
  pageId: 536,
 
241
  aspectRatio: ratio,
242
  imageUrls: [imageUrl],
243
  email: email
244
+ },
245
+ {
246
+ prompt: prompt,
247
+ channel: 'SORA2',
248
+ pageId: 536,
249
+ source: 'bylo.ai',
250
+ watermarkFlag: false,
251
+ privateFlag: false,
252
+ isTemp: true,
253
+ model: 'sora_video2',
254
+ videoType: 'image-to-video',
255
+ duration: duration.toString(),
256
+ aspectRatio: ratio,
257
+ imageUrl: imageUrl,
258
+ email: email
259
+ },
260
+ {
261
+ prompt: prompt,
262
+ channel: 'SORA2',
263
+ pageId: 536,
264
+ source: 'bylo.ai',
265
+ watermarkFlag: false,
266
+ privateFlag: false,
267
+ isTemp: true,
268
+ model: 'sora_video2',
269
+ videoType: 'image-to-video',
270
+ duration: duration.toString(),
271
+ aspectRatio: ratio,
272
+ image: imageUrl,
273
+ email: email
274
  }
275
+ ];
276
 
277
+ let lastError = null;
278
+
279
+ for (let i = 0; i < payloadVariants.length; i++) {
280
+ try {
281
+ console.log(`[DEBUG] Trying payload variant ${i + 1}:`, JSON.stringify(payloadVariants[i], null, 2));
282
+
283
+ const { data } = await proxyRequest('/aimodels/api/v1/ai/video/create', {
284
+ method: 'POST',
285
+ headers: {
286
+ 'Content-Type': 'application/json',
287
+ 'uniqueid': generateUniqueId(),
288
+ 'verify': '',
289
+ 'authorization': authToken
290
+ },
291
+ data: payloadVariants[i]
292
+ });
293
+
294
+ console.log('[DEBUG] Response:', JSON.stringify(data, null, 2));
295
+
296
+ if (data.code === 200) {
297
+ return data.data;
298
+ }
299
+
300
+ lastError = new Error(`Failed with code ${data.code}: ${data.message || data.msg || 'Unknown error'}`);
301
+
302
+ } catch (error) {
303
+ console.error(`[DEBUG] Payload variant ${i + 1} failed:`, error.message);
304
+ lastError = error;
305
+ }
306
  }
307
 
308
+ throw lastError || new Error('All payload variants failed');
309
  }
310
 
311
  async function getTaskStatus(taskId, authToken) {
 
335
  await randomDelay(5000, 7000);
336
  const taskData = await getTaskStatus(taskId, authToken);
337
 
338
+ console.log(`[Progress] Attempt ${attempts + 1}/${maxAttempts} - State: ${taskData.state}`);
339
+
340
  if (taskData.state === 1 && taskData.completeData) {
341
  const completeData = JSON.parse(taskData.completeData);
342
  return completeData.data.result_urls[0];
 
353
  }
354
 
355
  async function sora2ImageToVideo(prompt, imageUrl, ratio = 'portrait', duration = 10) {
356
+ console.log('[1/6] Creating temporary email...');
357
  const tempMail = await createTempEmail();
358
  const email = tempMail.email;
359
  const password = generatePassword();
360
+ console.log(`[Email] ${email}`);
361
 
362
+ console.log('[2/6] Sending verification email...');
363
  await sendVerificationEmail(email);
364
+
365
+ console.log('[3/6] Waiting for verification code...');
366
  const verificationCode = await getVerificationCode(email);
367
+ console.log(`[Code] ${verificationCode}`);
368
+
369
+ console.log('[4/6] Registering account...');
370
  const authToken = await registerAccount(email, password, verificationCode);
371
+ console.log('[Auth] Token received');
372
+
373
+ console.log('[5/6] Creating video task...');
374
  const taskId = await createVideoFromImage(prompt, imageUrl, ratio, duration, authToken, email);
375
+ console.log(`[Task ID] ${taskId}`);
376
+
377
+ console.log('[6/6] Waiting for video completion...');
378
  const videoUrl = await waitForVideoCompletion(taskId, authToken);
379
+ console.log(`[Video URL] ${videoUrl}`);
380
 
381
  return {
382
  success: true,
 
466
 
467
  const processingTime = ((Date.now() - startTime) / 1000).toFixed(2);
468
 
469
+ const errorMessage = error.response?.data?.error ||
470
+ error.response?.data?.message ||
471
+ error.message ||
472
+ 'Unknown error occurred';
473
+
474
+ res.status(error.response?.status || 500).json({
475
  author: 'Herza',
476
  success: false,
477
+ msg: errorMessage,
478
  processingTime: `${processingTime}s`,
479
  error: {
480
  code: error.code || 'UNKNOWN',
481
+ statusCode: error.response?.status,
482
+ details: error.response?.data || error.message
483
  }
484
  });
485
  }