diff --git a/app/package-lock.json b/app/package-lock.json index 1ef9ade..7f5e2fa 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -2959,14 +2959,12 @@ "mime-db": { "version": "1.37.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.37.0.tgz", - "integrity": "sha512-R3C4db6bgQhlIhPU48fUtdVmKnflq+hRdad7IyKhtFj06VPNVdk2RhiYL3UjQIlso8L+YxAtFkobT0VK+S/ybg==", - "dev": true + "integrity": "sha512-R3C4db6bgQhlIhPU48fUtdVmKnflq+hRdad7IyKhtFj06VPNVdk2RhiYL3UjQIlso8L+YxAtFkobT0VK+S/ybg==" }, "mime-types": { "version": "2.1.21", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.21.tgz", "integrity": "sha512-3iL6DbwpyLzjR3xHSFNFeb9Nz/M8WDkX33t1GFQnFOllWk8pOrh/LSrB5OXlnlW5P9LH73X6loW/eogc+F5lJg==", - "dev": true, "requires": { "mime-db": "~1.37.0" } diff --git a/app/package.json b/app/package.json index f674f4f..28a15cf 100644 --- a/app/package.json +++ b/app/package.json @@ -17,6 +17,7 @@ "castv2": "^0.1.9", "dnssd": "^0.4.1", "fast-srp-hap": "^1.0.1", + "mime-types": "^2.1.21", "node-fetch": "^2.3.0", "tweetnacl": "^1.0.0" }, diff --git a/app/src/main.js b/app/src/main.js index d4f31a9..0664af4 100755 --- a/app/src/main.js +++ b/app/src/main.js @@ -3,6 +3,7 @@ import dnssd from "dnssd"; import http from "http"; import fs from "fs"; import path from "path"; +import mime from "mime-types"; import * as transforms from "./transforms"; import Media from "./Media"; @@ -117,6 +118,8 @@ async function handleMessage (message) { const { size: fileSize } = fs.statSync(filePath); const { range } = req.headers; + const contentType = mime.lookup(filePath) || "video/mp4"; + // Partial content HTTP 206 if (range) { const bounds = range.substring(6).split("-"); @@ -132,7 +135,7 @@ async function handleMessage (message) { "Accept-Ranges": "bytes" , "Content-Range": `bytes ${start}-${end}/${fileSize}` , "Content-Length": chunkSize - , "Content-Type": "video/mp4" + , "Content-Type": contentType }); fs.createReadStream(filePath, { start, end }).pipe(res); @@ -140,7 +143,7 @@ async function handleMessage (message) { } else { res.writeHead(200, { "Content-Length": fileSize - , "Content-Type": "video/mp4" + , "Content-Type": contentType }); fs.createReadStream(filePath).pipe(res)