/* * Lokasi: features/image-describe.js * Versi: v1 */ const axios = require('axios'); const crypto = require('crypto'); async function sendCallback(url, payload) { try { await axios.post(url, payload, { headers: { 'Content-Type': 'application/json' } }); } catch (error) { console.error('Callback failed:', error.message); } } module.exports = async function(req, res) { const { imageUrl, prompt, jobId, callbackUrl, callbackKey } = req.body; if (!imageUrl || !prompt || !jobId || !callbackUrl || !callbackKey) { return res.status(400).json({ error: 'Missing required parameters.' }); } res.status(202).json({ message: 'Job accepted and is being processed.' }); try { const visitorId = crypto.randomBytes(16).toString('hex'); const headerF = crypto.createHash('md5').update(visitorId).digest('hex'); const chatPayload = { message: prompt, image: imageUrl, history: [], lang: 'en' }; const chatResponse = await axios.post( 'https://imagedescriber.online/api/chat-with-image', chatPayload, { headers: { 'Content-Type': 'application/json', 'f': headerF, 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; RMX2185 Build/QP1A.190711.020) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.7151.118 Mobile Safari/537.36', 'Referer': 'https://imagedescriber.online/tools/chat-with-image-ai' } } ); await sendCallback(callbackUrl, { jobId, callbackKey, status: 'success', result: { response: chatResponse.data }, }); } catch (e) { await sendCallback(callbackUrl, { jobId, callbackKey, status: 'failed', result: { error: e.message || 'An unknown error occurred during image description.' }, }); } };