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) {
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
// 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);
|
2017-06-24 04:49:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-11 03:21:07 +00:00
|
|
|
function resolveMimeType(query) {
|
2018-06-22 05:15:04 +00:00
|
|
|
if(mimeTypes.extensions[query]) {
|
|
|
|
return query; // alreaed a mime-type
|
|
|
|
}
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
return mimeTypes.lookup(query) || undefined; // lookup() returns false; we want undefined
|
2017-05-11 03:21:07 +00:00
|
|
|
}
|