mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Simplified image size cache module constructor
refs https://github.com/TryGhost/Toolbox/issues/364 - As little as possible should be passed in in the parameters for any method/constructor/whatever. Specific Function > vague Object
This commit is contained in:
parent
58a656cbc2
commit
e549528985
3 changed files with 8 additions and 14 deletions
|
@ -6,11 +6,11 @@ class CachedImageSizeFromUrl {
|
|||
/**
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Object} options.imageSize - instance with "getImageSizeFromUrl" method
|
||||
* @param {Function} options.getImageSizeFromUrl - method that resolves images based on URL
|
||||
* @param {Object} options.cache - cache store instance
|
||||
*/
|
||||
constructor({imageSize, cache}) {
|
||||
this.imageSize = imageSize;
|
||||
constructor({getImageSizeFromUrl, cache}) {
|
||||
this.getImageSizeFromUrl = getImageSizeFromUrl;
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ class CachedImageSizeFromUrl {
|
|||
return cachedImageSize;
|
||||
} else {
|
||||
try {
|
||||
const res = await this.imageSize.getImageSizeFromUrl(url);
|
||||
const res = await this.getImageSizeFromUrl(url);
|
||||
this.cache.set(url, res);
|
||||
|
||||
debug('Cached image:', url);
|
||||
|
|
|
@ -8,7 +8,7 @@ class ImageUtils {
|
|||
this.blogIcon = new BlogIcon({config, urlUtils, settingsCache, storageUtils});
|
||||
this.imageSize = new ImageSize({config, storage, storageUtils, validator, urlUtils, request});
|
||||
this.cachedImageSizeFromUrl = new CachedImageSizeFromUrl({
|
||||
imageSize: this.imageSize,
|
||||
getImageSizeFromUrl: this.imageSize.getImageSizeFromUrl.bind(this.imageSize),
|
||||
cache: new Map()
|
||||
});
|
||||
this.gravatar = new Gravatar({config, request});
|
||||
|
|
|
@ -26,9 +26,7 @@ describe('lib/image: image size cache', function () {
|
|||
});
|
||||
|
||||
const cachedImageSizeFromUrl = new CachedImageSizeFromUrl({
|
||||
imageSize: {
|
||||
getImageSizeFromUrl: sizeOfStub
|
||||
},
|
||||
getImageSizeFromUrl: sizeOfStub,
|
||||
cache: new Map()
|
||||
});
|
||||
|
||||
|
@ -67,9 +65,7 @@ describe('lib/image: image size cache', function () {
|
|||
sizeOfStub.rejects('error');
|
||||
|
||||
const cachedImageSizeFromUrl = new CachedImageSizeFromUrl({
|
||||
imageSize: {
|
||||
getImageSizeFromUrl: sizeOfStub
|
||||
},
|
||||
getImageSizeFromUrl: sizeOfStub,
|
||||
cache: new Map()
|
||||
});
|
||||
|
||||
|
@ -89,9 +85,7 @@ describe('lib/image: image size cache', function () {
|
|||
sizeOfStub.rejects(new errors.NotFoundError('it iz gone mate!'));
|
||||
|
||||
const cachedImageSizeFromUrl = new CachedImageSizeFromUrl({
|
||||
imageSize: {
|
||||
getImageSizeFromUrl: sizeOfStub
|
||||
},
|
||||
getImageSizeFromUrl: sizeOfStub,
|
||||
cache: new Map()
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue