2017-05-11 03:21:07 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2017-06-24 04:49:46 +00:00
|
|
|
// deps
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
2017-05-11 03:21:07 +00:00
|
|
|
const mimeTypes = require('mime-types');
|
|
|
|
|
2017-06-24 04:49:46 +00:00
|
|
|
exports.startup = startup;
|
2017-05-11 03:21:07 +00:00
|
|
|
exports.resolveMimeType = resolveMimeType;
|
|
|
|
|
2017-06-24 04:49:46 +00:00
|
|
|
function startup(cb) {
|
|
|
|
//
|
|
|
|
// Add in types (not yet) supported by mime-db -- and therefor, mime-types
|
|
|
|
//
|
|
|
|
const ADDITIONAL_EXT_MIMETYPES = {
|
|
|
|
arj : 'application/x-arj',
|
2017-07-10 02:00:36 +00:00
|
|
|
ans : 'text/x-ansi',
|
|
|
|
gz : 'application/gzip', // not in mime-types 2.1.15 :(
|
2017-06-24 04:49:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
_.forEach(ADDITIONAL_EXT_MIMETYPES, (mimeType, ext) => {
|
|
|
|
// don't override any entries
|
|
|
|
if(!_.isString(mimeTypes.types[ext])) {
|
|
|
|
mimeTypes[ext] = mimeType;
|
|
|
|
}
|
2017-07-10 02:00:36 +00:00
|
|
|
|
|
|
|
if(!mimeTypes.extensions[mimeType]) {
|
|
|
|
mimeTypes.extensions[mimeType] = [ ext ];
|
|
|
|
}
|
2017-06-24 04:49:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return cb(null);
|
|
|
|
}
|
|
|
|
|
2017-05-11 03:21:07 +00:00
|
|
|
function resolveMimeType(query) {
|
2017-05-20 00:41:13 +00:00
|
|
|
if(mimeTypes.extensions[query]) {
|
|
|
|
return query; // alreaed a mime-type
|
|
|
|
}
|
|
|
|
|
|
|
|
return mimeTypes.lookup(query) || undefined; // lookup() returns false; we want undefined
|
2017-05-11 03:21:07 +00:00
|
|
|
}
|