style changes

v1.18.x
Barış Soner Uşaklı 8 years ago
parent bcc566fb68
commit 890c2eff70

@ -1,21 +1,21 @@
'use strict'; 'use strict';
(function (module) {
var fork = require('child_process').fork;
var path = require('path');
module.hash = function (rounds, password, callback) { var fork = require('child_process').fork;
var path = require('path');
exports.hash = function (rounds, password, callback) {
forkChild({ type: 'hash', rounds: rounds, password: password }, callback); forkChild({ type: 'hash', rounds: rounds, password: password }, callback);
}; };
module.compare = function (password, hash, callback) { exports.compare = function (password, hash, callback) {
if (!hash || !password) { if (!hash || !password) {
return setImmediate(callback, null, false); return setImmediate(callback, null, false);
} }
forkChild({ type: 'compare', password: password, hash: hash }, callback); forkChild({ type: 'compare', password: password, hash: hash }, callback);
}; };
function forkChild(message, callback) { function forkChild(message, callback) {
var forkProcessParams = {}; var forkProcessParams = {};
if (global.v8debug || parseInt(process.execArgv.indexOf('--debug'), 10) !== -1) { if (global.v8debug || parseInt(process.execArgv.indexOf('--debug'), 10) !== -1) {
forkProcessParams = { execArgv: ['--debug=' + (5859), '--nolazy'] }; forkProcessParams = { execArgv: ['--debug=' + (5859), '--nolazy'] };
@ -31,7 +31,4 @@
}); });
child.send(message); child.send(message);
} }
return module;
}(exports));

@ -14,36 +14,37 @@ var file = require('./file');
var app; var app;
var middleware; var middleware;
(function (Plugins) { var Plugins = module.exports;
require('./plugins/install')(Plugins);
require('./plugins/load')(Plugins); require('./plugins/install')(Plugins);
require('./plugins/hooks')(Plugins); require('./plugins/load')(Plugins);
Plugins.data = require('./plugins/data'); require('./plugins/hooks')(Plugins);
Plugins.data = require('./plugins/data');
Plugins.getPluginPaths = Plugins.data.getPluginPaths;
Plugins.loadPluginInfo = Plugins.data.loadPluginInfo; Plugins.getPluginPaths = Plugins.data.getPluginPaths;
Plugins.loadPluginInfo = Plugins.data.loadPluginInfo;
Plugins.pluginsData = {};
Plugins.libraries = {}; Plugins.pluginsData = {};
Plugins.loadedHooks = {}; Plugins.libraries = {};
Plugins.staticDirs = {}; Plugins.loadedHooks = {};
Plugins.cssFiles = []; Plugins.staticDirs = {};
Plugins.lessFiles = []; Plugins.cssFiles = [];
Plugins.clientScripts = []; Plugins.lessFiles = [];
Plugins.acpScripts = []; Plugins.clientScripts = [];
Plugins.libraryPaths = []; Plugins.acpScripts = [];
Plugins.versionWarning = []; Plugins.libraryPaths = [];
Plugins.soundpacks = []; Plugins.versionWarning = [];
Plugins.languageData = {}; Plugins.soundpacks = [];
Plugins.languageData = {};
Plugins.initialized = false;
Plugins.initialized = false;
Plugins.requireLibrary = function (pluginID, libraryPath) {
Plugins.requireLibrary = function (pluginID, libraryPath) {
Plugins.libraries[pluginID] = require(libraryPath); Plugins.libraries[pluginID] = require(libraryPath);
Plugins.libraryPaths.push(libraryPath); Plugins.libraryPaths.push(libraryPath);
}; };
Plugins.init = function (nbbApp, nbbMiddleware, callback) { Plugins.init = function (nbbApp, nbbMiddleware, callback) {
callback = callback || function () {}; callback = callback || function () {};
if (Plugins.initialized) { if (Plugins.initialized) {
return callback(); return callback();
@ -72,9 +73,9 @@ var middleware;
Plugins.initialized = true; Plugins.initialized = true;
callback(); callback();
}); });
}; };
Plugins.reload = function (callback) { Plugins.reload = function (callback) {
// Resetting all local plugin data // Resetting all local plugin data
Plugins.libraries = {}; Plugins.libraries = {};
Plugins.loadedHooks = {}; Plugins.loadedHooks = {};
@ -112,9 +113,9 @@ var middleware;
next(); next();
}, },
], callback); ], callback);
}; };
Plugins.reloadRoutes = function (callback) { Plugins.reloadRoutes = function (callback) {
var router = express.Router(); var router = express.Router();
router.hotswapId = 'plugins'; router.hotswapId = 'plugins';
@ -133,9 +134,9 @@ var middleware;
winston.verbose('[plugins] All plugins reloaded and rerouted'); winston.verbose('[plugins] All plugins reloaded and rerouted');
callback(); callback();
}); });
}; };
Plugins.getTemplates = function (callback) { Plugins.getTemplates = function (callback) {
var templates = {}; var templates = {};
var tplName; var tplName;
@ -178,9 +179,9 @@ var middleware;
callback(err, templates); callback(err, templates);
}); });
}); });
}; };
Plugins.get = function (id, callback) { Plugins.get = function (id, callback) {
var url = (nconf.get('registry') || 'https://packages.nodebb.org') + '/api/v1/plugins/' + id; var url = (nconf.get('registry') || 'https://packages.nodebb.org') + '/api/v1/plugins/' + id;
require('request')(url, { require('request')(url, {
@ -197,9 +198,9 @@ var middleware;
return callback(err, !err ? normalised[0] : undefined); return callback(err, !err ? normalised[0] : undefined);
}); });
}); });
}; };
Plugins.list = function (matching, callback) { Plugins.list = function (matching, callback) {
if (arguments.length === 1 && typeof matching === 'function') { if (arguments.length === 1 && typeof matching === 'function') {
callback = matching; callback = matching;
matching = true; matching = true;
@ -217,9 +218,9 @@ var middleware;
Plugins.normalise(body, callback); Plugins.normalise(body, callback);
}); });
}; };
Plugins.normalise = function (apiReturn, callback) { Plugins.normalise = function (apiReturn, callback) {
var pluginMap = {}; var pluginMap = {};
var dependencies = require(path.join(nconf.get('base_dir'), 'package.json')).dependencies; var dependencies = require(path.join(nconf.get('base_dir'), 'package.json')).dependencies;
apiReturn = apiReturn || []; apiReturn = apiReturn || [];
@ -294,9 +295,9 @@ var middleware;
callback(null, pluginArray); callback(null, pluginArray);
}); });
}); });
}; };
Plugins.showInstalled = function (callback) { Plugins.showInstalled = function (callback) {
var npmPluginPath = path.join(__dirname, '../node_modules'); var npmPluginPath = path.join(__dirname, '../node_modules');
async.waterfall([ async.waterfall([
@ -360,5 +361,4 @@ var middleware;
}); });
}, },
], callback); ], callback);
}; };
}(exports));

@ -12,29 +12,30 @@ var categories = require('./categories');
var privileges = require('./privileges'); var privileges = require('./privileges');
var social = require('./social'); var social = require('./social');
(function (Topics) { var Topics = module.exports;
require('./topics/data')(Topics);
require('./topics/create')(Topics); require('./topics/data')(Topics);
require('./topics/delete')(Topics); require('./topics/create')(Topics);
require('./topics/unread')(Topics); require('./topics/delete')(Topics);
require('./topics/recent')(Topics); require('./topics/unread')(Topics);
require('./topics/popular')(Topics); require('./topics/recent')(Topics);
require('./topics/user')(Topics); require('./topics/popular')(Topics);
require('./topics/fork')(Topics); require('./topics/user')(Topics);
require('./topics/posts')(Topics); require('./topics/fork')(Topics);
require('./topics/follow')(Topics); require('./topics/posts')(Topics);
require('./topics/tags')(Topics); require('./topics/follow')(Topics);
require('./topics/teaser')(Topics); require('./topics/tags')(Topics);
require('./topics/suggested')(Topics); require('./topics/teaser')(Topics);
require('./topics/tools')(Topics); require('./topics/suggested')(Topics);
require('./topics/thumb')(Topics); require('./topics/tools')(Topics);
require('./topics/bookmarks')(Topics); require('./topics/thumb')(Topics);
require('./topics/bookmarks')(Topics);
Topics.exists = function (tid, callback) {
Topics.exists = function (tid, callback) {
db.isSortedSetMember('topics:tid', tid, callback); db.isSortedSetMember('topics:tid', tid, callback);
}; };
Topics.getPageCount = function (tid, uid, callback) { Topics.getPageCount = function (tid, uid, callback) {
var postCount; var postCount;
async.waterfall([ async.waterfall([
function (next) { function (next) {
@ -51,14 +52,14 @@ var social = require('./social');
next(null, Math.ceil((parseInt(postCount, 10) - 1) / settings.postsPerPage)); next(null, Math.ceil((parseInt(postCount, 10) - 1) / settings.postsPerPage));
}, },
], callback); ], callback);
}; };
Topics.getTidPage = function (tid, uid, callback) { Topics.getTidPage = function (tid, uid, callback) {
console.warn('[Topics.getTidPage] deprecated!'); console.warn('[Topics.getTidPage] deprecated!');
callback(null, 1); callback(null, 1);
}; };
Topics.getTopicsFromSet = function (set, uid, start, stop, callback) { Topics.getTopicsFromSet = function (set, uid, start, stop, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
db.getSortedSetRevRange(set, start, stop, next); db.getSortedSetRevRange(set, start, stop, next);
@ -70,9 +71,9 @@ var social = require('./social');
next(null, { topics: topics, nextStart: stop + 1 }); next(null, { topics: topics, nextStart: stop + 1 });
}, },
], callback); ], callback);
}; };
Topics.getTopics = function (tids, uid, callback) { Topics.getTopics = function (tids, uid, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
privileges.topics.filterTids('read', tids, uid, next); privileges.topics.filterTids('read', tids, uid, next);
@ -81,9 +82,9 @@ var social = require('./social');
Topics.getTopicsByTids(tids, uid, next); Topics.getTopicsByTids(tids, uid, next);
}, },
], callback); ], callback);
}; };
Topics.getTopicsByTids = function (tids, uid, callback) { Topics.getTopicsByTids = function (tids, uid, callback) {
if (!Array.isArray(tids) || !tids.length) { if (!Array.isArray(tids) || !tids.length) {
return callback(null, []); return callback(null, []);
} }
@ -167,9 +168,9 @@ var social = require('./social');
next(null, data.topics); next(null, data.topics);
}, },
], callback); ], callback);
}; };
Topics.getTopicWithPosts = function (topicData, set, uid, start, stop, reverse, callback) { Topics.getTopicWithPosts = function (topicData, set, uid, start, stop, reverse, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
async.parallel({ async.parallel({
@ -220,9 +221,9 @@ var social = require('./social');
next(null, data.topic); next(null, data.topic);
}, },
], callback); ], callback);
}; };
function getMainPostAndReplies(topic, set, uid, start, stop, reverse, callback) { function getMainPostAndReplies(topic, set, uid, start, stop, reverse, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
if (stop > 0) { if (stop > 0) {
@ -259,68 +260,72 @@ var social = require('./social');
Topics.addPostData(posts, uid, next); Topics.addPostData(posts, uid, next);
}, },
], callback); ], callback);
} }
function getDeleter(topicData, callback) { function getDeleter(topicData, callback) {
if (!topicData.deleterUid) { if (!topicData.deleterUid) {
return setImmediate(callback, null, null); return setImmediate(callback, null, null);
} }
user.getUserFields(topicData.deleterUid, ['username', 'userslug', 'picture'], callback); user.getUserFields(topicData.deleterUid, ['username', 'userslug', 'picture'], callback);
} }
Topics.getMainPost = function (tid, uid, callback) { Topics.getMainPost = function (tid, uid, callback) {
Topics.getMainPosts([tid], uid, function (err, mainPosts) { Topics.getMainPosts([tid], uid, function (err, mainPosts) {
callback(err, Array.isArray(mainPosts) && mainPosts.length ? mainPosts[0] : null); callback(err, Array.isArray(mainPosts) && mainPosts.length ? mainPosts[0] : null);
}); });
}; };
Topics.getMainPids = function (tids, callback) { Topics.getMainPids = function (tids, callback) {
if (!Array.isArray(tids) || !tids.length) { if (!Array.isArray(tids) || !tids.length) {
return callback(null, []); return callback(null, []);
} }
async.waterfall([
Topics.getTopicsFields(tids, ['mainPid'], function (err, topicData) { function (next) {
if (err) { Topics.getTopicsFields(tids, ['mainPid'], next);
return callback(err); },
} function (topicData, next) {
var mainPids = topicData.map(function (topic) { var mainPids = topicData.map(function (topic) {
return topic && topic.mainPid; return topic && topic.mainPid;
}); });
callback(null, mainPids); next(null, mainPids);
}); },
}; ], callback);
};
Topics.getMainPosts = function (tids, uid, callback) { Topics.getMainPosts = function (tids, uid, callback) {
Topics.getMainPids(tids, function (err, mainPids) { async.waterfall([
if (err) { function (next) {
return callback(err); Topics.getMainPids(tids, next);
} },
getMainPosts(mainPids, uid, callback); function (mainPids, next) {
}); getMainPosts(mainPids, uid, next);
}; },
], callback);
};
function getMainPosts(mainPids, uid, callback) { function getMainPosts(mainPids, uid, callback) {
posts.getPostsByPids(mainPids, uid, function (err, postData) { async.waterfall([
if (err) { function (next) {
return callback(err); posts.getPostsByPids(mainPids, uid, next);
} },
function (postData, next) {
postData.forEach(function (post) { postData.forEach(function (post) {
if (post) { if (post) {
post.index = 0; post.index = 0;
} }
}); });
Topics.addPostData(postData, uid, callback); Topics.addPostData(postData, uid, next);
}); },
} ], callback);
}
Topics.isLocked = function (tid, callback) { Topics.isLocked = function (tid, callback) {
Topics.getTopicField(tid, 'locked', function (err, locked) { Topics.getTopicField(tid, 'locked', function (err, locked) {
callback(err, parseInt(locked, 10) === 1); callback(err, parseInt(locked, 10) === 1);
}); });
}; };
Topics.search = function (tid, term, callback) { Topics.search = function (tid, term, callback) {
if (plugins.hasListeners('filter:topic.search')) { if (plugins.hasListeners('filter:topic.search')) {
plugins.fireHook('filter:topic.search', { plugins.fireHook('filter:topic.search', {
tid: tid, tid: tid,
@ -329,5 +334,4 @@ var social = require('./social');
} else { } else {
callback(new Error('[[error:no-plugins-available]]'), []); callback(new Error('[[error:no-plugins-available]]'), []);
} }
}; };
}(exports));

@ -12,20 +12,21 @@ var db = require('../database');
var meta = require('../meta'); var meta = require('../meta');
var emailer = require('../emailer'); var emailer = require('../emailer');
(function (UserEmail) { var UserEmail = module.exports;
UserEmail.exists = function (email, callback) {
UserEmail.exists = function (email, callback) {
user.getUidByEmail(email.toLowerCase(), function (err, exists) { user.getUidByEmail(email.toLowerCase(), function (err, exists) {
callback(err, !!exists); callback(err, !!exists);
}); });
}; };
UserEmail.available = function (email, callback) { UserEmail.available = function (email, callback) {
db.isSortedSetMember('email:uid', email.toLowerCase(), function (err, exists) { db.isSortedSetMember('email:uid', email.toLowerCase(), function (err, exists) {
callback(err, !exists); callback(err, !exists);
}); });
}; };
UserEmail.sendValidationEmail = function (uid, email, callback) { UserEmail.sendValidationEmail = function (uid, email, callback) {
callback = callback || function () {}; callback = callback || function () {};
var confirm_code = utils.generateUUID(); var confirm_code = utils.generateUUID();
var confirm_link = nconf.get('url') + '/confirm/' + confirm_code; var confirm_link = nconf.get('url') + '/confirm/' + confirm_code;
@ -87,9 +88,9 @@ var emailer = require('../emailer');
next(null, confirm_code); next(null, confirm_code);
}, },
], callback); ], callback);
}; };
UserEmail.confirm = function (code, callback) { UserEmail.confirm = function (code, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
db.getObject('confirm:' + code, next); db.getObject('confirm:' + code, next);
@ -113,5 +114,4 @@ var emailer = require('../emailer');
], function (err) { ], function (err) {
callback(err); callback(err);
}); });
}; };
}(exports));

@ -12,10 +12,11 @@ var db = require('../database');
var meta = require('../meta'); var meta = require('../meta');
var emailer = require('../emailer'); var emailer = require('../emailer');
(function (UserReset) { var UserReset = module.exports;
var twoHours = 7200000;
UserReset.validate = function (code, callback) { var twoHours = 7200000;
UserReset.validate = function (code, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
db.getObjectField('reset:uid', code, next); db.getObjectField('reset:uid', code, next);
@ -30,9 +31,9 @@ var emailer = require('../emailer');
next(null, parseInt(issueDate, 10) > Date.now() - twoHours); next(null, parseInt(issueDate, 10) > Date.now() - twoHours);
}, },
], callback); ], callback);
}; };
UserReset.generate = function (uid, callback) { UserReset.generate = function (uid, callback) {
var code = utils.generateUUID(); var code = utils.generateUUID();
async.parallel([ async.parallel([
async.apply(db.setObjectField, 'reset:uid', code, uid), async.apply(db.setObjectField, 'reset:uid', code, uid),
@ -40,9 +41,9 @@ var emailer = require('../emailer');
], function (err) { ], function (err) {
callback(err, code); callback(err, code);
}); });
}; };
function canGenerate(uid, callback) { function canGenerate(uid, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
db.sortedSetScore('reset:issueDate:uid', uid, next); db.sortedSetScore('reset:issueDate:uid', uid, next);
@ -54,9 +55,9 @@ var emailer = require('../emailer');
next(); next();
}, },
], callback); ], callback);
} }
UserReset.send = function (email, callback) { UserReset.send = function (email, callback) {
var uid; var uid;
async.waterfall([ async.waterfall([
function (next) { function (next) {
@ -92,9 +93,9 @@ var emailer = require('../emailer');
}, next); }, next);
}, },
], callback); ], callback);
}; };
UserReset.commit = function (code, password, callback) { UserReset.commit = function (code, password, callback) {
var uid; var uid;
async.waterfall([ async.waterfall([
function (next) { function (next) {
@ -128,18 +129,18 @@ var emailer = require('../emailer');
], next); ], next);
}, },
], callback); ], callback);
}; };
UserReset.updateExpiry = function (uid, callback) { UserReset.updateExpiry = function (uid, callback) {
var oneDay = 1000 * 60 * 60 * 24; var oneDay = 1000 * 60 * 60 * 24;
var expireDays = parseInt(meta.config.passwordExpiryDays || 0, 10); var expireDays = parseInt(meta.config.passwordExpiryDays || 0, 10);
var expiry = Date.now() + (oneDay * expireDays); var expiry = Date.now() + (oneDay * expireDays);
callback = callback || function () {}; callback = callback || function () {};
user.setUserField(uid, 'passwordExpiry', expireDays > 0 ? expiry : 0, callback); user.setUserField(uid, 'passwordExpiry', expireDays > 0 ? expiry : 0, callback);
}; };
UserReset.clean = function (callback) { UserReset.clean = function (callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
async.parallel({ async.parallel({
@ -164,5 +165,4 @@ var emailer = require('../emailer');
], next); ], next);
}, },
], callback); ], callback);
}; };
}(exports));

Loading…
Cancel
Save