2014-08-21 01:42:34 +04:00
|
|
|
// # Configuration API
|
|
|
|
// RESTful API for browsing the configuration
|
2017-09-12 18:31:14 +03:00
|
|
|
var Promise = require('bluebird'),
|
|
|
|
_ = require('lodash'),
|
2017-12-11 21:14:05 +03:00
|
|
|
urlService = require('../services/url'),
|
2017-09-12 18:31:14 +03:00
|
|
|
models = require('../models'),
|
|
|
|
config = require('../config'),
|
2017-12-14 05:01:23 +03:00
|
|
|
settingsCache = require('../services/settings/cache'),
|
2017-12-15 00:14:55 +03:00
|
|
|
ghostVersion = require('../lib/ghost-version'),
|
2014-08-21 01:42:34 +04:00
|
|
|
configuration;
|
|
|
|
|
2016-02-17 16:58:44 +03:00
|
|
|
function fetchAvailableTimezones() {
|
|
|
|
var timezones = require('../data/timezones.json');
|
|
|
|
return timezones;
|
|
|
|
}
|
|
|
|
|
2016-02-19 21:18:14 +03:00
|
|
|
function getAboutConfig() {
|
|
|
|
return {
|
2016-10-10 22:14:32 +03:00
|
|
|
version: ghostVersion.full,
|
2016-10-11 15:53:52 +03:00
|
|
|
environment: config.get('env'),
|
2016-09-13 18:41:14 +03:00
|
|
|
database: config.get('database').client,
|
|
|
|
mail: _.isObject(config.get('mail')) ? config.get('mail').transport : ''
|
2016-02-19 21:18:14 +03:00
|
|
|
};
|
2014-08-21 01:42:34 +04:00
|
|
|
}
|
|
|
|
|
2016-02-19 21:18:14 +03:00
|
|
|
function getBaseConfig() {
|
2016-01-19 18:43:09 +03:00
|
|
|
return {
|
2017-11-01 16:44:54 +03:00
|
|
|
useGravatar: !config.isPrivacyDisabled('useGravatar'),
|
|
|
|
publicAPI: config.get('publicAPI') === true,
|
2017-12-11 21:14:05 +03:00
|
|
|
blogUrl: urlService.utils.urlFor('home', true),
|
2017-11-01 16:44:54 +03:00
|
|
|
blogTitle: settingsCache.get('title'),
|
2018-01-18 18:43:22 +03:00
|
|
|
clientExtensions: config.get('clientExtensions'),
|
|
|
|
enableDeveloperExperiments: config.get('enableDeveloperExperiments')
|
2016-01-19 18:43:09 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-08-21 01:42:34 +04:00
|
|
|
/**
|
|
|
|
* ## Configuration API Methods
|
|
|
|
*
|
2016-10-28 16:07:46 +03:00
|
|
|
* We need to load the client credentials dynamically.
|
|
|
|
*
|
2017-12-14 16:13:40 +03:00
|
|
|
* **See:** [API Methods](constants.js.html#api%20methods)
|
2014-08-21 01:42:34 +04:00
|
|
|
*/
|
|
|
|
configuration = {
|
|
|
|
|
|
|
|
/**
|
2016-02-19 21:18:14 +03:00
|
|
|
* Always returns {configuration: []}
|
|
|
|
* Sometimes the array contains configuration items
|
|
|
|
* @param {Object} options
|
|
|
|
* @returns {Promise<Object>}
|
2014-08-21 01:42:34 +04:00
|
|
|
*/
|
|
|
|
read: function read(options) {
|
2016-02-19 21:18:14 +03:00
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
if (!options.key) {
|
2017-09-18 15:01:58 +03:00
|
|
|
return models.Client.findOne({slug: 'ghost-admin'})
|
|
|
|
.then(function (ghostAdmin) {
|
2016-10-28 16:07:46 +03:00
|
|
|
var configuration = getBaseConfig();
|
|
|
|
|
2017-09-18 15:01:58 +03:00
|
|
|
configuration.clientId = ghostAdmin.get('slug');
|
|
|
|
configuration.clientSecret = ghostAdmin.get('secret');
|
2016-10-28 16:07:46 +03:00
|
|
|
|
|
|
|
return {configuration: [configuration]};
|
|
|
|
});
|
2016-02-19 21:18:14 +03:00
|
|
|
}
|
2014-11-28 20:47:32 +03:00
|
|
|
|
2016-02-19 21:18:14 +03:00
|
|
|
if (options.key === 'about') {
|
|
|
|
return Promise.resolve({configuration: [getAboutConfig()]});
|
2014-11-28 20:47:32 +03:00
|
|
|
}
|
2016-02-19 21:18:14 +03:00
|
|
|
|
2016-02-17 16:58:44 +03:00
|
|
|
// Timezone endpoint
|
|
|
|
if (options.key === 'timezones') {
|
|
|
|
return Promise.resolve({configuration: [fetchAvailableTimezones()]});
|
|
|
|
}
|
|
|
|
|
2016-02-19 21:18:14 +03:00
|
|
|
return Promise.resolve({configuration: []});
|
2014-08-21 01:42:34 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = configuration;
|