From b257e53a60047f24ecb7fa717ca006a0be64cfe8 Mon Sep 17 00:00:00 2001 From: Flummi Date: Fri, 20 Oct 2017 12:13:46 +0200 Subject: [PATCH] muh --- src/websrv.js | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/websrv.js b/src/websrv.js index 5ee8a5d..31c651a 100644 --- a/src/websrv.js +++ b/src/websrv.js @@ -69,7 +69,7 @@ function Websrv(tlib) { '.jpg': 'image/jpg', '.gif': 'image/gif', '.mp3': 'audio/mpeg', - '.flac': 'audio/x-flac', + '.flac': 'audio/x-flac', '.mp4': 'video/mp4', '.webm': 'video/webm', '.ogg': 'audio/ogg', @@ -182,33 +182,32 @@ function Websrv(tlib) { || contentType === "video/mp4" || contentType === "video/quicktime" || contentType === "audio/mpeg" - || contentType === "audio/flac" - || contentType === "audio/x-flac" + || contentType === "audio/flac" + || contentType === "audio/x-flac" || contentType === "audio/ogg") && req.headers['range']) { 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, { - "Content-Range": "bytes " + start + "-" + end + "/" + (total), - "Accept-Ranges": "bytes", - "Content-Length": (end-start)+1, - "Transfer-Encoding": "chunked", - "Connection": "close" - }); - res.write(file.slice(start, end)+'0', "binary"); - } - else { - res.writeHead(200); - res.write(file, "binary"); - } - res.end(); + 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, { + "Content-Range": "bytes " + start + "-" + end + "/" + (total), + "Accept-Ranges": "bytes", + "Content-Length": (end-start)+1, + "Transfer-Encoding": "chunked", + "Connection": "close" + }); + res.write(file.slice(start, end)+'0', "binary"); + } + else { + res.writeHead(200); + res.write(file, "binary"); + } + res.end(); }); } else {