0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Renamed getLocalFileStoragePath

refs https://github.com/TryGhost/Toolbox/issues/95

- getLocalImagesStoragePath makes a lot more sense in context of what the method really does
This commit is contained in:
Naz 2021-11-05 16:38:04 +04:00
parent 12cad62a53
commit ad2583530a
6 changed files with 19 additions and 19 deletions

View file

@ -12,7 +12,7 @@ const urlUtils = require('../../../shared/url-utils');
* @description Takes a url or filepath and returns a filepath with is readable
* for the local file storage.
*/
exports.getLocalFileStoragePath = function getLocalFileStoragePath(imagePath) {
exports.getLocalImagesStoragePath = function getLocalImagesStoragePath(imagePath) {
// The '/' in urlJoin is necessary to add the '/' to `content/images`, if no subdirectory is setup
const urlRegExp = new RegExp(`^${urlUtils.urlJoin(
urlUtils.urlFor('home', true),
@ -43,7 +43,7 @@ exports.getLocalFileStoragePath = function getLocalFileStoragePath(imagePath) {
*/
exports.isLocalImage = function isLocalImage(imagePath) {
const localImagePath = this.getLocalFileStoragePath(imagePath);
const localImagePath = this.getLocalImagesStoragePath(imagePath);
if (localImagePath !== imagePath) {
return true;

View file

@ -115,7 +115,7 @@ class BlogIcon {
const blogIcon = this.settingsCache.get('icon');
if (blogIcon) {
return this.storageUtils.getLocalFileStoragePath(blogIcon);
return this.storageUtils.getLocalImagesStoragePath(blogIcon);
} else {
return path.join(this.config.get('paths:publicFilePath'), 'favicon.ico');
}

View file

@ -214,7 +214,7 @@ class ImageSize {
imagePath = this.urlUtils.urlFor('image', {image: imagePath}, true);
// get the storage readable filePath
filePath = this.storageUtils.getLocalFileStoragePath(imagePath);
filePath = this.storageUtils.getLocalImagesStoragePath(imagePath);
return this.storage.getStorage('images')
.read({path: filePath})

View file

@ -17,7 +17,7 @@ describe('storage utils', function () {
sinon.restore();
});
describe('fn: getLocalFileStoragePath', function () {
describe('fn: getLocalImagesStoragePath', function () {
it('should return local file storage path for absolute URL', function () {
const url = 'http://myblog.com/content/images/2017/07/ghost-logo.png';
let result;
@ -27,7 +27,7 @@ describe('storage utils', function () {
urlGetSubdirStub = sinon.stub(urlUtils, 'getSubdir');
urlGetSubdirStub.returns('');
result = storageUtils.getLocalFileStoragePath(url);
result = storageUtils.getLocalImagesStoragePath(url);
should.exist(result);
result.should.be.equal('/2017/07/ghost-logo.png');
});
@ -41,7 +41,7 @@ describe('storage utils', function () {
urlGetSubdirStub = sinon.stub(urlUtils, 'getSubdir');
urlGetSubdirStub.returns('/blog');
result = storageUtils.getLocalFileStoragePath(url);
result = storageUtils.getLocalImagesStoragePath(url);
should.exist(result);
result.should.be.equal('/2017/07/ghost-logo.png');
});
@ -55,7 +55,7 @@ describe('storage utils', function () {
urlGetSubdirStub = sinon.stub(urlUtils, 'getSubdir');
urlGetSubdirStub.returns('');
result = storageUtils.getLocalFileStoragePath(filePath);
result = storageUtils.getLocalImagesStoragePath(filePath);
should.exist(result);
result.should.be.equal('/2017/07/ghost-logo.png');
});
@ -69,7 +69,7 @@ describe('storage utils', function () {
urlGetSubdirStub = sinon.stub(urlUtils, 'getSubdir');
urlGetSubdirStub.returns('/blog');
result = storageUtils.getLocalFileStoragePath(filePath);
result = storageUtils.getLocalImagesStoragePath(filePath);
should.exist(result);
result.should.be.equal('/2017/07/ghost-logo.png');
});
@ -83,7 +83,7 @@ describe('storage utils', function () {
urlGetSubdirStub = sinon.stub(urlUtils, 'getSubdir');
urlGetSubdirStub.returns('');
result = storageUtils.getLocalFileStoragePath(url);
result = storageUtils.getLocalImagesStoragePath(url);
should.exist(result);
result.should.be.equal('http://example-blog.com/ghost-logo.png');
});

View file

@ -83,7 +83,7 @@ describe('lib/image: blog icon', function () {
it('custom uploaded ico blog icon', function () {
const stub = sinon.stub();
const blogIcon = new BlogIcon({config: {}, storageUtils: {
getLocalFileStoragePath: stub
getLocalImagesStoragePath: stub
}, urlUtils: {}, settingsCache: {
get: (key) => {
if (key === 'icon') {
@ -99,7 +99,7 @@ describe('lib/image: blog icon', function () {
it('custom uploaded png blog icon', function () {
const stub = sinon.stub();
const blogIcon = new BlogIcon({config: {}, storageUtils: {
getLocalFileStoragePath: stub
getLocalImagesStoragePath: stub
}, urlUtils: {}, settingsCache: {
get: (key) => {
if (key === 'icon') {

View file

@ -299,7 +299,7 @@ describe('lib/image: image size', function () {
})
}, storageUtils: {
isLocalImage: () => true,
getLocalFileStoragePath: imageUrl => path.join(storagePath, imageUrl.replace(/.*\//, ''))
getLocalImagesStoragePath: imageUrl => path.join(storagePath, imageUrl.replace(/.*\//, ''))
}, validator: {}, urlUtils: {
urlFor: urlForStub,
getSubdir: urlGetSubdirStub
@ -539,7 +539,7 @@ describe('lib/image: image size', function () {
})
}, storageUtils: {
isLocalImage: () => true,
getLocalFileStoragePath: imageUrl => path.join(storagePath, imageUrl.replace(/.*\//, ''))
getLocalImagesStoragePath: imageUrl => path.join(storagePath, imageUrl.replace(/.*\//, ''))
}, validator: {}, urlUtils: {
urlFor: urlForStub,
getSubdir: urlGetSubdirStub
@ -582,7 +582,7 @@ describe('lib/image: image size', function () {
})
}, storageUtils: {
isLocalImage: () => true,
getLocalFileStoragePath: imageUrl => path.join(storagePath, imageUrl.replace(/.*\//, ''))
getLocalImagesStoragePath: imageUrl => path.join(storagePath, imageUrl.replace(/.*\//, ''))
}, validator: {}, urlUtils: {
urlFor: urlForStub,
getSubdir: urlGetSubdirStub
@ -625,7 +625,7 @@ describe('lib/image: image size', function () {
})
}, storageUtils: {
isLocalImage: () => true,
getLocalFileStoragePath: imageUrl => path.join(storagePath, imageUrl.replace(/.*\//, ''))
getLocalImagesStoragePath: imageUrl => path.join(storagePath, imageUrl.replace(/.*\//, ''))
}, validator: {}, urlUtils: {
urlFor: urlForStub,
getSubdir: urlGetSubdirStub
@ -668,7 +668,7 @@ describe('lib/image: image size', function () {
})
}, storageUtils: {
isLocalImage: () => true,
getLocalFileStoragePath: imageUrl => path.join(storagePath, imageUrl.replace(/.*\//, ''))
getLocalImagesStoragePath: imageUrl => path.join(storagePath, imageUrl.replace(/.*\//, ''))
}, validator: {}, urlUtils: {
urlFor: urlForStub,
getSubdir: urlGetSubdirStub
@ -708,7 +708,7 @@ describe('lib/image: image size', function () {
})
}, storageUtils: {
isLocalImage: () => true,
getLocalFileStoragePath: imageUrl => path.join(storagePath, imageUrl.replace(/.*\//, ''))
getLocalImagesStoragePath: imageUrl => path.join(storagePath, imageUrl.replace(/.*\//, ''))
}, validator: {}, urlUtils: {
urlFor: urlForStub,
getSubdir: urlGetSubdirStub
@ -743,7 +743,7 @@ describe('lib/image: image size', function () {
})
}, storageUtils: {
isLocalImage: () => true,
getLocalFileStoragePath: () => ''
getLocalImagesStoragePath: () => ''
}, validator: {}, urlUtils: {
urlFor: urlForStub,
getSubdir: urlGetSubdirStub