mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
parent
55d1e86c55
commit
a639e48715
5 changed files with 19 additions and 23 deletions
|
@ -9,7 +9,8 @@ var Promise = require('bluebird'),
|
||||||
events = require('../events'),
|
events = require('../events'),
|
||||||
storage = require('../storage'),
|
storage = require('../storage'),
|
||||||
settings = require('./settings'),
|
settings = require('./settings'),
|
||||||
utils = require('./utils'),
|
apiUtils = require('./utils'),
|
||||||
|
utils = require('./../utils'),
|
||||||
i18n = require('../i18n'),
|
i18n = require('../i18n'),
|
||||||
themes;
|
themes;
|
||||||
|
|
||||||
|
@ -19,6 +20,13 @@ var Promise = require('bluebird'),
|
||||||
* **See:** [API Methods](index.js.html#api%20methods)
|
* **See:** [API Methods](index.js.html#api%20methods)
|
||||||
*/
|
*/
|
||||||
themes = {
|
themes = {
|
||||||
|
loadThemes: function () {
|
||||||
|
return utils.readThemes(config.paths.themePath)
|
||||||
|
.then(function (result) {
|
||||||
|
config.paths.availableThemes = result;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
upload: function upload(options) {
|
upload: function upload(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
|
@ -37,7 +45,7 @@ themes = {
|
||||||
throw new errors.ValidationError(i18n.t('errors.api.themes.overrideCasper'));
|
throw new errors.ValidationError(i18n.t('errors.api.themes.overrideCasper'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return utils.handlePermissions('themes', 'add')(options)
|
return apiUtils.handlePermissions('themes', 'add')(options)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return gscan.checkZip(zip, {keepExtractedDir: true});
|
return gscan.checkZip(zip, {keepExtractedDir: true});
|
||||||
})
|
})
|
||||||
|
@ -75,7 +83,7 @@ themes = {
|
||||||
// force reload of availableThemes
|
// force reload of availableThemes
|
||||||
// right now the logic is in the ConfigManager
|
// right now the logic is in the ConfigManager
|
||||||
// if we create a theme collection, we don't have to read them from disk
|
// if we create a theme collection, we don't have to read them from disk
|
||||||
return config.loadThemes();
|
return themes.loadThemes();
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
// the settings endpoint is used to fetch the availableThemes
|
// the settings endpoint is used to fetch the availableThemes
|
||||||
|
@ -118,7 +126,7 @@ themes = {
|
||||||
return Promise.reject(new errors.BadRequestError(i18n.t('errors.api.themes.invalidRequest')));
|
return Promise.reject(new errors.BadRequestError(i18n.t('errors.api.themes.invalidRequest')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return utils.handlePermissions('themes', 'read')(options)
|
return apiUtils.handlePermissions('themes', 'read')(options)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
events.emit('theme.downloaded', themeName);
|
events.emit('theme.downloaded', themeName);
|
||||||
return storageAdapter.serve({isTheme: true, name: themeName});
|
return storageAdapter.serve({isTheme: true, name: themeName});
|
||||||
|
@ -134,7 +142,7 @@ themes = {
|
||||||
theme,
|
theme,
|
||||||
storageAdapter = storage.getStorage('themes');
|
storageAdapter = storage.getStorage('themes');
|
||||||
|
|
||||||
return utils.handlePermissions('themes', 'destroy')(options)
|
return apiUtils.handlePermissions('themes', 'destroy')(options)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
if (name === 'casper') {
|
if (name === 'casper') {
|
||||||
throw new errors.ValidationError(i18n.t('errors.api.themes.destroyCasper'));
|
throw new errors.ValidationError(i18n.t('errors.api.themes.destroyCasper'));
|
||||||
|
@ -150,7 +158,7 @@ themes = {
|
||||||
return storageAdapter.delete(name, config.paths.themePath);
|
return storageAdapter.delete(name, config.paths.themePath);
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return config.loadThemes();
|
return themes.loadThemes();
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return settings.updateSettingsCache();
|
return settings.updateSettingsCache();
|
||||||
|
|
|
@ -10,7 +10,6 @@ var path = require('path'),
|
||||||
|
|
||||||
validator = require('validator'),
|
validator = require('validator'),
|
||||||
readDirectory = require('../utils/read-directory'),
|
readDirectory = require('../utils/read-directory'),
|
||||||
readThemes = require('../utils/read-themes'),
|
|
||||||
errors = require('../errors'),
|
errors = require('../errors'),
|
||||||
configUrl = require('./url'),
|
configUrl = require('./url'),
|
||||||
packageInfo = require('../../../package.json'),
|
packageInfo = require('../../../package.json'),
|
||||||
|
@ -78,24 +77,12 @@ ConfigManager.prototype.init = function (rawConfig) {
|
||||||
// just the object appropriate for this NODE_ENV
|
// just the object appropriate for this NODE_ENV
|
||||||
self.set(rawConfig);
|
self.set(rawConfig);
|
||||||
|
|
||||||
return self.loadThemes()
|
return self.loadApps()
|
||||||
.then(function () {
|
|
||||||
return self.loadApps();
|
|
||||||
})
|
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return self._config;
|
return self._config;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ConfigManager.prototype.loadThemes = function () {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
return readThemes(self._config.paths.themePath)
|
|
||||||
.then(function (result) {
|
|
||||||
self._config.paths.availableThemes = result;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ConfigManager.prototype.loadApps = function () {
|
ConfigManager.prototype.loadApps = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
@ -232,7 +219,6 @@ ConfigManager.prototype.set = function (config) {
|
||||||
adminViews: path.join(corePath, '/server/views/'),
|
adminViews: path.join(corePath, '/server/views/'),
|
||||||
helperTemplates: path.join(corePath, '/server/helpers/tpl/'),
|
helperTemplates: path.join(corePath, '/server/helpers/tpl/'),
|
||||||
|
|
||||||
availableThemes: this._config.paths.availableThemes || {},
|
|
||||||
availableApps: this._config.paths.availableApps || {},
|
availableApps: this._config.paths.availableApps || {},
|
||||||
clientAssets: path.join(corePath, '/built/assets/')
|
clientAssets: path.join(corePath, '/built/assets/')
|
||||||
},
|
},
|
||||||
|
|
|
@ -74,6 +74,8 @@ function init(options) {
|
||||||
// Load our config.js file from the local file system.
|
// Load our config.js file from the local file system.
|
||||||
return config.load(options.config).then(function () {
|
return config.load(options.config).then(function () {
|
||||||
return config.checkDeprecated();
|
return config.checkDeprecated();
|
||||||
|
}).then(function () {
|
||||||
|
return api.themes.loadThemes();
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
models.init();
|
models.init();
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
|
|
|
@ -102,7 +102,8 @@ utils = {
|
||||||
|
|
||||||
readCSV: require('./read-csv'),
|
readCSV: require('./read-csv'),
|
||||||
removeOpenRedirectFromUrl: require('./remove-open-redirect-from-url'),
|
removeOpenRedirectFromUrl: require('./remove-open-redirect-from-url'),
|
||||||
zipFolder: require('./zip-folder')
|
zipFolder: require('./zip-folder'),
|
||||||
|
readThemes: require('./read-themes')
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = utils;
|
module.exports = utils;
|
||||||
|
|
|
@ -110,7 +110,6 @@ describe('Config', function () {
|
||||||
'imagesRelPath',
|
'imagesRelPath',
|
||||||
'adminViews',
|
'adminViews',
|
||||||
'helperTemplates',
|
'helperTemplates',
|
||||||
'availableThemes',
|
|
||||||
'availableApps',
|
'availableApps',
|
||||||
'clientAssets'
|
'clientAssets'
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue