mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
Replaced i18n.t w/ tpl in core/server/lib/image (#13507)
refs: #13380 - The i18n package is deprecated. It is being replaced with the tpl package. Co-authored-by: Aleksander Chromik <aleksander.chromik@footballco.com>
This commit is contained in:
parent
36a2569370
commit
48ac52800b
@ -4,10 +4,14 @@ const _ = require('lodash');
|
||||
const path = require('path');
|
||||
const errors = require('@tryghost/errors');
|
||||
|
||||
const messages = {
|
||||
error: 'Could not fetch icon dimensions.'
|
||||
};
|
||||
|
||||
class BlogIcon {
|
||||
constructor({config, i18n, urlUtils, settingsCache, storageUtils}) {
|
||||
constructor({config, tpl, urlUtils, settingsCache, storageUtils}) {
|
||||
this.config = config;
|
||||
this.i18n = i18n;
|
||||
this.tpl = tpl;
|
||||
this.urlUtils = urlUtils;
|
||||
this.settingsCache = settingsCache;
|
||||
this.storageUtils = storageUtils;
|
||||
@ -42,7 +46,7 @@ class BlogIcon {
|
||||
});
|
||||
} catch (err) {
|
||||
return reject(new errors.ValidationError({
|
||||
message: this.i18n.t('errors.utils.blogIcon.error', {
|
||||
message: this.tpl(messages.error, {
|
||||
file: storagePath,
|
||||
error: err.message
|
||||
})
|
||||
|
@ -7,15 +7,19 @@ const Promise = require('bluebird');
|
||||
const _ = require('lodash');
|
||||
const errors = require('@tryghost/errors');
|
||||
|
||||
const messages = {
|
||||
invalidDimensions: 'Could not fetch image dimensions.'
|
||||
};
|
||||
|
||||
// these are formats supported by image-size but not probe-image-size
|
||||
const FETCH_ONLY_FORMATS = [
|
||||
'cur', 'icns', 'ico', 'dds'
|
||||
];
|
||||
|
||||
class ImageSize {
|
||||
constructor({config, i18n, storage, storageUtils, validator, urlUtils, request}) {
|
||||
constructor({config, tpl, storage, storageUtils, validator, urlUtils, request}) {
|
||||
this.config = config;
|
||||
this.i18n = i18n;
|
||||
this.tpl = tpl;
|
||||
this.storage = storage;
|
||||
this.storageUtils = storageUtils;
|
||||
this.validator = validator;
|
||||
@ -316,7 +320,7 @@ class ImageSize {
|
||||
});
|
||||
} catch (err) {
|
||||
return reject(new errors.ValidationError({
|
||||
message: this.i18n.t('errors.utils.images.invalidDimensions', {
|
||||
message: this.tpl(messages.invalidDimensions, {
|
||||
file: imagePath,
|
||||
error: err.message
|
||||
})
|
||||
|
@ -4,9 +4,9 @@ const Gravatar = require('./gravatar');
|
||||
const ImageSize = require('./image-size');
|
||||
|
||||
class ImageUtils {
|
||||
constructor({config, logging, i18n, urlUtils, settingsCache, storageUtils, storage, validator, request}) {
|
||||
this.blogIcon = new BlogIcon({config, i18n, urlUtils, settingsCache, storageUtils});
|
||||
this.imageSize = new ImageSize({config, i18n, storage, storageUtils, validator, urlUtils, request});
|
||||
constructor({config, logging, tpl, urlUtils, settingsCache, storageUtils, storage, validator, request}) {
|
||||
this.blogIcon = new BlogIcon({config, tpl, urlUtils, settingsCache, storageUtils});
|
||||
this.imageSize = new ImageSize({config, tpl, storage, storageUtils, validator, urlUtils, request});
|
||||
this.cachedImageSizeFromUrl = new CachedImageSizeFromUrl({logging, imageSize: this.imageSize});
|
||||
this.gravatar = new Gravatar({config, request});
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ const storageUtils = require('../../adapters/storage/utils');
|
||||
const validator = require('@tryghost/validator');
|
||||
const config = require('../../../shared/config');
|
||||
const logging = require('@tryghost/logging');
|
||||
const i18n = require('../../../shared/i18n');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const settingsCache = require('../../../shared/settings-cache');
|
||||
const ImageUtils = require('./image-utils');
|
||||
|
||||
module.exports = new ImageUtils({config, logging, i18n, urlUtils, settingsCache, storageUtils, storage, validator, request});
|
||||
module.exports = new ImageUtils({config, logging, tpl, urlUtils, settingsCache, storageUtils, storage, validator, request});
|
||||
|
@ -236,14 +236,13 @@ describe('lib/image: blog icon', function () {
|
||||
});
|
||||
|
||||
it('[failure] return error message', function (done) {
|
||||
const blogIcon = new BlogIcon({config: {}, i18n: {
|
||||
t: key => key
|
||||
}, storageUtils: {}, urlUtils: {}, settingsCache: {}});
|
||||
const blogIcon = new BlogIcon({config: {}, tpl: key => key
|
||||
, storageUtils: {}, urlUtils: {}, settingsCache: {}});
|
||||
|
||||
blogIcon.getIconDimensions(path.join(__dirname, '../../../../utils/fixtures/images/favicon_multi_sizes_FILE_DOES_NOT_EXIST.ico'))
|
||||
.catch(function (error) {
|
||||
should.exist(error);
|
||||
error.message.should.eql('errors.utils.blogIcon.error');
|
||||
error.message.should.eql('Could not fetch icon dimensions.');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ describe('lib/image: image size', function () {
|
||||
it('[success] should have an image size function', function () {
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {}, storageUtils: {}, validator: {}, urlUtils: {}, request: {}});
|
||||
}, tpl: {}, storage: {}, storageUtils: {}, validator: {}, urlUtils: {}, request: {}});
|
||||
should.exist(imageSize.getImageSizeFromUrl);
|
||||
should.exist(imageSize.getImageSizeFromStoragePath);
|
||||
});
|
||||
@ -38,7 +38,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {}, storageUtils: {
|
||||
}, tpl: {}, storage: {}, storageUtils: {
|
||||
isLocalImage: () => false
|
||||
}, validator: {
|
||||
isURL: () => true
|
||||
@ -66,7 +66,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {}, storageUtils: {
|
||||
}, tpl: {}, storage: {}, storageUtils: {
|
||||
isLocalImage: () => false
|
||||
}, validator: {
|
||||
isURL: () => true
|
||||
@ -103,7 +103,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {}, storageUtils: {
|
||||
}, tpl: {}, storage: {}, storageUtils: {
|
||||
isLocalImage: () => false
|
||||
}, validator: {
|
||||
isURL: () => true
|
||||
@ -131,7 +131,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {}, storageUtils: {
|
||||
}, tpl: {}, storage: {}, storageUtils: {
|
||||
isLocalImage: () => false
|
||||
}, validator: {
|
||||
isURL: () => true
|
||||
@ -171,7 +171,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {}, storageUtils: {
|
||||
}, tpl: {}, storage: {}, storageUtils: {
|
||||
isLocalImage: () => false
|
||||
}, validator: {
|
||||
isURL: () => true
|
||||
@ -217,7 +217,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {}, storageUtils: {
|
||||
}, tpl: {}, storage: {}, storageUtils: {
|
||||
isLocalImage: () => false
|
||||
}, validator: {
|
||||
isURL: () => true
|
||||
@ -253,7 +253,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {}, storageUtils: {
|
||||
}, tpl: {}, storage: {}, storageUtils: {
|
||||
isLocalImage: () => false
|
||||
}, validator: {
|
||||
isURL: () => true
|
||||
@ -293,7 +293,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {
|
||||
}, tpl: {}, storage: {
|
||||
getStorage: () => ({
|
||||
read: obj => fs.promises.readFile(obj.path)
|
||||
})
|
||||
@ -327,7 +327,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {}, storageUtils: {
|
||||
}, tpl: {}, storage: {}, storageUtils: {
|
||||
isLocalImage: () => false
|
||||
}, validator: {
|
||||
isURL: () => true
|
||||
@ -360,7 +360,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {}, storageUtils: {
|
||||
}, tpl: {}, storage: {}, storageUtils: {
|
||||
isLocalImage: () => false
|
||||
}, validator: {
|
||||
isURL: () => true
|
||||
@ -386,7 +386,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {}, storageUtils: {
|
||||
}, tpl: {}, storage: {}, storageUtils: {
|
||||
isLocalImage: () => false
|
||||
}, validator: {
|
||||
isURL: () => false
|
||||
@ -415,7 +415,7 @@ describe('lib/image: image size', function () {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}, i18n: {}, storage: {}, storageUtils: {
|
||||
}, tpl: {}, storage: {}, storageUtils: {
|
||||
isLocalImage: () => false
|
||||
}, validator: {
|
||||
isURL: () => true
|
||||
@ -440,7 +440,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {}, storageUtils: {
|
||||
}, tpl: {}, storage: {}, storageUtils: {
|
||||
isLocalImage: () => false
|
||||
}, validator: {
|
||||
isURL: () => true
|
||||
@ -467,7 +467,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {}, storageUtils: {
|
||||
}, tpl: {}, storage: {}, storageUtils: {
|
||||
isLocalImage: () => false
|
||||
}, validator: {
|
||||
isURL: () => true
|
||||
@ -497,7 +497,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {}, storageUtils: {
|
||||
}, tpl: {}, storage: {}, storageUtils: {
|
||||
isLocalImage: () => false
|
||||
}, validator: {
|
||||
isURL: () => true
|
||||
@ -533,7 +533,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {
|
||||
}, tpl: {}, storage: {
|
||||
getStorage: () => ({
|
||||
read: obj => fs.promises.readFile(obj.path)
|
||||
})
|
||||
@ -576,7 +576,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {
|
||||
}, tpl: {}, storage: {
|
||||
getStorage: () => ({
|
||||
read: obj => fs.promises.readFile(obj.path)
|
||||
})
|
||||
@ -619,7 +619,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {
|
||||
}, tpl: {}, storage: {
|
||||
getStorage: () => ({
|
||||
read: obj => fs.promises.readFile(obj.path)
|
||||
})
|
||||
@ -662,7 +662,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {
|
||||
}, tpl: {}, storage: {
|
||||
getStorage: () => ({
|
||||
read: obj => fs.promises.readFile(obj.path)
|
||||
})
|
||||
@ -700,7 +700,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {
|
||||
}, tpl: {}, storage: {
|
||||
getStorage: () => ({
|
||||
read: () => {
|
||||
return Promise.reject(new errors.NotFoundError());
|
||||
@ -735,7 +735,7 @@ describe('lib/image: image size', function () {
|
||||
|
||||
const imageSize = new ImageSize({config: {
|
||||
get: () => {}
|
||||
}, i18n: {}, storage: {
|
||||
}, tpl: {}, storage: {
|
||||
getStorage: () => ({
|
||||
read: () => {
|
||||
return Promise.resolve(Buffer.from('<svg xmlns="http://www.w3.org/2000/svg viewBox="0 0 100 100>/svg>'));
|
||||
|
Loading…
Reference in New Issue
Block a user