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'),
|
|
|
|
apiUtils = require('../utils'),
|
|
|
|
models = require('../models'),
|
|
|
|
config = require('../config'),
|
|
|
|
settingsCache = require('../settings/cache'),
|
|
|
|
ghostVersion = require('../utils/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 {
|
2016-10-28 16:07:46 +03:00
|
|
|
useGravatar: !config.isPrivacyDisabled('useGravatar'),
|
|
|
|
publicAPI: config.get('publicAPI') === true,
|
2017-09-12 18:31:14 +03:00
|
|
|
blogUrl: apiUtils.url.urlFor('home', true),
|
2017-02-03 16:15:11 +03:00
|
|
|
blogTitle: settingsCache.get('title'),
|
2017-06-22 21:45:35 +03:00
|
|
|
routeKeywords: config.get('routeKeywords'),
|
|
|
|
clientExtensions: config.get('clientExtensions')
|
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.
|
|
|
|
*
|
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 || {};
|
|
|
|
|
|
|
|
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;
|