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