This commit is contained in:
Flummi 2016-11-28 08:25:23 +01:00
parent e26930bdbf
commit 8d6ac4afcc

View File

@ -181,7 +181,8 @@ function Websrv(tlib) {
var start = 0; var start = 0;
var end = 0; var end = 0;
var range = req.headers['range']; var range = req.headers['range'];
var stat = fs.statSync(filePath); fs.stat(filePath, (err, stat) => {
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));
@ -198,6 +199,12 @@ function Websrv(tlib) {
var stream = fs.createReadStream(filePath, { flags: 'r', start: start, end: end}); var stream = fs.createReadStream(filePath, { flags: 'r', start: start, end: end});
stream.pipe(res); stream.pipe(res);
} }
else {
res.writeHead(200, { 'Content-Type': contentType });
res.end('404 - f0ck you', 'utf-8');
}
});
}
else { else {
fs.readFile(filePath, (error, content) => { fs.readFile(filePath, (error, content) => {
if(error) { if(error) {
@ -218,20 +225,6 @@ function Websrv(tlib) {
}); });
} }
} }
/*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 else if(filePath.match(/^\.\/api/i)) { // api
var url = filePath.split('/'); var url = filePath.split('/');
if(url[2] === undefined) { // Mainpage if(url[2] === undefined) { // Mainpage