+404
This commit is contained in:
parent
e26930bdbf
commit
8d6ac4afcc
|
@ -181,22 +181,29 @@ function Websrv(tlib) {
|
|||
var start = 0;
|
||||
var end = 0;
|
||||
var range = req.headers['range'];
|
||||
var stat = fs.statSync(filePath);
|
||||
if(range != null) {
|
||||
start = parseInt(range.slice(range.indexOf('bytes=')+6, range.indexOf('-')));
|
||||
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'
|
||||
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));
|
||||
}
|
||||
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);
|
||||
}
|
||||
else {
|
||||
res.writeHead(200, { 'Content-Type': contentType });
|
||||
res.end('404 - f0ck you', 'utf-8');
|
||||
}
|
||||
});
|
||||
var stream = fs.createReadStream(filePath, { flags: 'r', start: start, end: end});
|
||||
stream.pipe(res);
|
||||
}
|
||||
else {
|
||||
fs.readFile(filePath, (error, content) => {
|
||||
|
@ -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
|
||||
var url = filePath.split('/');
|
||||
if(url[2] === undefined) { // Mainpage
|
||||
|
|
Loading…
Reference in New Issue
Block a user