Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function guessValueType(
value: Primitive | Array
): $Values {
if (Array.isArray(value)) return valueTypes.ARRAY
if (value === null) return valueTypes.NULL
if (typeof value !== 'string') return TYPES[typeof value]
if (isUrl(value)) {
// eslint-disable-next-line node/no-deprecated-api
const parsedUrl = url.parse(value)
const mimeType = mime.getType(parsedUrl.pathname)
if (!mimeType) return valueTypes.URL
if (mimeType.split('/')[0] === 'image') return valueTypes.IMAGE_URL
if (mimeType.split('/')[0] === 'video') return valueTypes.VIDEO_URL
if (mimeType.split('/')[0] === 'audio') return valueTypes.AUDIO_URL
return valueTypes.URL
}
// Test date last because this is the most expensive
if (isShortDate(value)) return valueTypes.DATE
if (isodate.is(value)) return valueTypes.DATETIME
return valueTypes.STRING
}
uploadFile(fileName, file) {
let Key = this.options.basePath + fileName
const s3Params = _.mapValues(this.uploadOptions, (optionConfig) => {
return _.isFunction(optionConfig) ? optionConfig(fileName, file) : optionConfig
})
// avoid noname folders in bucket
if (Key[0] === '/')
Key = Key.substr(1)
if (s3Params.ContentType === undefined)
s3Params.ContentType = mime.getType(fileName)
const Body = fs.createReadStream(file)
const upload = this.client.upload(
_.merge({Key, Body}, DEFAULT_UPLOAD_OPTIONS, s3Params)
)
if (!this.noCdnizer)
this.cdnizerOptions.files.push(`*${fileName}*`)
return {upload, promise: upload.promise()}
}
}
const fileInfo = [];
for (const file of req.files) {
const { localOriginal, localThumb, localNormal, publicOriginal, publicThumb, publicNormal } = getUniqueFilenames(
req,
file,
currentUser.model.username
);
let isError = false;
try {
ensureDirectoriesExist(localOriginal, localThumb, localNormal);
fs.renameSync(file.path, localOriginal);
const mimetype = mime.getType(file.originalname);
if (['image/apng', 'image/gif'].includes(mimetype)) {
fs.copyFileSync(localOriginal, localThumb);
fs.copyFileSync(localOriginal, localNormal);
} else {
await resize(localOriginal, localThumb, constants.thumbWidth, constants.thumbHeight);
await resize(localOriginal, localNormal, constants.normalWidth, constants.normalHeight);
}
} catch (ex) {
isError = true;
console.error('Error uploading image.', ex);
}
fileInfo.push({
original: publicOriginal,
thumb: publicThumb,
normal: publicNormal,
export default async function unfurl(onLinkUnfurl, url, editorState) {
if (url.match(/^
.then((decrypted) => {
const typeM = MIME.getType(fileName);
const blob = new Blob([decrypted], { type: typeM });
blob.name = fileName;
createLog(fileInput, fileName, false);
downloadFile(fileName, blob);
})
.catch(() => {
get mimeType () {
return mime.getType(this.path)
}
function respondWith(output, givenPathname) {
const mimeType = mime.getType(path.extname(givenPathname) || '.html') || 'application/octet-stream'
res.set('content-type', mimeType)
res.end(output)
}
list(dir, (name, abs, stats) => {
if (!opts.dotfiles && name.charAt(0) === '.') {
return;
}
let headers = {
'Content-Length': stats.size,
'Content-Type': mime.getType(name),
'Last-Modified': stats.mtime.toUTCString(),
};
if (cc) headers['Cache-Control'] = cc;
if (opts.etag) headers['ETag'] = `W/"${stats.size}-${stats.mtime.getTime()}"`;
FILES['/' + name.replace(/\\+/g, '/')] = { abs, stats, headers };
});
return function (req, res, next) {
let stats, file, uri=decodeURIComponent(req.path || req.pathname || parser(req).pathname);
let arr = [uri].concat(toAssume(uri, extensions)).map(x => join(dir, x)).filter(fs.existsSync);
while (file = arr.shift()) {
stats = fs.statSync(file);
if (stats.isDirectory()) continue;
setHeaders(res, uri, stats);
return send(req, res, file, stats, {
'Content-Type': mime.getType(file),
'Last-Modified': stats.mtime.toUTCString(),
'Content-Length': stats.size,
});
}
return next ? next() : isNotFound(req, res);
}
}
function getMimeTypeByExtension(extension: string): string {
return mime.getType(extension) || 'application/octet-stream'
}