2014-08-21 01:42:34 +04:00
|
|
|
// # Configuration API
|
|
|
|
// RESTful API for browsing the configuration
|
|
|
|
var _ = require('lodash'),
|
|
|
|
config = require('../config'),
|
2017-02-03 16:15:11 +03:00
|
|
|
settingsCache = require('../api/settings').cache,
|
2016-10-10 22:14:32 +03:00
|
|
|
ghostVersion = require('../utils/ghost-version'),
|
2016-10-28 16:07:46 +03:00
|
|
|
models = require('../models'),
|
2014-08-21 01:42:34 +04:00
|
|
|
Promise = require('bluebird'),
|
2017-01-23 11:22:37 +03:00
|
|
|
utils = require('../utils'),
|
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 {
|
2016-10-28 16:07:46 +03:00
|
|
|
fileStorage: config.get('fileStorage') !== false,
|
|
|
|
useGravatar: !config.isPrivacyDisabled('useGravatar'),
|
|
|
|
publicAPI: config.get('publicAPI') === true,
|
2017-01-23 11:22:37 +03:00
|
|
|
blogUrl: utils.url.urlFor('home', true),
|
2017-02-03 16:15:11 +03:00
|
|
|
blogTitle: settingsCache.get('title'),
|
2016-10-28 16:07:46 +03:00
|
|
|
routeKeywords: config.get('routeKeywords')
|
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.
|
|
|
|
* For example: on bootstrap ghost-auth get's created and if we load them here in parallel,
|
|
|
|
* it can happen that we won't get any client credentials or wrong credentials.
|
|
|
|
*
|
2014-08-21 01:42:34 +04:00
|
|
|
* **See:** [API Methods](index.js.html#api%20methods)
|
|
|
|
*/
|
|
|
|
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 || {};
|
2016-10-28 16:07:46 +03:00
|
|
|
var ops = {};
|
2016-02-19 21:18:14 +03:00
|
|
|
|
|
|
|
if (!options.key) {
|
2016-10-28 16:07:46 +03:00
|
|
|
ops.ghostAdmin = models.Client.findOne({slug: 'ghost-admin'});
|
|
|
|
|
|
|
|
if (config.get('auth:type') === 'ghost') {
|
|
|
|
ops.ghostAuth = models.Client.findOne({slug: 'ghost-auth'});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.props(ops)
|
|
|
|
.then(function (result) {
|
|
|
|
var configuration = getBaseConfig();
|
|
|
|
|
|
|
|
configuration.clientId = result.ghostAdmin.get('slug');
|
|
|
|
configuration.clientSecret = result.ghostAdmin.get('secret');
|
|
|
|
|
2016-11-08 17:21:25 +03:00
|
|
|
if (config.get('auth:type') === 'ghost') {
|
|
|
|
configuration.ghostAuthId = result.ghostAuth && result.ghostAuth.get('uuid') || 'not-available';
|
2016-10-28 16:07:46 +03:00
|
|
|
configuration.ghostAuthUrl = config.get('auth:url');
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|