This commit is contained in:
CHIEFSOFT\ameye
2024-03-26 11:56:50 -04:00
parent 8dc120614c
commit b5c20f71d2
+44 -38
View File
@@ -68,51 +68,57 @@ app.get('/videos/:filename', (req, res)=>{
if ( result.rowCount === 1){
findFilename = result.rows[0].filename;
}
//const filePath = videoFileMap[fileName]
const completeFile = process.env.COMMON_MEDIA_PATH + findFilename;
if(!completeFile){
console.log("Finding File Not Found ", completeFile);
return res.status(404).send('File not found')
}
console.log("Finding File Found ", completeFile);
const stat = fs.statSync(completeFile);
const fileSize = stat.size;
const range = req.headers.range;
if(range){
const parts = range.replace(/bytes=/, '').split('-')
const start = parseInt(parts[0], 10);
const end = parts[1] ? parseInt(parts[1], 10) : fileSize - 1;
const chunksize = end - start + 1;
const file = fs.createReadStream(completeFile, {start, end});
const head = {
'Content-Range': `bytes ${start}-${end}/${fileSize}`,
'Accept-Ranges': 'bytes',
'Content-Length': chunksize,
'Content-Type': 'video/mp4'
};
res.writeHead(206, head);
file.pipe(res);
}
else{
const head = {
'Content-Length': fileSize,
'Content-Type': 'video/mp4'
};
res.writeHead(200, head);
fs.createReadStream(completeFile).pipe(res)
}
} catch (e) {
console.log("ERR->",e.message);
}
});
//const filePath = videoFileMap[fileName]
const completeFile = process.env.COMMON_MEDIA_PATH + findFilename;
if(!completeFile){
console.log("Finding File Not Found ", completeFile);
return res.status(404).send('File not found')
}
console.log("Finding File Found ", completeFile);
const stat = fs.statSync(completeFile);
const fileSize = stat.size;
const range = req.headers.range;
if(range){
const parts = range.replace(/bytes=/, '').split('-')
const start = parseInt(parts[0], 10);
const end = parts[1] ? parseInt(parts[1], 10) : fileSize - 1;
const chunksize = end - start + 1;
const file = fs.createReadStream(completeFile, {start, end});
const head = {
'Content-Range': `bytes ${start}-${end}/${fileSize}`,
'Accept-Ranges': 'bytes',
'Content-Length': chunksize,
'Content-Type': 'video/mp4'
};
res.writeHead(206, head);
file.pipe(res);
}
else{
const head = {
'Content-Length': fileSize,
'Content-Type': 'video/mp4'
};
res.writeHead(200, head);
fs.createReadStream(completeFile).pipe(res)
}
})
app.listen(3036, ()=>{