File size: 1,821 Bytes
8065f56 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | /*
* 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.' },
});
}
}; |