mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 12:53:13 +03:00
98c27b5555
refs https://linear.app/tryghost/issue/CORE-1/multiple-adapters-per-type - There's a need to support multiple adapter variations per given adapter type (storage, sso, etc.) - With the introduced changes we can specify a version of an adapter that should be fetched based on `:feature` postfix. For example: `adapterManager.getAdapter('storage')` - would return the default adapter listed under "active" configuration `adapterManager.getAdapter('storage:videos') - would return an adapter configured for videos *feature* - Here's an example configuration for a custom video storage: ``` "storage": { "active": "LocalFileStorage", "videos": "ghost-storage-custom-video", "ghost-storage-custom-video": { "custom": "configHere" } } ```
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
const AdapterManager = require('@tryghost/adapter-manager');
|
|
const getAdapterServiceConfig = require('./config');
|
|
const resolveAdapterOptions = require('./options-resolver');
|
|
const config = require('../../../shared/config');
|
|
|
|
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'));
|
|
adapterManager.registerAdapter('sso', require('../../adapters/sso/Base'));
|
|
|
|
module.exports = {
|
|
/**
|
|
*
|
|
* @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) {
|
|
const adapterServiceConfig = getAdapterServiceConfig(config);
|
|
|
|
const {adapterType, adapterName, adapterConfig} = resolveAdapterOptions(name, adapterServiceConfig);
|
|
|
|
return adapterManager.getAdapter(adapterType, adapterName, adapterConfig);
|
|
}
|
|
};
|