task files
This commit is contained in:
@@ -395,6 +395,85 @@ app.get('/myfile/:filename', (req, res)=>{
|
||||
|
||||
|
||||
})
|
||||
|
||||
app.get('/mytask/:filename', (req, res)=>{
|
||||
const fileName = req.params.filename;
|
||||
let findFilename = 'What Is Single Sign-on (SSO)? How It Works-(1080p25).mp4';
|
||||
let memberUID = '';
|
||||
let myfilesCommonPath = process.env.COMMON_MYFILE_PATH;
|
||||
console.log("myfilesCommonPath ==> " + myfilesCommonPath);
|
||||
// var findFilename = '';
|
||||
//c35c32bc-9ce4-4ca5-9afc-1ecddfd649f5
|
||||
let Qstring = "SELECT mf.*, m.uid AS member_uid FROM members_jobs_files mf LEFT JOIN members m ON m.uid=mf.member_uid WHERE mf.uid='"+fileName+"'";
|
||||
console.log("Qstring -> ", Qstring);
|
||||
db.query(Qstring, function (err, result) {
|
||||
try {
|
||||
console.log("BEFORE ERR CHECK -> " , result);
|
||||
if (err){
|
||||
console.log("IN ERR CHECK -> " , err);
|
||||
throw err;
|
||||
}
|
||||
|
||||
/*
|
||||
var queryText = 'INSERT INTO members_jobs_files( member_uid,job_uid,filename,originalname,mimetype,size,encoding ) VALUES($1,$2,$3,$4,$5,$6,$7) RETURNING uid';
|
||||
db.query(queryText, [data.member_uid,data.job_uid,data.filename,data.originalname,data.mimetype,data.size,data.encoding], function(dbErr, result) {
|
||||
/opt/wrenchboard/TEST/TASKFILE/9d6e00c0-2de8-4099-a617-0c2811d8a738
|
||||
*/
|
||||
|
||||
console.log("THIS IS RESULT --> ",result.rows[0].file_name);
|
||||
console.log("THIS IS RESULT COUNT --> ",result.rowCount);
|
||||
if ( result.rowCount === 1){
|
||||
findFilename = result.rows[0].filename;
|
||||
jobUID = result.rows[0].job_uid;
|
||||
}
|
||||
let destinationDir = process.env.COMMON_TASKF_PATH !== undefined ? process.env.COMMON_TASKF_PATH : '/opt/wrenchboard/TEST/TASKFILE';
|
||||
|
||||
// $selectedFile = $this->savePath.'PROFILE/'.$out["member_uid"]."/MYFILES/". $out["saved_file_name"];
|
||||
const completeFile = myfilesCommonPath+"/"+jobUID+"/" + 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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
app.listen(3036, ()=>{
|
||||
console.log('server is listening on post 3036')
|
||||
})
|
||||
Reference in New Issue
Block a user