fix final

This commit is contained in:
The Ghost of FOSS' Past 2024-10-28 11:50:23 -05:00
parent eae840c54e
commit bd7b0d65f3

View file

@ -62,7 +62,7 @@ app.get('/download', (req, res) => {
}
// Set the output file path
var outputPath = path.join('/tmp/downloads', `${getRandomHex()}.mp4`);
var outputPath = path.join('/tmp/downloads', `${getRandomHex()}`);
// Create /tmp/downloads directory if it doesn't exist
try {
@ -81,17 +81,18 @@ app.get('/download', (req, res) => {
console.log('yt-dlp output:', stdout);
const downloadedFilePath = outputPath;
const downloadedFilePath = `${outputPath}.webm`;
console.log('Downloaded file path:', downloadedFilePath);
if (!downloadedFilePath || !fs.existsSync(downloadedFilePath)) {
console.log(`${downloadedFilePath}`)
console.error('Error: Downloaded file not found or invalid path.');
return res.status(500).json({ error: 'Downloaded file not found or invalid path.' });
}
// Send the file
res.download(downloadedFilePath, (err) => {
res.sendFile(downloadedFilePath, (err) => {
if (err) {
console.error('Error sending the file:', err);
return res.status(500).json({ error: 'Failed to send the file.', details: err.message });