| const axios = require('axios') | |
| const FormData = require('form-data') | |
| const fetch = require('node-fetch') | |
| const handler = async (req, res) => { | |
| try { | |
| const { text } = req.query; | |
| if (!text) { | |
| return res.status(400).json({ | |
| success: false, | |
| error: 'Missing required parameter: text' | |
| }); | |
| } | |
| let result = await axios.get(`https://ab-text-toimgfast.abrahamdw882.workers.dev/?text=${encodeURIComponent(text)}`, { | |
| responseType: 'arraybuffer' | |
| }) | |
| let buffer = Buffer.from(result.data) | |
| let form = new FormData() | |
| form.append('file', buffer, { | |
| filename: 'image.webp', | |
| contentType: 'image/webp' | |
| }) | |
| let uploadRes = await fetch('https://tmpfiles.org/api/v1/upload', { | |
| method: 'POST', | |
| body: form | |
| }) | |
| let uploadData = await uploadRes.json() | |
| let fileUrl = uploadData.data.url.replace('tmpfiles.org/', 'tmpfiles.org/dl/') | |
| res.json({ | |
| author: "Herza", | |
| success: true, | |
| url: fileUrl | |
| }); | |
| } catch (error) { | |
| res.status(500).json({ | |
| success: false, | |
| error: error.message | |
| }); | |
| } | |
| }; | |
| module.exports = { | |
| name: 'Text2IMG AI', | |
| description: 'Generate Image using OpenAI ChatGPT', | |
| type: 'GET', | |
| routes: ['api/AI/text2img'], | |
| tags: ['ai', 'text2img', 'openai'], | |
| main: ['AI'], | |
| parameters: ['text'], | |
| enabled: true, | |
| handler | |
| }; |