2020-04-05 19:52:46 +03:00
|
|
|
const AdapterManager = require('@tryghost/adapter-manager');
|
|
|
|
const getAdapterServiceConfig = require('./config');
|
2021-10-20 18:03:58 +03:00
|
|
|
const resolveAdapterOptions = require('./options-resolver');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../../../shared/config');
|
2020-04-05 19:52:46 +03:00
|
|
|
|
|
|
|
const adapterManager = new AdapterManager({
|
|
|
|
loadAdapterFromPath: require,
|
|
|
|
pathsToAdapters: [
|
|
|
|
'', // A blank path will cause us to check node_modules for the adapter
|
|
|
|
config.getContentPath('adapters'),
|
|
|
|
config.get('paths').internalAdaptersPath
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
adapterManager.registerAdapter('storage', require('ghost-storage-base'));
|
|
|
|
adapterManager.registerAdapter('scheduling', require('../../adapters/scheduling/SchedulingBase'));
|
2020-04-05 19:52:47 +03:00
|
|
|
adapterManager.registerAdapter('sso', require('../../adapters/sso/Base'));
|
2020-04-05 19:52:46 +03:00
|
|
|
|
|
|
|
module.exports = {
|
2021-10-20 18:03:58 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {String} name - one of 'storage', 'scheduling', 'sso' etc. Or can contain a "resource" extension like "storage:image"
|
|
|
|
* @returns {Object} instance of an adapter
|
|
|
|
*/
|
|
|
|
getAdapter(name) {
|
2020-04-05 19:52:46 +03:00
|
|
|
const adapterServiceConfig = getAdapterServiceConfig(config);
|
|
|
|
|
2021-10-20 18:03:58 +03:00
|
|
|
const {adapterType, adapterName, adapterConfig} = resolveAdapterOptions(name, adapterServiceConfig);
|
2020-04-05 19:52:46 +03:00
|
|
|
|
2021-10-20 18:03:58 +03:00
|
|
|
return adapterManager.getAdapter(adapterType, adapterName, adapterConfig);
|
2020-04-05 19:52:46 +03:00
|
|
|
}
|
|
|
|
};
|