This commit is contained in:
Flummi 2016-11-28 08:20:31 +01:00
parent 4742fd3d81
commit 21334b2d5f

View File

@ -173,15 +173,14 @@ 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('-')));
@ -193,14 +192,13 @@ function Websrv(tlib) {
'Connection':'close', 'Connection':'close',
'Content-Type':contentType, 'Content-Type':contentType,
'Content-Length':end - start, 'Content-Length':end - start,
'Content-Length':stat.size,
'Content-Range':'bytes '+start+'-'+end+'/'+stat.size, 'Content-Range':'bytes '+start+'-'+end+'/'+stat.size,
'Transfer-Encoding':'chunked' 'Transfer-Encoding':'chunked'
}); });
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);
break; }
default: else {
fs.readFile(filePath, (error, content) => { fs.readFile(filePath, (error, content) => {
if(error) { if(error) {
if(error.code == 'ENOENT') { if(error.code == 'ENOENT') {
@ -218,9 +216,9 @@ function Websrv(tlib) {
res.end(content, 'utf-8'); res.end(content, 'utf-8');
} }
}); });
break;
} }
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