This commit is contained in:
Flummi 2017-05-25 20:01:45 +02:00
parent a590dbb3d7
commit bc57be6e00

View File

@ -178,31 +178,30 @@ function Websrv(tlib) {
|| contentType === "video/quicktime"
|| contentType === "audio/mpeg"
|| contentType === "audio/ogg") && req.headers['range']) {
var start = 0;
var end = 0;
var range = req.headers['range'];
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;
fs.readFile(filePath, "binary", function(err, file) {
if(typeof req.headers.range !== 'undefined') {
var range = req.headers.range;
var parts = range.replace(/bytes=/, "").split("-");
var partialstart = parts[0];
var partialend = parts[1];
var total = file.length;
var start = parseInt(partialstart, 10);
var end = partialend ? parseInt(partialend, 10) : total-1;
res.writeHead(206, {
'Connection':'close',
'Content-Type':contentType,
'Content-Length':end - start,
'Content-Range':'bytes '+start+'-'+end+'/'+stat.size,
'Transfer-Encoding':'chunked'
"Content-Range": "bytes " + start + "-" + end + "/" + (total),
"Accept-Ranges": "bytes",
"Content-Length": (end-start)+1,
"Transfer-Encoding": "chunked",
"Connection": "close"
});
var stream = fs.createReadStream(filePath, { flags: 'r', start: start, end: end});
stream.pipe(res);
res.write(file.slice(start, end)+'0', "binary");
}
else {
res.writeHead(404);
res.end('404 - f0ck you', 'utf-8');
res.writeHead(200);
res.write(file, "binary");
}
res.end();
});
}
else {