mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
eef7932e94
refs #8868 - Removed image-size in blog logo fn for meta data and made it synchronous - Renamed `image-size-from-url.js` to `image-size.js` (incl. the test) - Added second fn `getImageSizeFromFilePath` that reads from local file storage - Added guard in `getImageSizeFromUrl` that checks if the image should be on local file storage and uses the new fn then instead - Added a fn `fetchDimensionsFromBuffer` that takes the file buffer and returns an `imageObject` with dimensions. - Added a new utils.js in `adapters/storage` for getting the file storage path
27 lines
1.5 KiB
JavaScript
27 lines
1.5 KiB
JavaScript
var globalUtils = require('../../utils');
|
|
|
|
/**
|
|
* @TODO: move `index.js` to here - e.g. storageUtils.getStorage
|
|
*/
|
|
|
|
/**
|
|
* Sanitizes a given URL or path for an image to be readable by the local file storage
|
|
* Always returns {string} url
|
|
* @param {string} imagePath
|
|
* @returns {string} imagePath
|
|
* @description Takes a url or filepath and returns a filepath with is readable
|
|
* for the local file storage.
|
|
*/
|
|
exports.getLocalFileStoragePath = function getLocalFileStoragePath(imagePath) {
|
|
if (imagePath.match(new RegExp('^' + globalUtils.url.urlJoin(globalUtils.url.urlFor('home', true), globalUtils.url.getSubdir(), '/', globalUtils.url.STATIC_IMAGE_URL_PREFIX)))) {
|
|
// Storage needs the path without `/content/images/` prefix
|
|
// The '/' in urlJoin is necessary to add the '/' to `content/images`, if no subdirectory is setup
|
|
return imagePath.replace(new RegExp('^' + globalUtils.url.urlJoin(globalUtils.url.urlFor('home', true), globalUtils.url.getSubdir(), '/', globalUtils.url.STATIC_IMAGE_URL_PREFIX)), '');
|
|
} else if (imagePath.match(new RegExp('^' + globalUtils.url.urlJoin(globalUtils.url.getSubdir(), '/', globalUtils.url.STATIC_IMAGE_URL_PREFIX)))) {
|
|
// Storage needs the path without `/content/images/` prefix
|
|
// The '/' in urlJoin is necessary to add the '/' to `content/images`, if no subdirectory is setup
|
|
return imagePath.replace(new RegExp('^' + globalUtils.url.urlJoin(globalUtils.url.getSubdir(), '/', globalUtils.url.STATIC_IMAGE_URL_PREFIX)), '');
|
|
} else {
|
|
return imagePath;
|
|
}
|
|
};
|