Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const axios = require("axios");
- const { v4: uuidv4 } = require("uuid");
- const BASE_URL = "https://visualgpt.io/api/v1/prediction";
- function generateCookie() {
- const gaId = Math.floor(Math.random() * 1e10);
- const gaSession = `GA1.1.${gaId}.${Date.now()}`;
- const sboxGuid = Buffer.from(`${Date.now()}|${Math.random()}`).toString("base64");
- const crispSession = `session_${uuidv4()}`;
- const anonId = uuidv4();
- return `_ga=${gaSession}; _ga_PZ8PZQP57J=GS2.1.s${Date.now()}$o1$g0$t${Date.now()}$j60$l0$h0; sbox-guid=${sboxGuid}; crisp-client%2Fsession%2F${uuidv4()}=${crispSession}; anonymous_user_id=${anonId}`;
- }
- function buildHeaders() {
- const anonId = uuidv4();
- const cookie = generateCookie();
- return {
- post: {
- "user-agent":
- "Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124",
- "content-type": "application/json; charset=UTF-8",
- origin: "https://visualgpt.io",
- referer: "https://visualgpt.io/ai-models/nano-banana",
- cookie
- },
- get: {
- "user-agent":
- "Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124",
- accept: "application/json, text/plain, */*",
- origin: "https://visualgpt.io",
- referer: "https://visualgpt.io/ai-models/nano-banana",
- cookie
- }
- };
- }
- async function generateImage(imageUrls, prompt) {
- if (!prompt || typeof prompt !== "string") {
- throw new Error("❌ Prompt kosong atau tidak valid");
- }
- if (!Array.isArray(imageUrls) || imageUrls.length < 1 || imageUrls.length > 2) {
- throw new Error("❌ Harus kirim array berisi 1 atau 2 URL gambar");
- }
- if (imageUrls.some((u) => !u || typeof u !== "string")) {
- throw new Error("❌ URL gambar tidak valid: " + JSON.stringify(imageUrls));
- }
- const headers = buildHeaders();
- let body = {
- image_urls: imageUrls,
- type: 61,
- user_prompt: prompt,
- sub_type: 2,
- aspect_ratio: "",
- num: ""
- };
- if (imageUrls.length === 1) {
- body.max_images = 1;
- body.size = "";
- }
- const postRes = await axios.post(`${BASE_URL}/handle`, body, {
- headers: headers.post
- });
- if (!postRes.data || postRes.data.code !== 100000) {
- throw new Error("❌ Handle gagal: " + JSON.stringify(postRes.data));
- }
- const sessionId = postRes.data.data.session_id;
- const start = Date.now();
- while (true) {
- await new Promise((r) => setTimeout(r, 3000));
- if (Date.now() - start > 60000) {
- throw new Error("❌ Timeout menunggu hasil");
- }
- const getRes = await axios.get(
- `${BASE_URL}/get-status?session_id=${sessionId}`,
- { headers: headers.get }
- );
- if (getRes.data?.data?.status === "succeeded") {
- const results = getRes.data.data.results;
- if (!Array.isArray(results) || results.length === 0) {
- throw new Error("❌ Tidak ada hasil dari VisualGPT");
- }
- const finalUrls = results.flatMap(r => r.urls || []);
- return finalUrls;
- }
- }
- }
- module.exports = { generateImage };
Comments
-
- Bisa buat tofigure?
-
- bisalah , tinggal kasih prompt aja
-
- min error 404
Add Comment
Please, Sign In to add comment