diff --git a/index.js b/index.js index 31b4a69..2154a15 100644 --- a/index.js +++ b/index.js @@ -59,43 +59,45 @@ app.post('/sms', async (req, res) => { 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` }); + await (async () => { + // 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); }); - }, function (err) { - console.log('Error: ' + err); - }); - } - catch (e) { - console.log(e.code); - console.log(e.msg); - } + } + catch (e) { + console.log(e.code); + console.log(e.msg); + } + })(); } } - })(); + })(); hook.send({ content: out['text'], files: out['images'],