Replaced i18n.t w/ tpl in api/v2/utils/validators/input/images.js (#13575)

refs: TryGhost#13380

- The i18n package is deprecated. It is being replaced with the tpl package.
This commit is contained in:
IncredibleZuess 2021-10-13 09:50:15 +02:00 committed by GitHub
parent 6421f60852
commit 6d4b682b95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,14 @@
const jsonSchema = require('../utils/json-schema'); const jsonSchema = require('../utils/json-schema');
const config = require('../../../../../../shared/config'); const config = require('../../../../../../shared/config');
const i18n = require('../../../../../../shared/i18n'); const tpl = require('@tryghost/tpl');
const errors = require('@tryghost/errors'); const errors = require('@tryghost/errors');
const {imageSize, blogIcon} = require('../../../../../lib/image'); const {imageSize, blogIcon} = require('../../../../../lib/image');
const messages = {
isNotSquare: 'Please select a valid image file with square dimensions.',
invalidFile: 'Please select a valid image.'
};
const profileImage = (frame) => { const profileImage = (frame) => {
return imageSize.getImageSizeFromPath(frame.file.path).then((response) => { return imageSize.getImageSizeFromPath(frame.file.path).then((response) => {
// save the image dimensions in new property for file // save the image dimensions in new property for file
@ -12,7 +17,7 @@ const profileImage = (frame) => {
// CASE: file needs to be a square // CASE: file needs to be a square
if (frame.file.dimensions.width !== frame.file.dimensions.height) { if (frame.file.dimensions.width !== frame.file.dimensions.height) {
return Promise.reject(new errors.ValidationError({ return Promise.reject(new errors.ValidationError({
message: i18n.t('errors.api.images.isNotSquare') message: tpl(messages.isNotSquare)
})); }));
} }
}); });
@ -28,7 +33,7 @@ const icon = (frame) => {
// CASE: file should not be larger than 100kb // CASE: file should not be larger than 100kb
if (!validIconFileSize(frame.file.size)) { if (!validIconFileSize(frame.file.size)) {
return Promise.reject(new errors.ValidationError({ return Promise.reject(new errors.ValidationError({
message: i18n.t('errors.api.icons.invalidFile', {extensions: iconExtensions}) message: tpl(messages.invalidFile, {extensions: iconExtensions})
})); }));
} }
@ -39,7 +44,7 @@ const icon = (frame) => {
// CASE: file needs to be a square // CASE: file needs to be a square
if (frame.file.dimensions.width !== frame.file.dimensions.height) { if (frame.file.dimensions.width !== frame.file.dimensions.height) {
return Promise.reject(new errors.ValidationError({ return Promise.reject(new errors.ValidationError({
message: i18n.t('errors.api.icons.invalidFile', {extensions: iconExtensions}) message: tpl(messages.invalidFile, {extensions: iconExtensions})
})); }));
} }
@ -47,14 +52,14 @@ const icon = (frame) => {
// .ico files can contain multiple sizes, we need at least a minimum of 60px (16px is ok, as long as 60px are present as well) // .ico files can contain multiple sizes, we need at least a minimum of 60px (16px is ok, as long as 60px are present as well)
if (frame.file.dimensions.width < 60) { if (frame.file.dimensions.width < 60) {
return Promise.reject(new errors.ValidationError({ return Promise.reject(new errors.ValidationError({
message: i18n.t('errors.api.icons.invalidFile', {extensions: iconExtensions}) message: tpl(messages.invalidFile, {extensions: iconExtensions})
})); }));
} }
// CASE: icon needs to be smaller than or equal to 1000px // CASE: icon needs to be smaller than or equal to 1000px
if (frame.file.dimensions.width > 1000) { if (frame.file.dimensions.width > 1000) {
return Promise.reject(new errors.ValidationError({ return Promise.reject(new errors.ValidationError({
message: i18n.t('errors.api.icons.invalidFile', {extensions: iconExtensions}) message: tpl(messages.invalidFile, {extensions: iconExtensions})
})); }));
} }
}); });