This commit is contained in:
Christopher Cookman 2023-08-18 20:23:38 -06:00
parent c4cca8c929
commit de148ab579
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

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