muh
This commit is contained in:
parent
4742fd3d81
commit
21334b2d5f
@ -173,54 +173,52 @@ 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'];
|
var stat = fs.statSync(filePath);
|
||||||
var stat = fs.statSync(filePath);
|
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(isNaN(end) || end == 0) end = stat.size-1;
|
if(start > end) return;
|
||||||
if(start > end) return;
|
res.writeHead(206, {
|
||||||
res.writeHead(206, {
|
'Connection':'close',
|
||||||
'Connection':'close',
|
'Content-Type':contentType,
|
||||||
'Content-Type':contentType,
|
'Content-Length':end - start,
|
||||||
'Content-Length':end - start,
|
'Content-Range':'bytes '+start+'-'+end+'/'+stat.size,
|
||||||
'Content-Length':stat.size,
|
'Transfer-Encoding':'chunked'
|
||||||
'Content-Range':'bytes '+start+'-'+end+'/'+stat.size,
|
});
|
||||||
'Transfer-Encoding':'chunked'
|
var stream = fs.createReadStream(filePath, { flags: 'r', start: start, end: end});
|
||||||
});
|
stream.pipe(res);
|
||||||
var stream = fs.createReadStream(filePath, { flags: 'r', start: start, end: end});
|
}
|
||||||
stream.pipe(res);
|
else {
|
||||||
break;
|
fs.readFile(filePath, (error, content) => {
|
||||||
default:
|
if(error) {
|
||||||
fs.readFile(filePath, (error, content) => {
|
if(error.code == 'ENOENT') {
|
||||||
if(error) {
|
res.writeHead(200, { 'Content-Type': contentType });
|
||||||
if(error.code == 'ENOENT') {
|
res.end('404 - f0ck you', 'utf-8');
|
||||||
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 {
|
else {
|
||||||
res.writeHead(200, { 'Content-Type': contentType, 'Content-Length': content.length, 'Cache-Control': 'max-age=2592000, public' });
|
res.writeHead(500);
|
||||||
res.end(content, 'utf-8');
|
res.end('Sorry, check with the site admin for error: '+error.code+' ..\n');
|
||||||
|
res.end();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
break;
|
else {
|
||||||
|
res.writeHead(200, { 'Content-Type': contentType, 'Content-Length': content.length, 'Cache-Control': 'max-age=2592000, public' });
|
||||||
|
res.end(content, 'utf-8');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
fs.readFile(filePath, (error, content) => {
|
}
|
||||||
|
/*fs.readFile(filePath, (error, content) => {
|
||||||
if(error) {
|
if(error) {
|
||||||
if(error.code == 'ENOENT') {
|
if(error.code == 'ENOENT') {
|
||||||
res.writeHead(200, { 'Content-Type': contentType });
|
res.writeHead(200, { 'Content-Type': contentType });
|
||||||
@ -232,8 +230,8 @@ function Websrv(tlib) {
|
|||||||
res.end();
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user