2016-09-13 18:20:44 +03:00
|
|
|
var path = require('path'),
|
2016-10-18 11:04:44 +03:00
|
|
|
_ = require('lodash'),
|
|
|
|
errors = require('../errors');
|
2016-09-13 18:20:44 +03:00
|
|
|
|
|
|
|
exports.isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) {
|
|
|
|
if (!this.get('privacy')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.get('privacy').useTinfoil === true) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.get('privacy')[privacyFlag] === false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* transform all relative paths to absolute paths
|
|
|
|
* @TODO: imagesRelPath is a dirty little attribute (especially when looking at the usages)
|
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
|
|
|
if (!obj) {
|
|
|
|
throw new errors.IncorrectUsageError({
|
2017-02-02 15:46:30 +03:00
|
|
|
message: 'makePathsAbsolute: Can\'t make paths absolute of non existing object.',
|
|
|
|
help: parent
|
2016-10-18 11:04:44 +03:00
|
|
|
});
|
2016-09-13 18:20:44 +03:00
|
|
|
}
|
|
|
|
|
2016-10-18 11:04:44 +03:00
|
|
|
if (!parent) {
|
|
|
|
throw new errors.IncorrectUsageError({
|
|
|
|
message: 'makePathsAbsolute: Parent is missing.'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_.each(obj, function (configValue, pathsKey) {
|
2016-09-13 18:20:44 +03:00
|
|
|
if (_.isObject(configValue)) {
|
|
|
|
makePathsAbsolute.bind(self)(configValue, parent + ':' + pathsKey);
|
|
|
|
} else {
|
2016-10-18 11:04:44 +03:00
|
|
|
if (_.isString(configValue) &&
|
|
|
|
(configValue.match(/\/+|\\+/) || configValue === '.') &&
|
|
|
|
(configValue[0] !== '/' && configValue[0] !== '\\') &&
|
|
|
|
pathsKey !== 'imagesRelPath'
|
|
|
|
) {
|
2016-09-13 18:20:44 +03:00
|
|
|
self.set(parent + ':' + pathsKey, path.join(__dirname + '/../../../', configValue));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
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) {
|
|
|
|
case 'storage':
|
|
|
|
return path.join(this.get('paths:contentPath'), 'storage/');
|
|
|
|
case 'images':
|
|
|
|
return path.join(this.get('paths:contentPath'), 'images/');
|
|
|
|
case 'apps':
|
|
|
|
return path.join(this.get('paths:contentPath'), 'apps/');
|
|
|
|
case 'themes':
|
|
|
|
return path.join(this.get('paths:contentPath'), 'themes/');
|
|
|
|
case 'scheduling':
|
|
|
|
return path.join(this.get('paths:contentPath'), 'scheduling/');
|
2016-10-25 14:17:43 +03:00
|
|
|
case 'logs':
|
|
|
|
return path.join(this.get('paths:contentPath'), 'logs/');
|
2016-09-13 23:24:57 +03:00
|
|
|
default:
|
|
|
|
throw new Error('getContentPath was called with: ' + type);
|
|
|
|
}
|
|
|
|
};
|