import axios from "axios"; function ip() { const x = (a) => (Math.random() * a).toFixed(); return `${x(300)}.${x(300)}.${x(300)}.${x(300)}`; } export default async function txt2img(prompt) { try { return new Promise((resolve, reject) => { if(!prompt) throw "missing prompt input"; axios.post("https://internal.users.n8n.cloud/webhook/ai_image_generator", { prompt }, { headers: { 'Content-Type': 'application/json', 'User-Agent': 'Zanixon/1.0.0', 'X-Client-Ip': ip() } }).then(raw => { const data = raw.data; if(!data.result) throw "failed generatig image"; resolve({ success: true, images: data.result }) }).catch(reject) }) } catch (e) { return { success: true, errors: e } } } txt2img("kucing lucu berjalan di pinggir trotoar") .then(console.log) .catch(console.log)