Detect MIME type for local files

This commit is contained in:
hensm
2019-01-29 17:09:46 +00:00
parent 3f6cad64a6
commit a1101d6cf6
3 changed files with 7 additions and 5 deletions

4
app/package-lock.json generated
View File

@@ -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"
}

View File

@@ -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"
},

View File

@@ -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)