allow both `.png` and `png`
v1.18.x
barisusakli 9 years ago
parent 77b9406841
commit 99d64db9e0

@ -1,19 +1,18 @@
"use strict";
var uploadsController = {},
var fs = require('fs');
var path = require('path');
var async = require('async');
var nconf = require('nconf');
var validator = require('validator');
var winston = require('winston');
fs = require('fs'),
path = require('path'),
async = require('async'),
nconf = require('nconf'),
validator = require('validator'),
meta = require('../meta'),
file = require('../file'),
plugins = require('../plugins'),
utils = require('../../public/src/utils'),
image = require('../image');
var meta = require('../meta');
var file = require('../file');
var plugins = require('../plugins');
var image = require('../image');
var uploadsController = {};
uploadsController.upload = function(req, res, filesIterator, next) {
var files = req.files.files;
@ -126,8 +125,8 @@ function uploadFile(uid, uploadedFile, callback) {
}
if (meta.config.hasOwnProperty('allowedFileExtensions')) {
var allowed = meta.config.allowedFileExtensions.split(',').filter(Boolean);
var extension = path.extname(uploadedFile.name).slice(1);
var allowed = file.allowedExtensions();
var extension = path.extname(uploadedFile.name);
if (allowed.length > 0 && allowed.indexOf(extension) === -1) {
return callback(new Error('[[error:invalid-file-type, ' + allowed.join(', ') + ']]'));
}

@ -4,7 +4,6 @@ var fs = require('fs'),
nconf = require('nconf'),
path = require('path'),
winston = require('winston'),
mime = require('mime'),
jimp = require('jimp'),
utils = require('../public/src/utils');
@ -46,6 +45,28 @@ file.isFileTypeAllowed = function(path, callback) {
});
};
file.allowedExtensions = function() {
var meta = require('./meta');
var allowedExtensions = (meta.config.allowedFileExtensions || '').trim();
if (!allowedExtensions) {
return [];
}
allowedExtensions = allowedExtensions.split(',');
allowedExtensions = allowedExtensions.filter(Boolean).map(function(extension) {
extension = extension.trim();
if (!extension.startsWith('.')) {
extension = '.' + extension;
}
return extension;
});
if (allowedExtensions.indexOf('.jpg') !== -1 && allowedExtensions.indexOf('.jpeg') === -1) {
allowedExtensions.push('.jpeg');
}
return allowedExtensions;
};
file.exists = function(path, callback) {
fs.stat(path, function(err, stat) {
callback(!err && stat);

Loading…
Cancel
Save