2014-08-20 21:42:34 +00:00
|
|
|
// # Configuration API
|
|
|
|
// RESTful API for browsing the configuration
|
2017-09-12 16:31:14 +01:00
|
|
|
var Promise = require('bluebird'),
|
|
|
|
_ = require('lodash'),
|
2017-12-11 19:14:05 +01:00
|
|
|
urlService = require('../services/url'),
|
2017-09-12 16:31:14 +01:00
|
|
|
models = require('../models'),
|
|
|
|
config = require('../config'),
|
2018-05-31 15:14:59 +02:00
|
|
|
labs = require('../services/labs'),
|
2017-12-14 03:01:23 +01:00
|
|
|
settingsCache = require('../services/settings/cache'),
|
2017-12-14 22:14:55 +01:00
|
|
|
ghostVersion = require('../lib/ghost-version'),
|
2014-08-20 21:42:34 +00:00
|
|
|
configuration;
|
|
|
|
|
2016-02-17 15:58:44 +02:00
|
|
|
function fetchAvailableTimezones() {
|
|
|
|
var timezones = require('../data/timezones.json');
|
|
|
|
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,
|
|
|
|
mail: _.isObject(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
|
|
|
*/
|
|
|
|
read: function 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'})
|
|
|
|
.then(function (ghostAdmin) {
|
2016-10-28 15:07:46 +02:00
|
|
|
var configuration = getBaseConfig();
|
|
|
|
|
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;
|