2016-09-13 18:20:44 +03:00
|
|
|
var path = require('path'),
|
2017-06-07 12:31:01 +03:00
|
|
|
fs = require('fs-extra'),
|
2017-03-02 19:02:23 +03:00
|
|
|
_ = require('lodash');
|
2016-09-13 18:20:44 +03:00
|
|
|
|
|
|
|
exports.isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) {
|
|
|
|
if (!this.get('privacy')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-03 21:25:39 +03:00
|
|
|
// CASE: disable all privacy features
|
2016-09-13 18:20:44 +03:00
|
|
|
if (this.get('privacy').useTinfoil === true) {
|
2017-02-03 21:25:39 +03:00
|
|
|
// CASE: you can still enable single features
|
|
|
|
if (this.get('privacy')[privacyFlag] === true) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-13 18:20:44 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.get('privacy')[privacyFlag] === false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* transform all relative paths to absolute paths
|
2016-10-18 11:04:44 +03:00
|
|
|
* @TODO: re-write this function a little bit so we don't have to add the parent path - that is hard to understand
|
|
|
|
*
|
|
|
|
* Path must be string.
|
|
|
|
* Path must match minimum one / or \
|
|
|
|
* Path can be a "." to re-present current folder
|
2016-09-13 18:20:44 +03:00
|
|
|
*/
|
2016-10-18 11:04:44 +03:00
|
|
|
exports.makePathsAbsolute = function makePathsAbsolute(obj, parent) {
|
2016-09-13 18:20:44 +03:00
|
|
|
var self = this;
|
|
|
|
|
2016-10-18 11:04:44 +03:00
|
|
|
_.each(obj, function (configValue, pathsKey) {
|
2016-09-13 18:20:44 +03:00
|
|
|
if (_.isObject(configValue)) {
|
|
|
|
makePathsAbsolute.bind(self)(configValue, parent + ':' + pathsKey);
|
2017-07-06 01:04:18 +03:00
|
|
|
} else if (
|
|
|
|
_.isString(configValue) &&
|
|
|
|
(configValue.match(/\/+|\\+/) || configValue === '.') &&
|
|
|
|
!path.isAbsolute(configValue)
|
|
|
|
) {
|
|
|
|
self.set(parent + ':' + pathsKey, path.normalize(path.join(__dirname, '../../..', configValue)));
|
2016-09-13 18:20:44 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2016-09-13 23:24:57 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* we can later support setting folder names via custom config values
|
|
|
|
*/
|
|
|
|
exports.getContentPath = function getContentPath(type) {
|
|
|
|
switch (type) {
|
2018-09-17 21:49:30 +03:00
|
|
|
case 'images':
|
|
|
|
return path.join(this.get('paths:contentPath'), 'images/');
|
|
|
|
case 'themes':
|
|
|
|
return path.join(this.get('paths:contentPath'), 'themes/');
|
|
|
|
case 'storage':
|
|
|
|
return path.join(this.get('paths:contentPath'), 'adapters', 'storage/');
|
|
|
|
case 'scheduling':
|
|
|
|
return path.join(this.get('paths:contentPath'), 'adapters', 'scheduling/');
|
|
|
|
case 'logs':
|
|
|
|
return path.join(this.get('paths:contentPath'), 'logs/');
|
|
|
|
case 'data':
|
|
|
|
return path.join(this.get('paths:contentPath'), 'data/');
|
|
|
|
case 'settings':
|
|
|
|
return path.join(this.get('paths:contentPath'), 'settings/');
|
|
|
|
default:
|
|
|
|
throw new Error('getContentPath was called with: ' + type);
|
2016-09-13 23:24:57 +03:00
|
|
|
}
|
|
|
|
};
|
2017-02-11 21:02:12 +03:00
|
|
|
|
2017-06-07 12:31:01 +03:00
|
|
|
/**
|
|
|
|
* @TODO:
|
|
|
|
* - content/logs folder is required right now, otherwise Ghost want start
|
|
|
|
*/
|
|
|
|
exports.doesContentPathExist = function doesContentPathExist() {
|
|
|
|
if (!fs.pathExistsSync(this.get('paths:contentPath'))) {
|
|
|
|
throw new Error('Your content path does not exist! Please double check `paths.contentPath` in your custom config file e.g. config.production.json.');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-21 19:00:11 +03:00
|
|
|
/**
|
|
|
|
* Check if the URL in config has a protocol and sanitise it if not including a warning that it should be changed
|
|
|
|
*/
|
|
|
|
exports.checkUrlProtocol = function checkUrlProtocol() {
|
|
|
|
var url = this.get('url');
|
|
|
|
|
|
|
|
if (!url.match(/^https?:\/\//i)) {
|
|
|
|
throw new Error('URL in config must be provided with protocol, eg. "http://my-ghost-blog.com"');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-11 21:02:12 +03:00
|
|
|
/**
|
|
|
|
* nconf merges all database keys together and this can be confusing
|
|
|
|
* e.g. production default database is sqlite, but you override the configuration with mysql
|
|
|
|
*
|
|
|
|
* this.clear('key') does not work
|
|
|
|
* https://github.com/indexzero/nconf/issues/235#issuecomment-257606507
|
|
|
|
*/
|
|
|
|
exports.sanitizeDatabaseProperties = function sanitizeDatabaseProperties() {
|
|
|
|
var database = this.get('database');
|
|
|
|
|
|
|
|
if (this.get('database:client') === 'mysql') {
|
|
|
|
delete database.connection.filename;
|
|
|
|
} else {
|
|
|
|
delete database.connection.host;
|
|
|
|
delete database.connection.user;
|
|
|
|
delete database.connection.password;
|
|
|
|
delete database.connection.database;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.set('database', database);
|
|
|
|
};
|