Create sora2nowm.js
Browse files- plugins/sora2nowm.js +130 -0
plugins/sora2nowm.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
async function videoGenerator(prompt) {
|
| 2 |
+
if (!prompt) return { error: "Prompt tidak boleh kosong" };
|
| 3 |
+
|
| 4 |
+
const videoId = `video_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
|
| 5 |
+
const apiUrl = "https://veo31.ai/api";
|
| 6 |
+
|
| 7 |
+
try {
|
| 8 |
+
const res = await fetch(`${apiUrl}/generate/stream`, {
|
| 9 |
+
method: "POST",
|
| 10 |
+
headers: { "Content-Type": "application/json" },
|
| 11 |
+
body: JSON.stringify({
|
| 12 |
+
prompt,
|
| 13 |
+
aspectRatio: "9:16",
|
| 14 |
+
videoId,
|
| 15 |
+
}),
|
| 16 |
+
});
|
| 17 |
+
|
| 18 |
+
const data = await res.json();
|
| 19 |
+
if (!data.success) return { status: "failed", error: "Error generating video", detail: data };
|
| 20 |
+
|
| 21 |
+
await new Promise((r) => setTimeout(r, 120000));
|
| 22 |
+
|
| 23 |
+
while (true) {
|
| 24 |
+
const check = await fetch(`${apiUrl}/webhook?videoId=${videoId}`);
|
| 25 |
+
const status = await check.json();
|
| 26 |
+
|
| 27 |
+
if (status.status === "completed") {
|
| 28 |
+
return {
|
| 29 |
+
status: "completed",
|
| 30 |
+
videoUrl: status.videoUrl,
|
| 31 |
+
videoId,
|
| 32 |
+
};
|
| 33 |
+
} else if (status.status === "failed") {
|
| 34 |
+
return {
|
| 35 |
+
status: "failed",
|
| 36 |
+
error: status.error || "unknown",
|
| 37 |
+
};
|
| 38 |
+
} else {
|
| 39 |
+
await new Promise((r) => setTimeout(r, 60000));
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
} catch (err) {
|
| 43 |
+
return { status: "error", error: err.message };
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
const handler = async (req, res) => {
|
| 48 |
+
const startTime = Date.now();
|
| 49 |
+
|
| 50 |
+
try {
|
| 51 |
+
const { prompt, key } = req.query;
|
| 52 |
+
|
| 53 |
+
if (!prompt) {
|
| 54 |
+
return res.status(400).json({
|
| 55 |
+
author: 'Herza',
|
| 56 |
+
success: false,
|
| 57 |
+
msg: 'Missing required parameter: prompt',
|
| 58 |
+
usage: '/api/AI/sora2nowm?prompt=your_prompt&key=your_key'
|
| 59 |
+
});
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
if (!key) {
|
| 63 |
+
return res.status(400).json({
|
| 64 |
+
author: 'Herza',
|
| 65 |
+
success: false,
|
| 66 |
+
msg: 'Missing required parameter: key'
|
| 67 |
+
});
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
console.log(`\n${'='.repeat(60)}`);
|
| 71 |
+
console.log('NEW REQUEST RECEIVED');
|
| 72 |
+
console.log(`Prompt: ${prompt}`);
|
| 73 |
+
console.log(`${'='.repeat(60)}\n`);
|
| 74 |
+
|
| 75 |
+
const result = await videoGenerator(prompt);
|
| 76 |
+
|
| 77 |
+
const duration = ((Date.now() - startTime) / 1000).toFixed(2);
|
| 78 |
+
|
| 79 |
+
if (result.status === "completed") {
|
| 80 |
+
console.log(`\n${'='.repeat(60)}`);
|
| 81 |
+
console.log('REQUEST COMPLETED');
|
| 82 |
+
console.log(`Duration: ${duration}s`);
|
| 83 |
+
console.log(`${'='.repeat(60)}\n`);
|
| 84 |
+
|
| 85 |
+
res.json({
|
| 86 |
+
author: 'Herza',
|
| 87 |
+
success: true,
|
| 88 |
+
data: {
|
| 89 |
+
model: 'veo31-sora2',
|
| 90 |
+
prompt: prompt,
|
| 91 |
+
videoUrl: result.videoUrl,
|
| 92 |
+
videoId: result.videoId,
|
| 93 |
+
processingTime: `${duration}s`
|
| 94 |
+
}
|
| 95 |
+
});
|
| 96 |
+
} else {
|
| 97 |
+
throw new Error(result.error || 'Video generation failed');
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
} catch (error) {
|
| 101 |
+
console.error('\n❌ ERROR:', error.message);
|
| 102 |
+
console.error('Stack:', error.stack);
|
| 103 |
+
|
| 104 |
+
const duration = ((Date.now() - startTime) / 1000).toFixed(2);
|
| 105 |
+
|
| 106 |
+
res.status(500).json({
|
| 107 |
+
author: 'Herza',
|
| 108 |
+
success: false,
|
| 109 |
+
msg: error.message || 'Terjadi kesalahan saat generate video.',
|
| 110 |
+
processingTime: `${duration}s`,
|
| 111 |
+
error: {
|
| 112 |
+
code: error.code || 'UNKNOWN',
|
| 113 |
+
details: error.response?.data || null
|
| 114 |
+
}
|
| 115 |
+
});
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
module.exports = {
|
| 120 |
+
name: 'Sora2 Video Generator No Watermark',
|
| 121 |
+
description: 'Generate videos using Sora2 AI model without watermark',
|
| 122 |
+
type: 'GET',
|
| 123 |
+
routes: ['api/AI/sora2nowm'],
|
| 124 |
+
tags: ['AI', 'Sora', 'Video', 'NoWatermark'],
|
| 125 |
+
parameters: ['prompt', 'key'],
|
| 126 |
+
enabled: true,
|
| 127 |
+
main: ['AI'],
|
| 128 |
+
limit: 15,
|
| 129 |
+
handler
|
| 130 |
+
};
|