Merge branch 'f0ckdev' into 'master'

"download-any-videos"-fix

See merge request !55
This commit is contained in:
Flummi 2016-11-28 07:27:38 +00:00
commit d829c1ff77

View File

@ -173,16 +173,16 @@ function Websrv(tlib) {
}
else if(filePath.match(/^\.\/(b|s|t)\/.*/)) { // file
contentType = mimeTypes[extname];
switch(contentType) {
case "video/webm":
case "video/mp4":
case "video/quicktime":
case "audio/mpeg":
case "audio/ogg":
if(( contentType === "video/webm"
|| contentType === "video/mp4"
|| contentType === "video/quicktime"
|| contentType === "audio/mpeg"
|| contentType === "audio/ogg") && req.headers['range']) {
var start = 0;
var end = 0;
var range = req.headers['range'];
var stat = fs.statSync(filePath);
fs.stat(filePath, (err, stat) => {
if(!err) {
if(range != null) {
start = parseInt(range.slice(range.indexOf('bytes=')+6, range.indexOf('-')));
end = parseInt(range.slice(range.indexOf('-')+1, range.length));
@ -198,8 +198,14 @@ function Websrv(tlib) {
});
var stream = fs.createReadStream(filePath, { flags: 'r', start: start, end: end});
stream.pipe(res);
break;
default:
}
else {
res.writeHead(404);
res.end('404 - f0ck you', 'utf-8');
}
});
}
else {
fs.readFile(filePath, (error, content) => {
if(error) {
if(error.code == 'ENOENT') {
@ -217,21 +223,7 @@ function Websrv(tlib) {
res.end(content, 'utf-8');
}
});
break;
}
fs.readFile(filePath, (error, content) => {
if(error) {
if(error.code == 'ENOENT') {
res.writeHead(200, { 'Content-Type': contentType });
res.end('404 - f0ck you', 'utf-8');
}
else {
res.writeHead(500);
res.end('Sorry, check with the site admin for error: '+error.code+' ..\n');
res.end();
}
}
});
}
else if(filePath.match(/^\.\/api/i)) { // api
var url = filePath.split('/');