Spaces:
Sleeping
Sleeping
Update plugins/nanobanana-txt2img.js
Browse files- plugins/nanobanana-txt2img.js +21 -59
plugins/nanobanana-txt2img.js
CHANGED
|
@@ -1,14 +1,6 @@
|
|
| 1 |
-
/*
|
| 2 |
-
@ author: Herza
|
| 3 |
-
@ type : CommonJS
|
| 4 |
-
@ ========> Info <=========
|
| 5 |
-
@ github: https://github.com/herzonly
|
| 6 |
-
@ wa_channel: https://whatsapp.com/channel/0029VaGVOvq1iUxY6WgHLv2R
|
| 7 |
-
*/
|
| 8 |
-
|
| 9 |
const axios = require('axios');
|
| 10 |
|
| 11 |
-
async function
|
| 12 |
const tempMailClient = axios.create({
|
| 13 |
baseURL: 'https://api.internal.temp-mail.io/api/v3',
|
| 14 |
headers: {
|
|
@@ -24,7 +16,10 @@ async function createAccount() {
|
|
| 24 |
max_name_length: 10
|
| 25 |
});
|
| 26 |
|
| 27 |
-
await axios.post('https://nanobanana.ai/api/auth/send-code', {
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
await new Promise(resolve => setTimeout(resolve, 5000));
|
| 30 |
|
|
@@ -39,39 +34,15 @@ async function createAccount() {
|
|
| 39 |
{ headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }
|
| 40 |
);
|
| 41 |
|
| 42 |
-
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
async function imageEdit(imageUrls, prompt, cookies) {
|
| 46 |
-
if (!Array.isArray(imageUrls) || imageUrls.length === 0 || imageUrls.length > 9) {
|
| 47 |
-
throw new Error('imageUrls must be an array with 1-9 URLs');
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
const uploadedUrls = [];
|
| 51 |
-
for (const imageUrl of imageUrls) {
|
| 52 |
-
const imageResp = await axios.get(imageUrl, { responseType: 'arraybuffer' });
|
| 53 |
-
const contentType = imageResp.headers['content-type'] || 'image/jpeg';
|
| 54 |
-
const fileSize = imageResp.data.length;
|
| 55 |
-
|
| 56 |
-
const { data: { uploadUrl, publicUrl } } = await axios.post(
|
| 57 |
-
'https://nanobanana.ai/api/get-upload-url',
|
| 58 |
-
{ fileName: `image_${Date.now()}.jpg`, contentType, fileSize },
|
| 59 |
-
{ headers: { Cookie: cookies } }
|
| 60 |
-
);
|
| 61 |
-
|
| 62 |
-
await axios.put(uploadUrl, imageResp.data, { headers: { 'Content-Type': contentType } });
|
| 63 |
-
|
| 64 |
-
uploadedUrls.push(publicUrl);
|
| 65 |
-
}
|
| 66 |
|
| 67 |
const { data: { taskId } } = await axios.post(
|
| 68 |
'https://nanobanana.ai/api/generate-image',
|
| 69 |
{
|
| 70 |
prompt,
|
| 71 |
styleId: 'realistic',
|
| 72 |
-
mode: '
|
| 73 |
-
imageUrl:
|
| 74 |
-
imageUrls: uploadedUrls,
|
| 75 |
imageSize: '1024*1024',
|
| 76 |
numImages: 1,
|
| 77 |
outputFormat: 'png',
|
|
@@ -88,7 +59,9 @@ async function imageEdit(imageUrls, prompt, cookies) {
|
|
| 88 |
{ headers: { Cookie: cookies } }
|
| 89 |
);
|
| 90 |
|
| 91 |
-
if (data.status === 'completed')
|
|
|
|
|
|
|
| 92 |
|
| 93 |
await new Promise(resolve => setTimeout(resolve, 3000));
|
| 94 |
}
|
|
@@ -96,25 +69,16 @@ async function imageEdit(imageUrls, prompt, cookies) {
|
|
| 96 |
|
| 97 |
const handler = async (req, res) => {
|
| 98 |
try {
|
| 99 |
-
const {
|
| 100 |
-
|
| 101 |
-
if (!prompt) {
|
| 102 |
-
return res.status(400).json({
|
| 103 |
-
success: false,
|
| 104 |
-
error: 'Missing required parameter: prompt'
|
| 105 |
-
});
|
| 106 |
-
}
|
| 107 |
|
| 108 |
-
if (!
|
| 109 |
return res.status(400).json({
|
| 110 |
success: false,
|
| 111 |
-
error: 'Missing required parameter:
|
| 112 |
});
|
| 113 |
}
|
| 114 |
|
| 115 |
-
const
|
| 116 |
-
const cookies = await createAccount();
|
| 117 |
-
const imageUrl = await imageEdit(urls, prompt, cookies);
|
| 118 |
|
| 119 |
res.json({
|
| 120 |
author: "Herza",
|
|
@@ -131,15 +95,13 @@ const handler = async (req, res) => {
|
|
| 131 |
};
|
| 132 |
|
| 133 |
module.exports = {
|
| 134 |
-
name: 'Text2IMG
|
| 135 |
-
description: '
|
| 136 |
type: 'GET',
|
| 137 |
-
routes: ['api/AI/
|
| 138 |
-
tags: ['ai', 'text2img', 'nanobanana'
|
| 139 |
main: ['AI'],
|
| 140 |
-
parameters: ['
|
| 141 |
enabled: true,
|
| 142 |
handler
|
| 143 |
-
};
|
| 144 |
-
|
| 145 |
-
/*This Code Uploaded By NotMeBotz - MD, DO NOT DELETE WM | | Sunday, 26 October 2025 || 15:47:26 WIB */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
const axios = require('axios');
|
| 2 |
|
| 3 |
+
async function text2img(prompt) {
|
| 4 |
const tempMailClient = axios.create({
|
| 5 |
baseURL: 'https://api.internal.temp-mail.io/api/v3',
|
| 6 |
headers: {
|
|
|
|
| 16 |
max_name_length: 10
|
| 17 |
});
|
| 18 |
|
| 19 |
+
await axios.post('https://nanobanana.ai/api/auth/send-code', {
|
| 20 |
+
email,
|
| 21 |
+
locale: 'en'
|
| 22 |
+
});
|
| 23 |
|
| 24 |
await new Promise(resolve => setTimeout(resolve, 5000));
|
| 25 |
|
|
|
|
| 34 |
{ headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }
|
| 35 |
);
|
| 36 |
|
| 37 |
+
const cookies = headers['set-cookie'].join('; ');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
const { data: { taskId } } = await axios.post(
|
| 40 |
'https://nanobanana.ai/api/generate-image',
|
| 41 |
{
|
| 42 |
prompt,
|
| 43 |
styleId: 'realistic',
|
| 44 |
+
mode: 'text',
|
| 45 |
+
imageUrl: null,
|
|
|
|
| 46 |
imageSize: '1024*1024',
|
| 47 |
numImages: 1,
|
| 48 |
outputFormat: 'png',
|
|
|
|
| 59 |
{ headers: { Cookie: cookies } }
|
| 60 |
);
|
| 61 |
|
| 62 |
+
if (data.status === 'completed') {
|
| 63 |
+
return data.imageUrl;
|
| 64 |
+
}
|
| 65 |
|
| 66 |
await new Promise(resolve => setTimeout(resolve, 3000));
|
| 67 |
}
|
|
|
|
| 69 |
|
| 70 |
const handler = async (req, res) => {
|
| 71 |
try {
|
| 72 |
+
const { text } = req.query;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
if (!text) {
|
| 75 |
return res.status(400).json({
|
| 76 |
success: false,
|
| 77 |
+
error: 'Missing required parameter: text'
|
| 78 |
});
|
| 79 |
}
|
| 80 |
|
| 81 |
+
const imageUrl = await text2img(text);
|
|
|
|
|
|
|
| 82 |
|
| 83 |
res.json({
|
| 84 |
author: "Herza",
|
|
|
|
| 95 |
};
|
| 96 |
|
| 97 |
module.exports = {
|
| 98 |
+
name: 'Text2IMG NanoBanana',
|
| 99 |
+
description: 'Generate Image using NanoBanana AI',
|
| 100 |
type: 'GET',
|
| 101 |
+
routes: ['api/AI/text2img-nano'],
|
| 102 |
+
tags: ['ai', 'text2img', 'nanobanana'],
|
| 103 |
main: ['AI'],
|
| 104 |
+
parameters: ['text'],
|
| 105 |
enabled: true,
|
| 106 |
handler
|
| 107 |
+
};
|
|
|
|
|
|