fix: validacion de url de imagen valida.

This commit is contained in:
2023-01-14 04:52:08 -06:00
parent f5468835bf
commit c4d22e38f6

View File

@@ -50,18 +50,21 @@ router.post('/sendimage/', async (req,res) => {
if (!fs.existsSync('./temp')) { if (!fs.existsSync('./temp')) {
await fs.mkdirSync('./temp'); await fs.mkdirSync('./temp');
} }
var path = './temp/' + image.split("/").slice(-1)[0] var path = './temp/' + image.split("/").slice(-1)[0]
mediadownloader(image, path, () => { if (fs.existsSync(path)){
let media = MessageMedia.fromFilePath(path); mediadownloader(image, path, () => {
let media = MessageMedia.fromFilePath(path);
client.sendMessage(`${phone}@c.us`, media, { caption: caption || '' }).then((response) => { client.sendMessage(`${phone}@c.us`, media, { caption: caption || '' }).then((response) => {
if (response.id.fromMe) { if (response.id.fromMe) {
res.send({ status: 'success', message: `MediaMessage successfully sent to ${phone}` }) res.send({ status: 'success', message: `MediaMessage successfully sent to ${phone}` })
fs.unlinkSync(path) fs.unlinkSync(path)
} }
}); });
}) })
} else {
console.log("La imagen no existe o no se pudo descargar.")
res.send({ status:'error', message: 'Invalid URL/Base64 Encoded Media' })
}
} else { } else {
res.send({ status:'error', message: 'Invalid URL/Base64 Encoded Media' }) res.send({ status:'error', message: 'Invalid URL/Base64 Encoded Media' })
} }