fix(file.controller.js): set headers for file extensions from MIME -I1218 (#1330)

* fix(file.controller.js): set headers for file extensions from MIME - I1218
* Use name to work out content type and provide fallback

Co-authored-by: Andrew Nicolaou <me@andrewnicolaou.co.uk>
This commit is contained in:
Elit Altum 2020-03-27 17:30:50 +05:30 committed by GitHub
parent 866d67d119
commit 06bca997ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions

14
package-lock.json generated
View file

@ -13939,16 +13939,16 @@
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg=="
}, },
"mime-db": { "mime-db": {
"version": "1.40.0", "version": "1.43.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz",
"integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA==" "integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ=="
}, },
"mime-types": { "mime-types": {
"version": "2.1.24", "version": "2.1.26",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.24.tgz", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.26.tgz",
"integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==", "integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==",
"requires": { "requires": {
"mime-db": "1.40.0" "mime-db": "1.43.0"
} }
}, },
"mimer": { "mimer": {

View file

@ -134,6 +134,7 @@
"jshint": "^2.11.0", "jshint": "^2.11.0",
"lodash": "^4.17.15", "lodash": "^4.17.15",
"loop-protect": "github:catarak/loop-protect", "loop-protect": "github:catarak/loop-protect",
"mime-types": "^2.1.26",
"mjml": "^3.3.2", "mjml": "^3.3.2",
"mockingoose": "^2.13.2", "mockingoose": "^2.13.2",
"mongoose": "^5.9.2", "mongoose": "^5.9.2",

View file

@ -1,4 +1,5 @@
import each from 'async/each'; import each from 'async/each';
import mime from 'mime-types';
import isBefore from 'date-fns/is_before'; import isBefore from 'date-fns/is_before';
import Project from '../models/project'; import Project from '../models/project';
import { resolvePathToFile } from '../utils/filePath'; import { resolvePathToFile } from '../utils/filePath';
@ -120,6 +121,8 @@ export function getFileContent(req, res) {
res.status(404).send({ success: false, message: 'File with that name and path does not exist.' }); res.status(404).send({ success: false, message: 'File with that name and path does not exist.' });
return; return;
} }
const contentType = mime.lookup(resolvedFile.name) || 'application/octet-stream';
res.set('Content-Type', contentType);
res.send(resolvedFile.content); res.send(resolvedFile.content);
}); });
} }