fix final
This commit is contained in:
parent
eae840c54e
commit
bd7b0d65f3
1 changed files with 4 additions and 3 deletions
7
index.js
7
index.js
|
@ -62,7 +62,7 @@ app.get('/download', (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the output file path
|
// 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
|
// Create /tmp/downloads directory if it doesn't exist
|
||||||
try {
|
try {
|
||||||
|
@ -81,17 +81,18 @@ app.get('/download', (req, res) => {
|
||||||
|
|
||||||
console.log('yt-dlp output:', stdout);
|
console.log('yt-dlp output:', stdout);
|
||||||
|
|
||||||
const downloadedFilePath = outputPath;
|
const downloadedFilePath = `${outputPath}.webm`;
|
||||||
|
|
||||||
console.log('Downloaded file path:', downloadedFilePath);
|
console.log('Downloaded file path:', downloadedFilePath);
|
||||||
|
|
||||||
if (!downloadedFilePath || !fs.existsSync(downloadedFilePath)) {
|
if (!downloadedFilePath || !fs.existsSync(downloadedFilePath)) {
|
||||||
|
console.log(`${downloadedFilePath}`)
|
||||||
console.error('Error: Downloaded file not found or invalid path.');
|
console.error('Error: Downloaded file not found or invalid path.');
|
||||||
return res.status(500).json({ error: 'Downloaded file not found or invalid path.' });
|
return res.status(500).json({ error: 'Downloaded file not found or invalid path.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the file
|
// Send the file
|
||||||
res.download(downloadedFilePath, (err) => {
|
res.sendFile(downloadedFilePath, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error sending the file:', err);
|
console.error('Error sending the file:', err);
|
||||||
return res.status(500).json({ error: 'Failed to send the file.', details: err.message });
|
return res.status(500).json({ error: 'Failed to send the file.', details: err.message });
|
||||||
|
|
Loading…
Reference in a new issue