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-19 21:18:14 +03:00
|
|
|
function getAboutConfig() {
|
|
|
|
return {
|
|
|
|
version: config.ghostVersion,
|
|
|
|
environment: process.env.NODE_ENV,
|
|
|
|
database: config.database.client,
|
|
|
|
mail: _.isObject(config.mail) ? config.mail.transport : ''
|
|
|
|
};
|
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'},
|
|
|
|
useGoogleFonts: {value: !config.isPrivacyDisabled('useGoogleFonts'), type: 'bool'},
|
|
|
|
useGravatar: {value: !config.isPrivacyDisabled('useGravatar'), type: 'bool'},
|
|
|
|
publicAPI: labsFlag('publicAPI'),
|
|
|
|
blogUrl: {value: config.url.replace(/\/$/, ''), type: 'string'},
|
|
|
|
blogTitle: {value: config.theme.title, type: 'string'},
|
|
|
|
routeKeywords: {value: JSON.stringify(config.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
|
|
|
|
|
|
|
return Promise.resolve({configuration: []});
|
2014-08-21 01:42:34 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = configuration;
|