2014-08-21 01:42:34 +04:00
|
|
|
// # Configuration API
|
|
|
|
// RESTful API for browsing the configuration
|
|
|
|
var _ = require('lodash'),
|
|
|
|
config = require('../config'),
|
|
|
|
Promise = require('bluebird'),
|
|
|
|
|
|
|
|
configuration;
|
|
|
|
|
2016-01-19 18:43:09 +03:00
|
|
|
function labsFlag(key) {
|
|
|
|
return {
|
|
|
|
value: (config[key] === true),
|
|
|
|
type: 'bool'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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-09-13 18:41:14 +03:00
|
|
|
version: config.get('ghostVersion'),
|
2016-02-19 21:18:14 +03:00
|
|
|
environment: process.env.NODE_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-02-19 21:18:14 +03:00
|
|
|
fileStorage: {value: (config.fileStorage !== false), type: 'bool'},
|
|
|
|
useGravatar: {value: !config.isPrivacyDisabled('useGravatar'), type: 'bool'},
|
|
|
|
publicAPI: labsFlag('publicAPI'),
|
2016-09-13 18:41:14 +03:00
|
|
|
blogUrl: {value: config.get('url').replace(/\/$/, ''), type: 'string'},
|
|
|
|
blogTitle: {value: config.get('theme').title, type: 'string'},
|
|
|
|
routeKeywords: {value: JSON.stringify(config.get('routeKeywords')), type: 'json'}
|
2016-01-19 18:43:09 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-08-21 01:42:34 +04:00
|
|
|
/**
|
|
|
|
* ## Configuration API Methods
|
|
|
|
*
|
|
|
|
* **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) {
|
|
|
|
return Promise.resolve({configuration: [getBaseConfig()]});
|
|
|
|
}
|
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;
|