mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Initial implementation for custom storage engines
closes #4600 - implemented as suggested in #4600 - loads a custom storage defined in config from the /content/storage directory
This commit is contained in:
parent
e07ec3ef84
commit
5c640e95f5
3 changed files with 58 additions and 5 deletions
|
@ -108,7 +108,10 @@ function configureDriver(client) {
|
||||||
*/
|
*/
|
||||||
ConfigManager.prototype.set = function (config) {
|
ConfigManager.prototype.set = function (config) {
|
||||||
var localPath = '',
|
var localPath = '',
|
||||||
|
defaultStorage = 'local-file-store',
|
||||||
contentPath,
|
contentPath,
|
||||||
|
activeStorage,
|
||||||
|
storagePath,
|
||||||
subdir,
|
subdir,
|
||||||
assetHash;
|
assetHash;
|
||||||
|
|
||||||
|
@ -146,6 +149,18 @@ ConfigManager.prototype.set = function (config) {
|
||||||
knexInstance = knex(this._config.database);
|
knexInstance = knex(this._config.database);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Protect against accessing a non-existant object.
|
||||||
|
// This ensures there's always at least a storage object
|
||||||
|
// because it's referenced in multiple places.
|
||||||
|
this._config.storage = this._config.storage || {};
|
||||||
|
activeStorage = this._config.storage.active || defaultStorage;
|
||||||
|
|
||||||
|
if (activeStorage === defaultStorage) {
|
||||||
|
storagePath = path.join(corePath, '/server/storage/');
|
||||||
|
} else {
|
||||||
|
storagePath = path.join(contentPath, 'storage');
|
||||||
|
}
|
||||||
|
|
||||||
_.merge(this._config, {
|
_.merge(this._config, {
|
||||||
database: {
|
database: {
|
||||||
knex: knexInstance
|
knex: knexInstance
|
||||||
|
@ -158,6 +173,8 @@ ConfigManager.prototype.set = function (config) {
|
||||||
configExample: path.join(appRoot, 'config.example.js'),
|
configExample: path.join(appRoot, 'config.example.js'),
|
||||||
corePath: corePath,
|
corePath: corePath,
|
||||||
|
|
||||||
|
storage: path.join(storagePath, activeStorage),
|
||||||
|
|
||||||
contentPath: contentPath,
|
contentPath: contentPath,
|
||||||
themePath: path.resolve(contentPath, 'themes'),
|
themePath: path.resolve(contentPath, 'themes'),
|
||||||
appPath: path.resolve(contentPath, 'apps'),
|
appPath: path.resolve(contentPath, 'apps'),
|
||||||
|
@ -173,6 +190,9 @@ ConfigManager.prototype.set = function (config) {
|
||||||
availableApps: this._config.paths.availableApps || {},
|
availableApps: this._config.paths.availableApps || {},
|
||||||
builtScriptPath: path.join(corePath, 'built/scripts/')
|
builtScriptPath: path.join(corePath, 'built/scripts/')
|
||||||
},
|
},
|
||||||
|
storage: {
|
||||||
|
active: activeStorage
|
||||||
|
},
|
||||||
theme: {
|
theme: {
|
||||||
// normalise the URL by removing any trailing slash
|
// normalise the URL by removing any trailing slash
|
||||||
url: this._config.url ? this._config.url.replace(/\/$/, '') : ''
|
url: this._config.url ? this._config.url.replace(/\/$/, '') : ''
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
var errors = require('../errors'),
|
var errors = require('../errors'),
|
||||||
|
config = require('../config'),
|
||||||
storage = {};
|
storage = {};
|
||||||
|
|
||||||
function getStorage(storageChoice) {
|
function getStorage(storageChoice) {
|
||||||
// TODO: this is where the check for storage apps should go
|
var storagePath,
|
||||||
// Local file system is the default. Fow now that is all we support.
|
storageConfig;
|
||||||
storageChoice = 'local-file-store';
|
|
||||||
|
storageChoice = config.storage.active;
|
||||||
|
storagePath = config.paths.storage;
|
||||||
|
storageConfig = config.storage[storageChoice];
|
||||||
|
|
||||||
if (storage[storageChoice]) {
|
if (storage[storageChoice]) {
|
||||||
return storage[storageChoice];
|
return storage[storageChoice];
|
||||||
|
@ -12,13 +16,13 @@ function getStorage(storageChoice) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO: determine if storage has all the necessary methods.
|
// TODO: determine if storage has all the necessary methods.
|
||||||
storage[storageChoice] = require('./' + storageChoice);
|
storage[storageChoice] = require(storagePath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errors.logError(e);
|
errors.logError(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instantiate and cache the storage module instance.
|
// Instantiate and cache the storage module instance.
|
||||||
storage[storageChoice] = new storage[storageChoice]();
|
storage[storageChoice] = new storage[storageChoice](storageConfig);
|
||||||
|
|
||||||
return storage[storageChoice];
|
return storage[storageChoice];
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,7 @@ describe('Config', function () {
|
||||||
'subdir',
|
'subdir',
|
||||||
'config',
|
'config',
|
||||||
'configExample',
|
'configExample',
|
||||||
|
'storage',
|
||||||
'contentPath',
|
'contentPath',
|
||||||
'corePath',
|
'corePath',
|
||||||
'themePath',
|
'themePath',
|
||||||
|
@ -147,6 +148,34 @@ describe('Config', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Storage', function () {
|
||||||
|
afterEach(function () {
|
||||||
|
resetConfig();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should default to local-file-store', function () {
|
||||||
|
var storagePath = path.join(config.paths.corePath, '/server/storage/', 'local-file-store');
|
||||||
|
|
||||||
|
config.paths.should.have.property('storage', storagePath);
|
||||||
|
config.storage.should.have.property('active', 'local-file-store');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow setting a custom active storage', function () {
|
||||||
|
var storagePath = path.join(config.paths.contentPath, 'storage', 's3');
|
||||||
|
|
||||||
|
config.set({
|
||||||
|
storage: {
|
||||||
|
active: 's3',
|
||||||
|
s3: {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
config.paths.should.have.property('storage', storagePath);
|
||||||
|
config.storage.should.have.property('active', 's3');
|
||||||
|
config.storage.should.have.property('s3', {});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('urlFor', function () {
|
describe('urlFor', function () {
|
||||||
before(function () {
|
before(function () {
|
||||||
resetConfig();
|
resetConfig();
|
||||||
|
|
Loading…
Add table
Reference in a new issue