loopback-component-storage/lib/factory.js

36 lines
932 B
JavaScript
Raw Normal View History

/**
* Create a client instance based on the options
* @param options
* @returns {*}
*/
function createClient(options) {
2013-06-24 23:57:16 +00:00
options = options || {};
2013-06-25 16:29:53 +00:00
var provider = options.provider || 'filesystem';
2013-06-24 23:57:16 +00:00
try {
// Try to load the provider from providers folder
provider = require('./providers/' + provider);
return provider.createClient(options);
} catch (err) {
// Fall back to pkgcloud
return require('pkgcloud').storage.createClient(options);
2013-06-24 23:57:16 +00:00
}
}
2013-06-24 23:57:16 +00:00
/**
* Look up a provider by name
* @param provider
* @returns {*}
*/
function getProvider(provider) {
try {
// Try to load the provider from providers folder
return require('./providers/' + provider);
} catch (err) {
// Fall back to pkgcloud
return require('pkgcloud').providers[provider];
}
2013-07-02 14:54:58 +00:00
}
module.exports.createClient = createClient;
module.exports.getProvider = getProvider;