Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const Path = require('path');
const _ = require('underscore');
const httpErrors = require('httperrors');
const getFilterInfosAndTargetContentTypeFromQueryString = require('./getFilterInfosAndTargetContentTypeFromQueryString');
const mime = require('mime');
const stream = require('stream');
const accepts = require('accepts');
const hijackResponse = require('hijackresponse');
const isImageByExtension = {};
Object.keys(mime._extensions).forEach(contentType => {
if (/^image\//.test(contentType)) {
const extension = mime._extensions[contentType];
isImageByExtension[extension] = true;
}
});
isImageByExtension.jpg = true;
function isImageExtension(extension) {
return isImageByExtension[extension.toLowerCase()];
}
module.exports = options => {
options = options || {};
if (
Object.keys(mime._extensions).forEach(contentType => {
if (/^image\//.test(contentType)) {
const extension = mime._extensions[contentType];
isImageByExtension[extension] = true;
}
});
function getMockFileNameForContentType(contentType) {
if (contentType) {
if (
contentType === 'image/vnd.microsoft.icon' ||
contentType === 'image/x-icon'
) {
return '.ico';
}
return `.${mime._extensions[contentType]}`;
}
}