Replaced i18n.t w/ tpl in upload middleware

refs: TryGhost#13380

- The i18n package is deprecated. It is being replaced with the tpl package.
This commit is contained in:
Ozan Uslan 2021-10-04 14:19:18 +03:00 committed by Hannah Wolfe
parent b10802f4c6
commit b1395bbe20

View File

@ -4,9 +4,36 @@ const multer = require('multer');
const fs = require('fs-extra');
const errors = require('@tryghost/errors');
const config = require('../../../../shared/config');
const i18n = require('../../../../shared/i18n');
const tpl = require('@tryghost/tpl');
const logging = require('@tryghost/logging');
const messages = {
db: {
missingFile: 'Please select a database file to import.',
invalidFile: 'Unsupported file. Please try any of the following formats: {extensions}'
},
redirects: {
missingFile: 'Please select a JSON file.',
invalidFile: 'Please select a valid JSON file to import.'
},
routes: {
missingFile: 'Please select a YAML file.',
invalidFile: 'Please select a valid YAML file to import.'
},
themes: {
missingFile: 'Please select a theme.',
invalidFile: 'Please select a valid zip file.'
},
images: {
missingFile: 'Please select an image.',
invalidFile: 'Please select a valid image.'
},
icons: {
missingFile: 'Please select an icon.',
invalidFile: 'Icon must be a square .ico or .png file between 60px 1,000px, under 100kb.'
}
};
const upload = {
enabledClear: config.get('uploadClear') || true,
multer: multer({dest: os.tmpdir()})
@ -72,7 +99,7 @@ const validation = function (options) {
// Check if a file was provided
if (!checkFileExists(req.file)) {
return next(new errors.ValidationError({
message: i18n.t(`errors.api.${type}.missingFile`)
message: tpl(messages[type].missingFile)
}));
}
@ -81,7 +108,7 @@ const validation = function (options) {
// Check if the file is valid
if (!checkFileIsValid(req.file, contentTypes, extensions)) {
return next(new errors.UnsupportedMediaTypeError({
message: i18n.t(`errors.api.${type}.invalidFile`, {extensions: extensions})
message: tpl(messages[type].invalidFile, {extensions: extensions})
}));
}