fix load
This commit is contained in:
@@ -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, ()=>{
|
||||
|
||||
Reference in New Issue
Block a user