Ghost/core/server/services/adapter-manager/options-resolver.js
Naz 98c27b5555 Added multiple adapters capability to adapter manager
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"
    }
}
```
2021-10-21 20:22:45 +13:00

19 lines
735 B
JavaScript

module.exports = function resolveAdapterOptions(name, adapterServiceConfig) {
const [adapterType, feature] = name.split(':');
const adapterSettings = adapterServiceConfig[adapterType];
let adapterName;
let adapterConfig;
// CASE: load resource-specific adapter when there is an adapter feature name specified as well as custom feature config
if (feature && adapterSettings[feature] && adapterSettings[adapterSettings[feature]]) {
adapterName = adapterSettings[feature];
adapterConfig = adapterSettings[adapterName];
} else {
adapterName = adapterSettings.active;
adapterConfig = adapterSettings[adapterName];
}
return {adapterType, adapterName, adapterConfig};
};