diff --git a/index.js b/index.js index c19ee23..fa2dfdd 100644 --- a/index.js +++ b/index.js @@ -58,9 +58,38 @@ app.post('/sms', async (req, res) => { // get file name from URL filename = data.MediaURLs[i].split("/").pop(); out['images'].push({ name: filename, attachment: data.MediaURLs[i] }); - } + } else if (data.MediaURLs[i].includes(".3gp")) { // Weird file format, convert it to mp4 + // get file name from URL + filename = data.MediaURLs[i].split("/").pop(); + // Download the file + await axios.get(data.MediaURLs[i], { + responseType: 'arraybuffer' + }).then(function (response) { + fs.writeFileSync(filename, Buffer.from(response.data)); + } + ).catch(function (error) { + console.log(error); + } + ) + // Convert the file to mp4 + try { + var process = new ffmpeg(filename); + process.then(function (video) { + // now save the new file + // Cut out ext from old filename + filename = filename.split(".")[0]; + video.save(`${filename}.mp4`, function (error, file) { + if (!error) console.log('Video file: ' + file); + // Delete the old file, then push the new one to the array + fs.unlinkSync(`${filename}.3gp`); + out['images'].push({ name: `${filename}.mp4`, attachment: `${filename}.mp4` }); + }); + }, function (err) { + console.log('Error: ' + err); + }); + } } - })(); + })(); hook.send({ content: out['text'], files: out['images'],