Enabled passing through a feature name to utilize with a storage adapter

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

- When the storage is requested the caller can now specify a "feature" they want to use the storage for. For example there could be different configurations for "images" or "vidoes" storages and the caller would not necessarily have to know about the details of how the feature is implemented.
This commit is contained in:
Naz 2021-10-20 19:13:15 +04:00 committed by naz
parent 98c27b5555
commit f890d8d4cd

View File

@ -1,7 +1,17 @@
const adapterManager = require('../../services/adapter-manager');
function getStorage() {
return adapterManager.getAdapter('storage');
/**
* @param {'images'|'videos'|'audios'} [feature] - name for the "feature" to enable through adapter, e.g.: images or videos storage
* @returns {Object} adapter instance
*/
function getStorage(feature) {
let adapterName = 'storage';
if (feature) {
adapterName += `:${feature}`;
}
return adapterManager.getAdapter(adapterName);
}
module.exports.getStorage = getStorage;