2014-08-29 07:48:49 +04:00
|
|
|
var errors = require('../errors'),
|
2015-01-18 06:54:56 +03:00
|
|
|
config = require('../config'),
|
2014-08-29 07:48:49 +04:00
|
|
|
storage = {};
|
2013-11-07 20:00:39 +04:00
|
|
|
|
2014-08-29 07:48:49 +04:00
|
|
|
function getStorage(storageChoice) {
|
2015-01-18 06:54:56 +03:00
|
|
|
var storagePath,
|
|
|
|
storageConfig;
|
|
|
|
|
|
|
|
storageChoice = config.storage.active;
|
|
|
|
storagePath = config.paths.storage;
|
|
|
|
storageConfig = config.storage[storageChoice];
|
2013-11-07 20:00:39 +04:00
|
|
|
|
2014-08-29 07:48:49 +04:00
|
|
|
if (storage[storageChoice]) {
|
|
|
|
return storage[storageChoice];
|
2013-11-07 20:00:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2014-08-29 07:48:49 +04:00
|
|
|
// TODO: determine if storage has all the necessary methods.
|
2015-01-18 06:54:56 +03:00
|
|
|
storage[storageChoice] = require(storagePath);
|
2013-11-07 20:00:39 +04:00
|
|
|
} catch (e) {
|
|
|
|
errors.logError(e);
|
|
|
|
}
|
2014-08-29 07:48:49 +04:00
|
|
|
|
|
|
|
// Instantiate and cache the storage module instance.
|
2015-01-18 06:54:56 +03:00
|
|
|
storage[storageChoice] = new storage[storageChoice](storageConfig);
|
2014-08-29 07:48:49 +04:00
|
|
|
|
|
|
|
return storage[storageChoice];
|
2013-11-07 20:00:39 +04:00
|
|
|
}
|
|
|
|
|
2014-09-10 08:06:24 +04:00
|
|
|
module.exports.getStorage = getStorage;
|