This commit is contained in:
Flummi 2017-10-20 12:13:46 +02:00
parent c7bdf67436
commit b257e53a60

View File

@ -69,7 +69,7 @@ function Websrv(tlib) {
'.jpg': 'image/jpg', '.jpg': 'image/jpg',
'.gif': 'image/gif', '.gif': 'image/gif',
'.mp3': 'audio/mpeg', '.mp3': 'audio/mpeg',
'.flac': 'audio/x-flac', '.flac': 'audio/x-flac',
'.mp4': 'video/mp4', '.mp4': 'video/mp4',
'.webm': 'video/webm', '.webm': 'video/webm',
'.ogg': 'audio/ogg', '.ogg': 'audio/ogg',
@ -182,33 +182,32 @@ function Websrv(tlib) {
|| contentType === "video/mp4" || contentType === "video/mp4"
|| contentType === "video/quicktime" || contentType === "video/quicktime"
|| contentType === "audio/mpeg" || contentType === "audio/mpeg"
|| contentType === "audio/flac" || contentType === "audio/flac"
|| contentType === "audio/x-flac" || contentType === "audio/x-flac"
|| contentType === "audio/ogg") && req.headers['range']) { || contentType === "audio/ogg") && req.headers['range']) {
fs.readFile(filePath, "binary", function(err, file) { fs.readFile(filePath, "binary", function(err, file) {
if(typeof req.headers.range !== 'undefined') { if(typeof req.headers.range !== 'undefined') {
var range = req.headers.range; var range = req.headers.range;
var parts = range.replace(/bytes=/, "").split("-"); var parts = range.replace(/bytes=/, "").split("-");
var partialstart = parts[0]; var partialstart = parts[0];
var partialend = parts[1]; var partialend = parts[1];
var total = file.length; var total = file.length;
var start = parseInt(partialstart, 10); var start = parseInt(partialstart, 10);
var end = partialend ? parseInt(partialend, 10) : total-1; var end = partialend ? parseInt(partialend, 10) : total-1;
res.writeHead(206, {
res.writeHead(206, { "Content-Range": "bytes " + start + "-" + end + "/" + (total),
"Content-Range": "bytes " + start + "-" + end + "/" + (total), "Accept-Ranges": "bytes",
"Accept-Ranges": "bytes", "Content-Length": (end-start)+1,
"Content-Length": (end-start)+1, "Transfer-Encoding": "chunked",
"Transfer-Encoding": "chunked", "Connection": "close"
"Connection": "close" });
}); res.write(file.slice(start, end)+'0', "binary");
res.write(file.slice(start, end)+'0', "binary"); }
} else {
else { res.writeHead(200);
res.writeHead(200); res.write(file, "binary");
res.write(file, "binary"); }
} res.end();
res.end();
}); });
} }
else { else {