mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-13 19:09:58 +00:00
Detect MIME type for local files
This commit is contained in:
4
app/package-lock.json
generated
4
app/package-lock.json
generated
@@ -2959,14 +2959,12 @@
|
|||||||
"mime-db": {
|
"mime-db": {
|
||||||
"version": "1.37.0",
|
"version": "1.37.0",
|
||||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.37.0.tgz",
|
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.37.0.tgz",
|
||||||
"integrity": "sha512-R3C4db6bgQhlIhPU48fUtdVmKnflq+hRdad7IyKhtFj06VPNVdk2RhiYL3UjQIlso8L+YxAtFkobT0VK+S/ybg==",
|
"integrity": "sha512-R3C4db6bgQhlIhPU48fUtdVmKnflq+hRdad7IyKhtFj06VPNVdk2RhiYL3UjQIlso8L+YxAtFkobT0VK+S/ybg=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"mime-types": {
|
"mime-types": {
|
||||||
"version": "2.1.21",
|
"version": "2.1.21",
|
||||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.21.tgz",
|
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.21.tgz",
|
||||||
"integrity": "sha512-3iL6DbwpyLzjR3xHSFNFeb9Nz/M8WDkX33t1GFQnFOllWk8pOrh/LSrB5OXlnlW5P9LH73X6loW/eogc+F5lJg==",
|
"integrity": "sha512-3iL6DbwpyLzjR3xHSFNFeb9Nz/M8WDkX33t1GFQnFOllWk8pOrh/LSrB5OXlnlW5P9LH73X6loW/eogc+F5lJg==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"mime-db": "~1.37.0"
|
"mime-db": "~1.37.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
"castv2": "^0.1.9",
|
"castv2": "^0.1.9",
|
||||||
"dnssd": "^0.4.1",
|
"dnssd": "^0.4.1",
|
||||||
"fast-srp-hap": "^1.0.1",
|
"fast-srp-hap": "^1.0.1",
|
||||||
|
"mime-types": "^2.1.21",
|
||||||
"node-fetch": "^2.3.0",
|
"node-fetch": "^2.3.0",
|
||||||
"tweetnacl": "^1.0.0"
|
"tweetnacl": "^1.0.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import dnssd from "dnssd";
|
|||||||
import http from "http";
|
import http from "http";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import mime from "mime-types";
|
||||||
|
|
||||||
import * as transforms from "./transforms";
|
import * as transforms from "./transforms";
|
||||||
import Media from "./Media";
|
import Media from "./Media";
|
||||||
@@ -117,6 +118,8 @@ async function handleMessage (message) {
|
|||||||
const { size: fileSize } = fs.statSync(filePath);
|
const { size: fileSize } = fs.statSync(filePath);
|
||||||
const { range } = req.headers;
|
const { range } = req.headers;
|
||||||
|
|
||||||
|
const contentType = mime.lookup(filePath) || "video/mp4";
|
||||||
|
|
||||||
// Partial content HTTP 206
|
// Partial content HTTP 206
|
||||||
if (range) {
|
if (range) {
|
||||||
const bounds = range.substring(6).split("-");
|
const bounds = range.substring(6).split("-");
|
||||||
@@ -132,7 +135,7 @@ async function handleMessage (message) {
|
|||||||
"Accept-Ranges": "bytes"
|
"Accept-Ranges": "bytes"
|
||||||
, "Content-Range": `bytes ${start}-${end}/${fileSize}`
|
, "Content-Range": `bytes ${start}-${end}/${fileSize}`
|
||||||
, "Content-Length": chunkSize
|
, "Content-Length": chunkSize
|
||||||
, "Content-Type": "video/mp4"
|
, "Content-Type": contentType
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.createReadStream(filePath, { start, end }).pipe(res);
|
fs.createReadStream(filePath, { start, end }).pipe(res);
|
||||||
@@ -140,7 +143,7 @@ async function handleMessage (message) {
|
|||||||
} else {
|
} else {
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
"Content-Length": fileSize
|
"Content-Length": fileSize
|
||||||
, "Content-Type": "video/mp4"
|
, "Content-Type": contentType
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.createReadStream(filePath).pipe(res)
|
fs.createReadStream(filePath).pipe(res)
|
||||||
|
|||||||
Reference in New Issue
Block a user