feat: Delete tmp folder after send video

This commit is contained in:
GiovaniFZ 2024-10-19 15:46:02 -03:00
parent 94630ac0f0
commit 2795eed14f

View File

@ -1,6 +1,7 @@
const { exec } = require('child_process'); const { exec } = require('child_process');
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
const path = require('path'); const path = require('path');
const fs = require('fs');
const os = require('os'); const os = require('os');
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
const { getStrings } = require('../plugins/checklang.js'); const { getStrings } = require('../plugins/checklang.js');
@ -15,7 +16,7 @@ const ffmpegPaths = {
return ffmpegPaths[platform] || ffmpegPaths.linux; return ffmpegPaths[platform] || ffmpegPaths.linux;
}; };
function getVideo(command) { async function getVideo(command) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => { exec(command, (error, stdout, stderr) => {
if (error) { if (error) {
@ -35,7 +36,7 @@ module.exports = (bot) => {
const mp4File = userId + '.f137.mp4'; const mp4File = userId + '.f137.mp4';
const webmFile = userId + '.f251.webm'; const webmFile = userId + '.f251.webm';
const ffmpegCommand = 'cd tmp && ' + ffmpegPath + ' -i ' + mp4File + ' -i ' + webmFile + ' -c:v copy -c:a copy -strict -2 output.mp4'; const ffmpegCommand = 'cd tmp && ' + ffmpegPath + ' -i ' + mp4File + ' -i ' + webmFile + ' -c:v copy -c:a copy -strict -2 output.mp4';
getVideo(ffmpegCommand); await getVideo(ffmpegCommand);
const message = strings.ytUploadDesc const message = strings.ytUploadDesc
.replace("{userId}", userId) .replace("{userId}", userId)
.replace("{userName}", ctx.from.first_name); .replace("{userName}", ctx.from.first_name);
@ -51,5 +52,7 @@ module.exports = (bot) => {
reply_to_message_id: ctx.message.message_id reply_to_message_id: ctx.message.message_id
}); });
} }
// Delete tmp folder
fs.rmSync('tmp', { recursive: true, force: true })
}); });
} }