loopback-component-storage/lib/factory.js

39 lines
930 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';
var handler;
2013-06-24 23:57:16 +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;
2013-06-24 23:57:16 +00:00
}
return handler.createClient(options);
}
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;