-
Notifications
You must be signed in to change notification settings - Fork 104
/
mime_util.js
42 lines (33 loc) · 1.05 KB
/
mime_util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* jslint node: true */
'use strict';
// deps
const _ = require('lodash');
const mimeTypes = require('mime-types');
exports.startup = startup;
exports.resolveMimeType = resolveMimeType;
function startup(cb) {
//
// Add in types (not yet) supported by mime-db -- and therefor, mime-types
//
const ADDITIONAL_EXT_MIMETYPES = {
ans: 'text/x-ansi',
gz: 'application/gzip', // not in mime-types 2.1.15 :(
lzx: 'application/x-lzx', // :TODO: submit to mime-types
};
_.forEach(ADDITIONAL_EXT_MIMETYPES, (mimeType, ext) => {
// don't override any entries
if (!_.isString(mimeTypes.types[ext])) {
mimeTypes[ext] = mimeType;
}
if (!mimeTypes.extensions[mimeType]) {
mimeTypes.extensions[mimeType] = [ext];
}
});
return cb(null);
}
function resolveMimeType(query) {
if (mimeTypes.extensions[query]) {
return query; // already a mime-type
}
return mimeTypes.lookup(query) || undefined; // lookup() returns false; we want undefined
}