This commit is contained in:
Christopher Cookman 2023-08-18 20:21:51 -06:00
parent 7672cd382a
commit ec637d1fa1
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -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'],