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,65 +173,57 @@ function Websrv(tlib) {
} }
else if(filePath.match(/^\.\/(b|s|t)\/.*/)) { // file else if(filePath.match(/^\.\/(b|s|t)\/.*/)) { // file
contentType = mimeTypes[extname]; contentType = mimeTypes[extname];
switch(contentType) { if(( contentType === "video/webm"
case "video/webm": || contentType === "video/mp4"
case "video/mp4": || contentType === "video/quicktime"
case "video/quicktime": || contentType === "audio/mpeg"
case "audio/mpeg": || contentType === "audio/ogg") && req.headers['range']) {
case "audio/ogg": var start = 0;
var start = 0; var end = 0;
var end = 0; var range = req.headers['range'];
var range = req.headers['range']; fs.stat(filePath, (err, stat) => {
var stat = fs.statSync(filePath); if(!err) {
if(range != null) { if(range != null) {
start = parseInt(range.slice(range.indexOf('bytes=')+6, range.indexOf('-'))); start = parseInt(range.slice(range.indexOf('bytes=')+6, range.indexOf('-')));
end = parseInt(range.slice(range.indexOf('-')+1, range.length)); end = parseInt(range.slice(range.indexOf('-')+1, range.length));
}
if(isNaN(end) || end == 0) end = stat.size-1;
if(start > end) return;
res.writeHead(206, {
'Connection':'close',
'Content-Type':contentType,
'Content-Length':end - start,
'Content-Range':'bytes '+start+'-'+end+'/'+stat.size,
'Transfer-Encoding':'chunked'
});
var stream = fs.createReadStream(filePath, { flags: 'r', start: start, end: end});
stream.pipe(res);
break;
default:
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(isNaN(end) || end == 0) end = stat.size-1;
res.writeHead(200, { 'Content-Type': contentType, 'Content-Length': content.length, 'Cache-Control': 'max-age=2592000, public' }); if(start > end) return;
res.end(content, 'utf-8'); res.writeHead(206, {
} 'Connection':'close',
}); 'Content-Type':contentType,
break; 'Content-Length':end - start,
} 'Content-Range':'bytes '+start+'-'+end+'/'+stat.size,
fs.readFile(filePath, (error, content) => { 'Transfer-Encoding':'chunked'
if(error) { });
if(error.code == 'ENOENT') { var stream = fs.createReadStream(filePath, { flags: 'r', start: start, end: end});
res.writeHead(200, { 'Content-Type': contentType }); stream.pipe(res);
res.end('404 - f0ck you', 'utf-8');
} }
else { else {
res.writeHead(500); res.writeHead(404);
res.end('Sorry, check with the site admin for error: '+error.code+' ..\n'); res.end('404 - f0ck you', 'utf-8');
res.end();
} }
} });
}); }
else {
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 {
res.writeHead(200, { 'Content-Type': contentType, 'Content-Length': content.length, 'Cache-Control': 'max-age=2592000, public' });
res.end(content, 'utf-8');
}
});
}
} }
else if(filePath.match(/^\.\/api/i)) { // api else if(filePath.match(/^\.\/api/i)) { // api
var url = filePath.split('/'); var url = filePath.split('/');