mirror of
https://github.com/cheveguerra/ws-api-node.git
synced 2026-04-17 19:36:23 +00:00
fix: validacion de url de imagen valida.
This commit is contained in:
@@ -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' })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user