v1.18.x
Barış Soner Uşaklı 8 years ago
parent f57b5f4e4c
commit 2faf175739

@ -8,45 +8,48 @@ var batch = require('../batch');
module.exports = function (Groups) { module.exports = function (Groups) {
Groups.destroy = function (groupName, callback) { Groups.destroy = function (groupName, callback) {
Groups.getGroupsData([groupName], function (err, groupsData) { var groupObj;
if (err) { async.waterfall([
return callback(err); function (next) {
} Groups.getGroupsData([groupName], next);
if (!Array.isArray(groupsData) || !groupsData[0]) { },
return callback(); function (groupsData, next) {
} if (!Array.isArray(groupsData) || !groupsData[0]) {
var groupObj = groupsData[0]; return callback();
async.parallel([
async.apply(db.delete, 'group:' + groupName),
async.apply(db.sortedSetRemove, 'groups:createtime', groupName),
async.apply(db.sortedSetRemove, 'groups:visible:createtime', groupName),
async.apply(db.sortedSetRemove, 'groups:visible:memberCount', groupName),
async.apply(db.sortedSetRemove, 'groups:visible:name', groupName.toLowerCase() + ':' + groupName),
async.apply(db.delete, 'group:' + groupName + ':members'),
async.apply(db.delete, 'group:' + groupName + ':pending'),
async.apply(db.delete, 'group:' + groupName + ':invited'),
async.apply(db.delete, 'group:' + groupName + ':owners'),
async.apply(db.delete, 'group:' + groupName + ':member:pids'),
async.apply(db.deleteObjectField, 'groupslug:groupname', utils.slugify(groupName)),
function (next) {
batch.processSortedSet('groups:createtime', function (groupNames, next) {
var keys = groupNames.map(function (group) {
return 'group:' + group + ':members';
});
db.sortedSetsRemove(keys, groupName, next);
}, {
batch: 500,
}, next);
},
], function (err) {
if (err) {
return callback(err);
} }
groupObj = groupsData[0];
async.parallel([
async.apply(db.delete, 'group:' + groupName),
async.apply(db.sortedSetRemove, 'groups:createtime', groupName),
async.apply(db.sortedSetRemove, 'groups:visible:createtime', groupName),
async.apply(db.sortedSetRemove, 'groups:visible:memberCount', groupName),
async.apply(db.sortedSetRemove, 'groups:visible:name', groupName.toLowerCase() + ':' + groupName),
async.apply(db.delete, 'group:' + groupName + ':members'),
async.apply(db.delete, 'group:' + groupName + ':pending'),
async.apply(db.delete, 'group:' + groupName + ':invited'),
async.apply(db.delete, 'group:' + groupName + ':owners'),
async.apply(db.delete, 'group:' + groupName + ':member:pids'),
async.apply(db.deleteObjectField, 'groupslug:groupname', utils.slugify(groupName)),
function (next) {
batch.processSortedSet('groups:createtime', function (groupNames, next) {
var keys = groupNames.map(function (group) {
return 'group:' + group + ':members';
});
db.sortedSetsRemove(keys, groupName, next);
}, {
batch: 500,
}, next);
},
], function (err) {
next(err);
});
},
function (next) {
Groups.resetCache(); Groups.resetCache();
plugins.fireHook('action:group.destroy', { group: groupObj }); plugins.fireHook('action:group.destroy', { group: groupObj });
callback(); next();
}); },
}); ], callback);
}; };
}; };

@ -287,13 +287,14 @@ module.exports = function (Groups) {
Groups.getMemberUsers = function (groupNames, start, stop, callback) { Groups.getMemberUsers = function (groupNames, start, stop, callback) {
async.map(groupNames, function (groupName, next) { async.map(groupNames, function (groupName, next) {
Groups.getMembers(groupName, start, stop, function (err, uids) { async.waterfall([
if (err) { function (next) {
return next(err); Groups.getMembers(groupName, start, stop, next);
} },
function (uids, next) {
user.getUsersFields(uids, ['uid', 'username', 'picture', 'userslug'], next); user.getUsersFields(uids, ['uid', 'username', 'picture', 'userslug'], next);
}); },
], next);
}, callback); }, callback);
}; };

@ -13,27 +13,24 @@ var Blacklist = {
Blacklist.load = function (callback) { Blacklist.load = function (callback) {
callback = callback || function () {}; callback = callback || function () {};
async.waterfall([ async.waterfall([
Blacklist.get, Blacklist.get,
Blacklist.validate, Blacklist.validate,
], function (err, rules) { function (rules, next) {
if (err) { winston.verbose('[meta/blacklist] Loading ' + rules.valid.length + ' blacklist rules');
return callback(err); if (rules.invalid.length) {
} winston.warn('[meta/blacklist] ' + rules.invalid.length + ' invalid blacklist rule(s) were ignored.');
}
winston.verbose('[meta/blacklist] Loading ' + rules.valid.length + ' blacklist rules');
if (rules.invalid.length) { Blacklist._rules = {
winston.warn('[meta/blacklist] ' + rules.invalid.length + ' invalid blacklist rule(s) were ignored.'); ipv4: rules.ipv4,
} ipv6: rules.ipv6,
cidr: rules.cidr,
Blacklist._rules = { };
ipv4: rules.ipv4, next();
ipv6: rules.ipv6, },
cidr: rules.cidr, ], callback);
};
callback();
});
}; };
pubsub.on('blacklist:reload', Blacklist.load); pubsub.on('blacklist:reload', Blacklist.load);

@ -1,5 +1,6 @@
'use strict'; 'use strict';
var async = require('async');
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var mkdirp = require('mkdirp'); var mkdirp = require('mkdirp');
@ -15,13 +16,14 @@ function generate() {
} }
exports.write = function write(callback) { exports.write = function write(callback) {
mkdirp(path.dirname(filePath), function (err) { async.waterfall([
if (err) { function (next) {
return callback(err); mkdirp(path.dirname(filePath), next);
} },
function (data, next) {
fs.writeFile(filePath, generate(), callback); fs.writeFile(filePath, generate(), next);
}); },
], callback);
}; };
exports.read = function read(callback) { exports.read = function read(callback) {

@ -2,7 +2,6 @@
var path = require('path'); var path = require('path');
var fs = require('fs'); var fs = require('fs');
var winston = require('winston');
module.exports = function (Meta) { module.exports = function (Meta) {
Meta.logs = { Meta.logs = {
@ -12,13 +11,7 @@ module.exports = function (Meta) {
Meta.logs.get = function (callback) { Meta.logs.get = function (callback) {
fs.readFile(Meta.logs.path, { fs.readFile(Meta.logs.path, {
encoding: 'utf-8', encoding: 'utf-8',
}, function (err, logs) { }, callback);
if (err) {
winston.error('[meta/logs] Could not retrieve logs: ' + err.message);
}
callback(undefined, logs || '');
});
}; };
Meta.logs.clear = function (callback) { Meta.logs.clear = function (callback) {

@ -11,14 +11,75 @@ var nconf = require('nconf');
var plugins = require('../plugins'); var plugins = require('../plugins');
var file = require('../file'); var file = require('../file');
var Templates = {}; var Templates = module.exports;
Templates.compile = function (callback) { Templates.compile = function (callback) {
callback = callback || function () {}; callback = callback || function () {};
compile(callback); var themeConfig = require(nconf.get('theme_config'));
}; var baseTemplatesPaths = themeConfig.baseTheme ? getBaseTemplates(themeConfig.baseTheme) : [nconf.get('base_templates_path')];
var viewsPath = nconf.get('views_dir');
function processImports(paths, relativePath, source, callback) {
var regex = /<!-- IMPORT (.+?) -->/;
var matches = source.match(regex);
if (!matches) {
return callback(null, source);
}
var partial = '/' + matches[1];
if (paths[partial] && relativePath !== partial) {
fs.readFile(paths[partial], function (err, file) {
if (err) {
return callback(err);
}
var partialSource = file.toString();
source = source.replace(regex, partialSource);
processImports(paths, relativePath, source, callback);
});
} else {
winston.warn('[meta/templates] Partial not loaded: ' + matches[1]);
source = source.replace(regex, '');
processImports(paths, relativePath, source, callback);
}
}
async.waterfall([
function (next) {
preparePaths(baseTemplatesPaths, next);
},
function (paths, next) {
async.each(Object.keys(paths), function (relativePath, next) {
async.waterfall([
function (next) {
fs.readFile(paths[relativePath], next);
},
function (file, next) {
var source = file.toString();
processImports(paths, relativePath, source, next);
},
function (compiled, next) {
mkdirp(path.join(viewsPath, path.dirname(relativePath)), function (err) {
next(err, compiled);
});
},
function (compiled, next) {
fs.writeFile(path.join(viewsPath, relativePath), compiled, next);
},
], next);
}, next);
},
function (next) {
winston.verbose('[meta/templates] Successfully compiled templates.');
next();
},
], callback);
};
function getBaseTemplates(theme) { function getBaseTemplates(theme) {
var baseTemplatesPaths = []; var baseTemplatesPaths = [];
@ -39,7 +100,7 @@ function getBaseTemplates(theme) {
function preparePaths(baseTemplatesPaths, callback) { function preparePaths(baseTemplatesPaths, callback) {
var coreTemplatesPath = nconf.get('core_templates_path'); var coreTemplatesPath = nconf.get('core_templates_path');
var viewsPath = nconf.get('views_dir'); var viewsPath = nconf.get('views_dir');
var pluginTemplates;
async.waterfall([ async.waterfall([
function (next) { function (next) {
rimraf(viewsPath, next); rimraf(viewsPath, next);
@ -53,32 +114,31 @@ function preparePaths(baseTemplatesPaths, callback) {
function (next) { function (next) {
plugins.getTemplates(next); plugins.getTemplates(next);
}, },
], function (err, pluginTemplates) { function (_pluginTemplates, next) {
if (err) { pluginTemplates = _pluginTemplates;
return callback(err); winston.verbose('[meta/templates] Compiling templates');
}
winston.verbose('[meta/templates] Compiling templates'); async.parallel({
coreTpls: function (next) {
async.parallel({ file.walk(coreTemplatesPath, next);
coreTpls: function (next) { },
file.walk(coreTemplatesPath, next); baseThemes: function (next) {
}, async.map(baseTemplatesPaths, function (baseTemplatePath, next) {
baseThemes: function (next) { file.walk(baseTemplatePath, function (err, paths) {
async.map(baseTemplatesPaths, function (baseTemplatePath, next) { paths = paths.map(function (tpl) {
file.walk(baseTemplatePath, function (err, paths) { return {
paths = paths.map(function (tpl) { base: baseTemplatePath,
return { path: tpl.replace(baseTemplatePath, ''),
base: baseTemplatePath, };
path: tpl.replace(baseTemplatePath, ''), });
};
next(err, paths);
}); });
}, next);
next(err, paths); },
}); }, next);
}, next); },
}, function (data, next) {
}, function (err, data) {
var baseThemes = data.baseThemes; var baseThemes = data.baseThemes;
var coreTpls = data.coreTpls; var coreTpls = data.coreTpls;
var paths = {}; var paths = {};
@ -99,79 +159,7 @@ function preparePaths(baseTemplatesPaths, callback) {
} }
} }
callback(err, paths); next(null, paths);
}); },
}); ], callback);
}
function compile(callback) {
var themeConfig = require(nconf.get('theme_config'));
var baseTemplatesPaths = themeConfig.baseTheme ? getBaseTemplates(themeConfig.baseTheme) : [nconf.get('base_templates_path')];
var viewsPath = nconf.get('views_dir');
function processImports(paths, relativePath, source, callback) {
var regex = /<!-- IMPORT (.+?) -->/;
var matches = source.match(regex);
if (!matches) {
return callback(null, source);
}
var partial = '/' + matches[1];
if (paths[partial] && relativePath !== partial) {
fs.readFile(paths[partial], function (err, file) {
if (err) {
return callback(err);
}
var partialSource = file.toString();
source = source.replace(regex, partialSource);
processImports(paths, relativePath, source, callback);
});
} else {
winston.warn('[meta/templates] Partial not loaded: ' + matches[1]);
source = source.replace(regex, '');
processImports(paths, relativePath, source, callback);
}
}
preparePaths(baseTemplatesPaths, function (err, paths) {
if (err) {
return callback(err);
}
async.each(Object.keys(paths), function (relativePath, next) {
async.waterfall([
function (next) {
fs.readFile(paths[relativePath], next);
},
function (file, next) {
var source = file.toString();
processImports(paths, relativePath, source, next);
},
function (compiled, next) {
mkdirp(path.join(viewsPath, path.dirname(relativePath)), function (err) {
next(err, compiled);
});
},
function (compiled, next) {
fs.writeFile(path.join(viewsPath, relativePath), compiled, next);
},
], next);
}, function (err) {
if (err) {
winston.error('[meta/templates] ' + err.stack);
return callback(err);
}
winston.verbose('[meta/templates] Successfully compiled templates.');
callback();
});
});
} }
module.exports = Templates;

@ -19,27 +19,25 @@ module.exports = function (Meta) {
return callback(null, []); return callback(null, []);
} }
fs.readdir(themePath, function (err, files) { async.waterfall([
if (err) { function (next) {
return callback(err); fs.readdir(themePath, next);
} },
function (files, next) {
async.filter(files, function (file, next) { async.filter(files, function (file, next) {
fs.stat(path.join(themePath, file), function (err, fileStat) { fs.stat(path.join(themePath, file), function (err, fileStat) {
if (err) { if (err) {
if (err.code === 'ENOENT') { if (err.code === 'ENOENT') {
return next(null, false); return next(null, false);
}
return next(err);
} }
return next(err);
}
next(null, (fileStat.isDirectory() && file.slice(0, 13) === 'nodebb-theme-'));
});
}, function (err, themes) {
if (err) {
return callback(err);
}
next(null, (fileStat.isDirectory() && file.slice(0, 13) === 'nodebb-theme-'));
});
}, next);
},
function (themes, next) {
async.map(themes, function (theme, next) { async.map(themes, function (theme, next) {
var config = path.join(themePath, theme, 'theme.json'); var config = path.join(themePath, theme, 'theme.json');
@ -66,16 +64,13 @@ module.exports = function (Meta) {
next(null, null); next(null, null);
} }
}); });
}, function (err, themes) { }, next);
if (err) { },
return callback(err); function (themes, next) {
} themes = themes.filter(Boolean);
next(null, themes);
themes = themes.filter(Boolean); },
callback(null, themes); ], callback);
});
});
});
}; };
Meta.themes.set = function (data, callback) { Meta.themes.set = function (data, callback) {
@ -134,33 +129,34 @@ module.exports = function (Meta) {
}; };
Meta.themes.setupPaths = function (callback) { Meta.themes.setupPaths = function (callback) {
async.parallel({ async.waterfall([
themesData: Meta.themes.get, function (next) {
currentThemeId: function (next) { async.parallel({
db.getObjectField('config', 'theme:id', next); themesData: Meta.themes.get,
currentThemeId: function (next) {
db.getObjectField('config', 'theme:id', next);
},
}, next);
}, },
}, function (err, data) { function (data, next) {
if (err) { var themeId = data.currentThemeId || 'nodebb-theme-persona';
return callback(err);
}
var themeId = data.currentThemeId || 'nodebb-theme-persona';
var themeObj = data.themesData.filter(function (themeObj) { var themeObj = data.themesData.filter(function (themeObj) {
return themeObj.id === themeId; return themeObj.id === themeId;
})[0]; })[0];
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
winston.info('[themes] Using theme ' + themeId); winston.info('[themes] Using theme ' + themeId);
} }
if (!themeObj) { if (!themeObj) {
return callback(new Error('[[error:theme-not-found]]')); return callback(new Error('[[error:theme-not-found]]'));
} }
Meta.themes.setPath(themeObj); Meta.themes.setPath(themeObj);
callback(); next();
}); },
], callback);
}; };
Meta.themes.setPath = function (themeObj) { Meta.themes.setPath = function (themeObj) {

Loading…
Cancel
Save