better checks for file extensions

jpg allows jpeg
dots dont break extensions
This commit is contained in:
barisusakli
2015-09-18 11:07:43 -04:00
parent fbfb39f967
commit c98bd87334
2 changed files with 9 additions and 5 deletions

View File

@@ -46,10 +46,6 @@ file.isFileTypeAllowed = function(path, allowedExtensions, callback) {
return callback();
}
allowedExtensions = allowedExtensions.filter(Boolean).map(function(extension) {
return extension.trim();
});
var magic = new Magic(mmmagic.MAGIC_MIME_TYPE);
magic.detectFile(path, function(err, mimeType) {
if (err) {
@@ -72,6 +68,14 @@ file.allowedExtensions = function() {
return [];
}
allowedExtensions = allowedExtensions.split(',');
allowedExtensions = allowedExtensions.filter(Boolean).map(function(extension) {
extension = extension.trim();
return extension.replace(/\./g, '');
});
if (allowedExtensions.indexOf('jpg') !== -1 && allowedExtensions.indexOf('jpeg') === -1) {
allowedExtensions.push('jpeg');
}
console.log(allowedExtensions)
return allowedExtensions;
};

View File

@@ -140,7 +140,7 @@
</div>
<strong>Topic Thumb Size</strong><br /> <input type="text" class="form-control" value="120" data-field="topicThumbSize"> <br />
<strong>Allowed file types, (ie png, pdf, zip). Leave empty to allow all.</strong><br /> <input type="text" class="form-control" value="" data-field="allowedFileExtensions"><br />
<strong>Allowed file types, (ie png, jpg, pdf, zip). Leave empty to allow all.</strong><br /> <input type="text" class="form-control" value="" data-field="allowedFileExtensions"><br />
</form>
</div>