loopback-component-storage/lib/factory.js

39 lines
875 B
JavaScript
Raw Normal View History

/**
* Create a client instance based on the options
* @param options
* @returns {*}
*/
function createClient(options) {
2014-01-24 17:44:58 +00:00
options = options || {};
var provider = options.provider || 'filesystem';
var handler;
2013-06-24 23:57:16 +00:00
2014-01-24 17:44:58 +00:00
try {
// Try to load the provider from providers folder
handler = require('./providers/' + provider);
} catch (err) {
// Fall back to pkgcloud
handler = require('pkgcloud').storage;
}
return handler.createClient(options);
}
2013-06-24 23:57:16 +00:00
/**
* Look up a provider by name
* @param provider
* @returns {*}
*/
function getProvider(provider) {
2014-01-24 17:44:58 +00:00
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;