| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 1× 1× 1× 75× 103× 1× 1× 1× 110× 110× 1× | const MimeTypes = require("../MimeTypes");
const ExtTypes = {};
Object.keys(MimeTypes).forEach(function (type) {
MimeTypes[type].forEach(function (ext) {
ExtTypes[ext] = type;
});
});
const DEFAULT_TYPE = "application/octet-stream";
const EXT_MATCHER = /\.(\w+)$/;
function getMimeType(file, defaultType) {
const match = file.match(EXT_MATCHER);
return match && ExtTypes[match[1]] || defaultType || DEFAULT_TYPE;
}
module.exports = getMimeType;
|