mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
refs #9178 - move express apps to one place (called `web`) - requires https://github.com/TryGhost/Ghost-Admin/pull/923 - any further improvements are not part of this PR - this PR just moves the files and ensures the paths are up-to-date
30 lines
1.2 KiB
JavaScript
30 lines
1.2 KiB
JavaScript
var apiUtils = require('../../../api/utils'),
|
|
errors = require('../../../errors'),
|
|
config = require('../../../config'),
|
|
i18n = require('../../../i18n');
|
|
|
|
module.exports = function upload(options) {
|
|
var type = options.type;
|
|
|
|
// if we finish the data/importer logic, we forward the request to the specified importer
|
|
return function uploadValidation(req, res, next) {
|
|
var extensions = (config.get('uploads')[type] && config.get('uploads')[type].extensions) || [],
|
|
contentTypes = (config.get('uploads')[type] && config.get('uploads')[type].contentTypes) || [];
|
|
|
|
req.file = req.file || {};
|
|
req.file.name = req.file.originalname;
|
|
req.file.type = req.file.mimetype;
|
|
|
|
// Check if a file was provided
|
|
if (!apiUtils.checkFileExists(req.file)) {
|
|
return next(new errors.NoPermissionError({message: i18n.t('errors.api.' + type + '.missingFile')}));
|
|
}
|
|
|
|
// Check if the file is valid
|
|
if (!apiUtils.checkFileIsValid(req.file, contentTypes, extensions)) {
|
|
return next(new errors.UnsupportedMediaTypeError({message: i18n.t('errors.api.' + type + '.invalidFile', {extensions: extensions})}));
|
|
}
|
|
|
|
next();
|
|
};
|
|
};
|