0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Made storage calls related to images use "images" feature

refs https://linear.app/tryghost/issue/CORE-1/multiple-adapters-per-type

- Having this preemptive change allows to separate implementation of "image" storage from future usecases like "videos", "audios" etc. Even if the "image" adapter is not configured the default behavior will fallback to use the "active" storage adapter. If there's a need to handle "images" differently through a custom apapter that'll work out of the box ;)
This commit is contained in:
Naz 2021-10-20 19:22:09 +04:00 committed by naz
parent f890d8d4cd
commit 07afb08875
10 changed files with 12 additions and 11 deletions

View file

@ -7,7 +7,7 @@ module.exports = {
statusCode: 201, statusCode: 201,
permissions: false, permissions: false,
query(frame) { query(frame) {
const store = storage.getStorage(); const store = storage.getStorage('images');
if (frame.files) { if (frame.files) {
return Promise return Promise

View file

@ -7,7 +7,7 @@ module.exports = {
statusCode: 201, statusCode: 201,
permissions: false, permissions: false,
query(frame) { query(frame) {
const store = storage.getStorage(); const store = storage.getStorage('images');
if (frame.files) { if (frame.files) {
return Promise return Promise

View file

@ -7,7 +7,7 @@ module.exports = {
statusCode: 201, statusCode: 201,
permissions: false, permissions: false,
query(frame) { query(frame) {
const store = storage.getStorage(); const store = storage.getStorage('images');
if (frame.files) { if (frame.files) {
return Promise return Promise

View file

@ -13,7 +13,7 @@ ImageHandler = {
directories: ['images', 'content'], directories: ['images', 'content'],
loadFile: function (files, baseDir) { loadFile: function (files, baseDir) {
const store = storage.getStorage(); const store = storage.getStorage('images');
const baseDirRegex = baseDir ? new RegExp('^' + baseDir + '/') : new RegExp(''); const baseDirRegex = baseDir ? new RegExp('^' + baseDir + '/') : new RegExp('');
const imageFolderRegexes = _.map(urlUtils.STATIC_IMAGE_URL_PREFIX.split('/'), function (dir) { const imageFolderRegexes = _.map(urlUtils.STATIC_IMAGE_URL_PREFIX.split('/'), function (dir) {

View file

@ -64,7 +64,7 @@ ImageImporter = {
return importData; return importData;
}, },
doImport: function (imageData) { doImport: function (imageData) {
const store = storage.getStorage(); const store = storage.getStorage('images');
return Promise.map(imageData, function (image) { return Promise.map(imageData, function (image) {
return store.save(image, image.targetDir).then(function (result) { return store.save(image, image.targetDir).then(function (result) {

View file

@ -216,7 +216,7 @@ class ImageSize {
// get the storage readable filePath // get the storage readable filePath
filePath = this.storageUtils.getLocalFileStoragePath(imagePath); filePath = this.storageUtils.getLocalFileStoragePath(imagePath);
return this.storage.getStorage() return this.storage.getStorage('images')
.read({path: filePath}) .read({path: filePath})
.then((buf) => { .then((buf) => {
debug('Image fetched (storage):', filePath); debug('Image fetched (storage):', filePath);
@ -267,7 +267,7 @@ class ImageSize {
} }
const originalImagePath = path.join(dir, `${imageName}_o${imageNumber || ''}${ext}`); const originalImagePath = path.join(dir, `${imageName}_o${imageNumber || ''}${ext}`);
const originalImageExists = await this.storage.getStorage().exists(originalImagePath); const originalImageExists = await this.storage.getStorage('images').exists(originalImagePath);
return this.getImageSizeFromStoragePath(originalImageExists ? originalImagePath : imagePath); return this.getImageSizeFromStoragePath(originalImageExists ? originalImagePath : imagePath);
} }

View file

@ -36,9 +36,10 @@ module.exports = {
canTransformImage(storagePath) { canTransformImage(storagePath) {
const {ext} = path.parse(storagePath); const {ext} = path.parse(storagePath);
// NOTE: the "saveRaw" check is smelly
return imageTransform.canTransformFiles() return imageTransform.canTransformFiles()
&& imageTransform.canTransformFileExtension(ext) && imageTransform.canTransformFileExtension(ext)
&& typeof storage.getStorage().saveRaw === 'function'; && typeof storage.getStorage('images').saveRaw === 'function';
} }
}); });

View file

@ -107,7 +107,7 @@ module.exports = function setupSiteApp(options = {}) {
siteApp.use(mw.servePublicFile('public/ghost.min.css', 'text/css', constants.ONE_YEAR_S)); siteApp.use(mw.servePublicFile('public/ghost.min.css', 'text/css', constants.ONE_YEAR_S));
// Serve blog images using the storage adapter // Serve blog images using the storage adapter
siteApp.use(STATIC_IMAGE_URL_PREFIX, mw.handleImageSizes, storage.getStorage().serve()); siteApp.use(STATIC_IMAGE_URL_PREFIX, mw.handleImageSizes, storage.getStorage('images').serve());
// @TODO find this a better home // @TODO find this a better home
// We do this here, at the top level, because helpers require so much stuff. // We do this here, at the top level, because helpers require so much stuff.

View file

@ -63,7 +63,7 @@ module.exports = function (req, res, next) {
return redirectToOriginal(); return redirectToOriginal();
} }
const storageInstance = storage.getStorage(); const storageInstance = storage.getStorage('images');
// CASE: unsupported storage adapter // CASE: unsupported storage adapter
if (typeof storageInstance.saveRaw !== 'function') { if (typeof storageInstance.saveRaw !== 'function') {
return redirectToOriginal(); return redirectToOriginal();

View file

@ -49,7 +49,7 @@ function serveFavicon() {
return res.redirect(302, urlUtils.urlFor({relativeUrl: `/favicon${originalExtension}`})); return res.redirect(302, urlUtils.urlFor({relativeUrl: `/favicon${originalExtension}`}));
} }
storage.getStorage() storage.getStorage('images')
.read({path: filePath}) .read({path: filePath})
.then((buf) => { .then((buf) => {
iconType = blogIcon.getIconType(); iconType = blogIcon.getIconType();