mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-08-26 23:35:16 +02:00
Merge branch 'master' into develop
This commit is contained in:
@@ -19,7 +19,7 @@ function filterDirectories(directories) {
|
||||
// exclude category.tpl, group.tpl, category-analytics.tpl
|
||||
return !dir.includes('/partials/') &&
|
||||
/\/.*\//.test(dir) &&
|
||||
!/manage\/(category|group|category\-analytics)$/.test(dir);
|
||||
!/manage\/(category|group|category-analytics)$/.test(dir);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ function sanitize(html) {
|
||||
function simplify(translations) {
|
||||
return translations
|
||||
// remove all mustaches
|
||||
.replace(/(?:\{{1,2}[^\}]*?\}{1,2})/g, '')
|
||||
.replace(/(?:\{{1,2}[^}]*?\}{1,2})/g, '')
|
||||
// collapse whitespace
|
||||
.replace(/(?:[ \t]*[\n\r]+[ \t]*)+/g, '\n')
|
||||
.replace(/[\t ]+/g, ' ');
|
||||
@@ -137,7 +137,7 @@ function initDict(language, callback) {
|
||||
title = '[[admin/menu:general/dashboard]]';
|
||||
} else {
|
||||
title = title.match(/admin\/(.+?)\/(.+?)$/);
|
||||
title = '[[admin/menu:section-' +
|
||||
title = '[[admin/menu:section-' +
|
||||
(title[1] === 'development' ? 'advanced' : title[1]) +
|
||||
']]' + (title[2] ? (' > [[admin/menu:' +
|
||||
title[1] + '/' + title[2] + ']]') : '');
|
||||
|
||||
@@ -25,7 +25,7 @@ Analytics.increment = function (keys, callback) {
|
||||
|
||||
keys.forEach(function (key) {
|
||||
counters[key] = counters[key] || 0;
|
||||
++counters[key];
|
||||
counters[key] += 1;
|
||||
});
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
@@ -34,7 +34,7 @@ Analytics.increment = function (keys, callback) {
|
||||
};
|
||||
|
||||
Analytics.pageView = function (payload) {
|
||||
++pageViews;
|
||||
pageViews += 1;
|
||||
|
||||
if (payload.ip) {
|
||||
db.sortedSetScore('ip:recent', payload.ip, function (err, score) {
|
||||
@@ -42,20 +42,20 @@ Analytics.pageView = function (payload) {
|
||||
return;
|
||||
}
|
||||
if (!score) {
|
||||
++uniqueIPCount;
|
||||
uniqueIPCount += 1;
|
||||
}
|
||||
var today = new Date();
|
||||
today.setHours(today.getHours(), 0, 0, 0);
|
||||
if (!score || score < today.getTime()) {
|
||||
++uniquevisitors;
|
||||
uniquevisitors += 1;
|
||||
db.sortedSetAdd('ip:recent', Date.now(), payload.ip);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (payload.path) {
|
||||
var categoryMatch = payload.path.match(isCategory),
|
||||
cid = categoryMatch ? parseInt(categoryMatch[1], 10) : null;
|
||||
var categoryMatch = payload.path.match(isCategory);
|
||||
var cid = categoryMatch ? parseInt(categoryMatch[1], 10) : null;
|
||||
|
||||
if (cid) {
|
||||
Analytics.increment(['pageviews:byCid:' + cid]);
|
||||
@@ -90,7 +90,7 @@ Analytics.writeData = function (callback) {
|
||||
}
|
||||
|
||||
if (Object.keys(counters).length > 0) {
|
||||
for(var key in counters) {
|
||||
for (var key in counters) {
|
||||
if (counters.hasOwnProperty(key)) {
|
||||
dbQueue.push(async.apply(db.sortedSetIncrBy, 'analytics:' + key, counters[key], today.getTime()));
|
||||
delete counters[key];
|
||||
@@ -107,13 +107,13 @@ Analytics.writeData = function (callback) {
|
||||
};
|
||||
|
||||
Analytics.getHourlyStatsForSet = function (set, hour, numHours, callback) {
|
||||
var terms = {},
|
||||
hoursArr = [];
|
||||
var terms = {};
|
||||
var hoursArr = [];
|
||||
|
||||
hour = new Date(hour);
|
||||
hour.setHours(hour.getHours(), 0, 0, 0);
|
||||
|
||||
for (var i = 0, ii = numHours; i < ii; i++) {
|
||||
for (var i = 0, ii = numHours; i < ii; i += 1) {
|
||||
hoursArr.push(hour.getTime());
|
||||
hour.setHours(hour.getHours() - 1, 0, 0, 0);
|
||||
}
|
||||
@@ -146,7 +146,8 @@ Analytics.getDailyStatsForSet = function (set, day, numDays, callback) {
|
||||
day.setHours(0, 0, 0, 0);
|
||||
|
||||
async.whilst(function () {
|
||||
return numDays--;
|
||||
numDays -= 1;
|
||||
return numDays + 1;
|
||||
}, function (next) {
|
||||
Analytics.getHourlyStatsForSet(set, day.getTime() - (1000 * 60 * 60 * 24 * numDays), 24, function (err, day) {
|
||||
if (err) {
|
||||
@@ -181,7 +182,7 @@ Analytics.getMonthlyPageViews = function (callback) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
callback(null, {thisMonth: scores[0] || 0, lastMonth: scores[1] || 0});
|
||||
callback(null, { thisMonth: scores[0] || 0, lastMonth: scores[1] || 0 });
|
||||
});
|
||||
};
|
||||
|
||||
@@ -197,7 +198,7 @@ Analytics.getCategoryAnalytics = function (cid, callback) {
|
||||
Analytics.getErrorAnalytics = function (callback) {
|
||||
async.parallel({
|
||||
'not-found': async.apply(Analytics.getDailyStatsForSet, 'analytics:errors:404', Date.now(), 7),
|
||||
'toobusy': async.apply(Analytics.getDailyStatsForSet, 'analytics:errors:503', Date.now(), 7)
|
||||
toobusy: async.apply(Analytics.getDailyStatsForSet, 'analytics:errors:503', Date.now(), 7),
|
||||
}, callback);
|
||||
};
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ exports.processArray = function (array, process, options, callback) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
start = start + batch;
|
||||
start += batch;
|
||||
if (options.interval) {
|
||||
setTimeout(next, options.interval);
|
||||
} else {
|
||||
|
||||
@@ -10,7 +10,6 @@ var plugins = require('./plugins');
|
||||
var privileges = require('./privileges');
|
||||
|
||||
(function (Categories) {
|
||||
|
||||
require('./categories/data')(Categories);
|
||||
require('./categories/create')(Categories);
|
||||
require('./categories/delete')(Categories);
|
||||
@@ -49,7 +48,7 @@ var privileges = require('./privileges');
|
||||
},
|
||||
isIgnored: function (next) {
|
||||
Categories.isIgnored([data.cid], data.uid, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -58,11 +57,11 @@ var privileges = require('./privileges');
|
||||
category.isIgnored = results.isIgnored[0];
|
||||
category.topic_count = results.topicCount;
|
||||
|
||||
plugins.fireHook('filter:category.get', {category: category, uid: data.uid}, next);
|
||||
plugins.fireHook('filter:category.get', { category: category, uid: data.uid }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
next(null, data.category);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -73,7 +72,7 @@ var privileges = require('./privileges');
|
||||
Categories.getPageCount = function (cid, uid, callback) {
|
||||
async.parallel({
|
||||
topicCount: async.apply(Categories.getCategoryField, cid, 'topic_count'),
|
||||
settings: async.apply(user.getSettings, uid)
|
||||
settings: async.apply(user.getSettings, uid),
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -107,7 +106,7 @@ var privileges = require('./privileges');
|
||||
},
|
||||
function (cids, next) {
|
||||
Categories.getCategories(cids, uid, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -146,7 +145,7 @@ var privileges = require('./privileges');
|
||||
},
|
||||
hasRead: function (next) {
|
||||
Categories.hasReadCategories(cids, uid, next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -214,7 +213,7 @@ var privileges = require('./privileges');
|
||||
});
|
||||
|
||||
if (!parentCids.length) {
|
||||
return callback(null, cids.map(function () {return null;}));
|
||||
return callback(null, cids.map(function () { return null; }));
|
||||
}
|
||||
|
||||
Categories.getCategoriesData(parentCids, next);
|
||||
@@ -224,13 +223,13 @@ var privileges = require('./privileges');
|
||||
return parentData[parentCids.indexOf(parseInt(category.parentCid, 10))];
|
||||
});
|
||||
next(null, parentData);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
Categories.getChildren = function (cids, uid, callback) {
|
||||
var categories = cids.map(function (cid) {
|
||||
return {cid: cid};
|
||||
return { cid: cid };
|
||||
});
|
||||
|
||||
async.each(categories, function (category, next) {
|
||||
@@ -266,7 +265,7 @@ var privileges = require('./privileges');
|
||||
async.each(category.children, function (child, next) {
|
||||
getChildrenRecursive(child, uid, next);
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -293,9 +292,12 @@ var privileges = require('./privileges');
|
||||
* @param parentCid {number} start from 0 to build full tree
|
||||
*/
|
||||
Categories.getTree = function (categories, parentCid) {
|
||||
var tree = [], i = 0, len = categories.length, category;
|
||||
var tree = [];
|
||||
var i = 0;
|
||||
var len = categories.length;
|
||||
var category;
|
||||
|
||||
for (i; i < len; ++i) {
|
||||
for (i; i < len; i += 1) {
|
||||
category = categories[i];
|
||||
if (!category.hasOwnProperty('parentCid') || category.parentCid === null) {
|
||||
category.parentCid = 0;
|
||||
@@ -357,9 +359,7 @@ var privileges = require('./privileges');
|
||||
return uid && !isIgnoring[index];
|
||||
});
|
||||
next(null, readingUids);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
|
||||
}(exports));
|
||||
|
||||
@@ -5,7 +5,6 @@ var posts = require('../posts');
|
||||
var db = require('../database');
|
||||
|
||||
module.exports = function (Categories) {
|
||||
|
||||
Categories.getActiveUsers = function (cid, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
@@ -22,7 +21,7 @@ module.exports = function (Categories) {
|
||||
});
|
||||
|
||||
next(null, uids);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -9,7 +9,6 @@ var privileges = require('../privileges');
|
||||
var utils = require('../../public/src/utils');
|
||||
|
||||
module.exports = function (Categories) {
|
||||
|
||||
Categories.create = function (data, callback) {
|
||||
var category;
|
||||
var parentCid = data.parentCid ? data.parentCid : 0;
|
||||
@@ -40,11 +39,11 @@ module.exports = function (Categories) {
|
||||
order: order,
|
||||
link: '',
|
||||
numRecentReplies: 1,
|
||||
class: ( data.class ? data.class : 'col-md-3 col-xs-6' ),
|
||||
imageClass: 'cover'
|
||||
class: (data.class ? data.class : 'col-md-3 col-xs-6'),
|
||||
imageClass: 'cover',
|
||||
};
|
||||
|
||||
plugins.fireHook('filter:category.create', {category: category, data: data}, next);
|
||||
plugins.fireHook('filter:category.create', { category: category, data: data }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
category = data.category;
|
||||
@@ -63,7 +62,7 @@ module.exports = function (Categories) {
|
||||
async.apply(db.sortedSetAdd, 'cid:' + parentCid + ':children', category.order, category.cid),
|
||||
async.apply(privileges.categories.give, defaultPrivileges, category.cid, 'administrators'),
|
||||
async.apply(privileges.categories.give, defaultPrivileges, category.cid, 'registered-users'),
|
||||
async.apply(privileges.categories.give, ['find', 'read', 'topics:read'], category.cid, 'guests')
|
||||
async.apply(privileges.categories.give, ['find', 'read', 'topics:read'], category.cid, 'guests'),
|
||||
], next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -75,7 +74,7 @@ module.exports = function (Categories) {
|
||||
function (category, next) {
|
||||
plugins.fireHook('action:category.create', {category: category});
|
||||
next(null, category);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -93,7 +92,7 @@ module.exports = function (Categories) {
|
||||
function (next) {
|
||||
async.parallel({
|
||||
source: async.apply(db.getObject, 'category:' + fromCid),
|
||||
destination: async.apply(db.getObject, 'category:' + toCid)
|
||||
destination: async.apply(db.getObject, 'category:' + toCid),
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -132,7 +131,7 @@ module.exports = function (Categories) {
|
||||
},
|
||||
function (results, next) {
|
||||
Categories.copyPrivilegesFrom(fromCid, toCid, next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
callback(err, destination);
|
||||
});
|
||||
@@ -176,8 +175,7 @@ module.exports = function (Categories) {
|
||||
async.eachSeries(members, function (member, next) {
|
||||
groups.join('cid:' + toCid + ':privileges:' + privilege, member, next);
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -7,7 +7,6 @@ var winston = require('winston');
|
||||
var db = require('../database');
|
||||
|
||||
module.exports = function (Categories) {
|
||||
|
||||
Categories.getCategoryData = function (cid, callback) {
|
||||
db.getObject('category:' + cid, function (err, category) {
|
||||
if (err) {
|
||||
@@ -46,11 +45,13 @@ module.exports = function (Categories) {
|
||||
category.disabled = category.hasOwnProperty('disabled') ? parseInt(category.disabled, 10) === 1 : undefined;
|
||||
category.icon = category.icon || 'hidden';
|
||||
if (category.hasOwnProperty('post_count')) {
|
||||
category.post_count = category.totalPostCount = category.post_count || 0;
|
||||
category.post_count = category.post_count || 0;
|
||||
category.totalPostCount = category.post_count;
|
||||
}
|
||||
|
||||
if (category.hasOwnProperty('topic_count')) {
|
||||
category.topic_count = category.totalTopicCount = category.topic_count || 0;
|
||||
category.topic_count = category.topic_count || 0;
|
||||
category.totalTopicCount = category.topic_count;
|
||||
}
|
||||
|
||||
if (category.image) {
|
||||
@@ -96,7 +97,7 @@ module.exports = function (Categories) {
|
||||
async.apply(db.getSortedSetRange, 'categories:cid', 0, -1),
|
||||
function (cids, next) {
|
||||
Categories.getCategoriesFields(cids, fields, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -111,5 +112,4 @@ module.exports = function (Categories) {
|
||||
Categories.incrementCategoryFieldBy = function (cid, field, value, callback) {
|
||||
db.incrObjectFieldBy('category:' + cid, field, value, callback);
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -9,7 +9,6 @@ var groups = require('../groups');
|
||||
var privileges = require('../privileges');
|
||||
|
||||
module.exports = function (Categories) {
|
||||
|
||||
Categories.purge = function (cid, uid, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
@@ -17,7 +16,7 @@ module.exports = function (Categories) {
|
||||
async.eachLimit(tids, 10, function (tid, next) {
|
||||
topics.purgePostsAndTopic(tid, uid, next);
|
||||
}, next);
|
||||
}, {alwaysStartAt: 0}, next);
|
||||
}, { alwaysStartAt: 0 }, next);
|
||||
},
|
||||
function (next) {
|
||||
Categories.getPinnedTids('cid:' + cid + ':tids:pinned', 0, -1, next);
|
||||
@@ -33,7 +32,7 @@ module.exports = function (Categories) {
|
||||
function (next) {
|
||||
plugins.fireHook('action:category.delete', {cid: cid, uid: uid});
|
||||
next();
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -55,14 +54,14 @@ module.exports = function (Categories) {
|
||||
'cid:' + cid + ':ignorers',
|
||||
'cid:' + cid + ':children',
|
||||
'cid:' + cid + ':tag:whitelist',
|
||||
'category:' + cid
|
||||
'category:' + cid,
|
||||
], next);
|
||||
},
|
||||
function (next) {
|
||||
async.each(privileges.privilegeList, function (privilege, next) {
|
||||
groups.destroy('cid:' + cid + ':privileges:' + privilege, next);
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
callback(err);
|
||||
});
|
||||
@@ -77,7 +76,7 @@ module.exports = function (Categories) {
|
||||
},
|
||||
children: function (next) {
|
||||
db.getSortedSetRange('cid:' + cid + ':children', 0, -1, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -94,14 +93,14 @@ module.exports = function (Categories) {
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetAdd('cid:0:children', cid, cid, next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -14,7 +14,6 @@ var batch = require('../batch');
|
||||
|
||||
|
||||
module.exports = function (Categories) {
|
||||
|
||||
Categories.getRecentReplies = function (cid, uid, count, callback) {
|
||||
if (!parseInt(count, 10)) {
|
||||
return callback(null, []);
|
||||
@@ -28,8 +27,8 @@ module.exports = function (Categories) {
|
||||
privileges.posts.filter('read', pids, uid, next);
|
||||
},
|
||||
function (pids, next) {
|
||||
posts.getPostSummaryByPids(pids, uid, {stripTags: true}, next);
|
||||
}
|
||||
posts.getPostSummaryByPids(pids, uid, { stripTags: true }, next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -40,7 +39,7 @@ module.exports = function (Categories) {
|
||||
},
|
||||
numRecentReplies: function (next) {
|
||||
db.getObjectField('category:' + cid, 'numRecentReplies', next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -61,7 +60,7 @@ module.exports = function (Categories) {
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetAdd('cid:' + cid + ':recent_tids', Date.now(), tid, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
});
|
||||
};
|
||||
@@ -95,7 +94,7 @@ module.exports = function (Categories) {
|
||||
bubbleUpChildrenPosts(categoryData);
|
||||
|
||||
next();
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -131,17 +130,19 @@ module.exports = function (Categories) {
|
||||
results.teasers.forEach(function (teaser, index) {
|
||||
if (teaser) {
|
||||
teaser.cid = topicData[index].cid;
|
||||
teaser.parentCid = parseInt(parentCids[teaser.cid]) || 0;
|
||||
teaser.tid = teaser.uid = teaser.user.uid = undefined;
|
||||
teaser.parentCid = parseInt(parentCids[teaser.cid], 10) || 0;
|
||||
teaser.tid = undefined;
|
||||
teaser.uid = undefined;
|
||||
teaser.user.uid = undefined;
|
||||
teaser.topic = {
|
||||
slug: topicData[index].slug,
|
||||
title: validator.escape(String(topicData[index].title))
|
||||
title: validator.escape(String(topicData[index].title)),
|
||||
};
|
||||
}
|
||||
});
|
||||
results.teasers = results.teasers.filter(Boolean);
|
||||
next(null, results.teasers);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -211,9 +212,9 @@ module.exports = function (Categories) {
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetAdd('cid:' + cid + ':pids', timestamps, pids, next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
@@ -238,7 +239,7 @@ module.exports = function (Categories) {
|
||||
},
|
||||
function (next) {
|
||||
db.incrObjectFieldBy('category:' + newCid, 'post_count', postCount, next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
winston.error(err.message);
|
||||
@@ -248,4 +249,3 @@ module.exports = function (Categories) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ var topics = require('../topics');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
module.exports = function (Categories) {
|
||||
|
||||
Categories.getCategoryTopics = function (data, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
@@ -21,23 +20,23 @@ module.exports = function (Categories) {
|
||||
},
|
||||
function (topics, next) {
|
||||
if (!Array.isArray(topics) || !topics.length) {
|
||||
return next(null, {topics: [], uid: data.uid});
|
||||
return next(null, { topics: [], uid: data.uid });
|
||||
}
|
||||
|
||||
for (var i = 0; i < topics.length; ++i) {
|
||||
for (var i = 0; i < topics.length; i += 1) {
|
||||
topics[i].index = data.start + i;
|
||||
}
|
||||
|
||||
plugins.fireHook('filter:category.topics.get', {cid: data.cid, topics: topics, uid: data.uid}, next);
|
||||
plugins.fireHook('filter:category.topics.get', { cid: data.cid, topics: topics, uid: data.uid }, next);
|
||||
},
|
||||
function (results, next) {
|
||||
next(null, {topics: results.topics, nextStart: data.stop + 1});
|
||||
}
|
||||
next(null, { topics: results.topics, nextStart: data.stop + 1 });
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
Categories.getTopicIds = function (cid, set, reverse, start, stop, callback) {
|
||||
var pinnedTids;
|
||||
var pinnedTids;
|
||||
var pinnedCount;
|
||||
var totalPinnedCount;
|
||||
|
||||
@@ -65,7 +64,7 @@ module.exports = function (Categories) {
|
||||
stop = stop === -1 ? stop : start + normalTidsToGet - 1;
|
||||
|
||||
if (Array.isArray(set)) {
|
||||
db[reverse ? 'getSortedSetRevIntersect' : 'getSortedSetIntersect']({sets: set, start: start, stop: stop}, next);
|
||||
db[reverse ? 'getSortedSetRevIntersect' : 'getSortedSetIntersect']({ sets: set, start: start, stop: stop }, next);
|
||||
} else {
|
||||
db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, stop, next);
|
||||
}
|
||||
@@ -76,7 +75,7 @@ module.exports = function (Categories) {
|
||||
});
|
||||
|
||||
next(null, pinnedTids.concat(normalTids));
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -132,15 +131,14 @@ module.exports = function (Categories) {
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetIncrBy('cid:' + cid + ':tids:posts', 1, postData.tid, next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
function (next) {
|
||||
Categories.updateRecentTid(cid, postData.tid, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
"use strict";
|
||||
|
||||
var async = require('async');
|
||||
var db = require('../database');
|
||||
|
||||
module.exports = function (Categories) {
|
||||
|
||||
Categories.markAsRead = function (cids, uid, callback) {
|
||||
callback = callback || function () {};
|
||||
if (!Array.isArray(cids) || !cids.length) {
|
||||
@@ -43,7 +40,7 @@ module.exports = function (Categories) {
|
||||
Categories.hasReadCategories = function (cids, uid, callback) {
|
||||
var sets = [];
|
||||
|
||||
for (var i = 0, ii = cids.length; i < ii; i++) {
|
||||
for (var i = 0, ii = cids.length; i < ii; i += 1) {
|
||||
sets.push('cid:' + cids[i] + ':read_by_uid');
|
||||
}
|
||||
|
||||
@@ -53,5 +50,4 @@ module.exports = function (Categories) {
|
||||
Categories.hasReadCategory = function (cid, uid, callback) {
|
||||
db.isSetMember('cid:' + cid + ':read_by_uid', uid, callback);
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -10,9 +10,7 @@ var translator = require('../../public/src/modules/translator');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
module.exports = function (Categories) {
|
||||
|
||||
Categories.update = function (modified, callback) {
|
||||
|
||||
var cids = Object.keys(modified);
|
||||
|
||||
async.each(cids, function (cid, next) {
|
||||
@@ -43,7 +41,7 @@ module.exports = function (Categories) {
|
||||
}
|
||||
},
|
||||
function (next) {
|
||||
plugins.fireHook('filter:category.update', {category: modifiedFields}, next);
|
||||
plugins.fireHook('filter:category.update', { category: modifiedFields }, next);
|
||||
},
|
||||
function (categoryData, next) {
|
||||
category = categoryData.category;
|
||||
@@ -59,9 +57,9 @@ module.exports = function (Categories) {
|
||||
}, next);
|
||||
},
|
||||
function (next) {
|
||||
plugins.fireHook('action:category.update', {cid: cid, modified: category});
|
||||
plugins.fireHook('action:category.update', { cid: cid, modified: category });
|
||||
next();
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -84,7 +82,7 @@ module.exports = function (Categories) {
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -108,9 +106,9 @@ module.exports = function (Categories) {
|
||||
},
|
||||
function (next) {
|
||||
db.setObjectField('category:' + cid, 'parentCid', newParent, next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
callback(err);
|
||||
});
|
||||
@@ -131,7 +129,7 @@ module.exports = function (Categories) {
|
||||
return index;
|
||||
});
|
||||
db.sortedSetAdd('cid:' + cid + ':tag:whitelist', scores, tags, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -148,9 +146,9 @@ module.exports = function (Categories) {
|
||||
function (next) {
|
||||
parentCid = parseInt(parentCid, 10) || 0;
|
||||
db.sortedSetAdd('cid:' + parentCid + ':children', order, cid, next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
callback(err);
|
||||
});
|
||||
@@ -163,8 +161,7 @@ module.exports = function (Categories) {
|
||||
},
|
||||
function (parsedDescription, next) {
|
||||
Categories.setCategoryField(cid, 'descriptionParsed', parsedDescription, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ var accountsController = {
|
||||
posts: require('./accounts/posts'),
|
||||
notifications: require('./accounts/notifications'),
|
||||
chats: require('./accounts/chats'),
|
||||
session: require('./accounts/session')
|
||||
session: require('./accounts/session'),
|
||||
};
|
||||
|
||||
module.exports = accountsController;
|
||||
|
||||
@@ -21,7 +21,7 @@ chatsController.get = function (req, res, callback) {
|
||||
function (next) {
|
||||
async.parallel({
|
||||
uid: async.apply(user.getUidByUserslug, req.params.userslug),
|
||||
username: async.apply(user.getUsernameByUserslug, req.params.userslug)
|
||||
username: async.apply(user.getUsernameByUserslug, req.params.userslug),
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -45,7 +45,7 @@ chatsController.get = function (req, res, callback) {
|
||||
nextStart: recentChats.nextStart,
|
||||
allowed: true,
|
||||
title: '[[pages:chats]]',
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{text: username, url: '/user/' + req.params.userslug}, {text: '[[pages:chats]]'}])
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{ text: username, url: '/user/' + req.params.userslug }, { text: '[[pages:chats]]' }]),
|
||||
});
|
||||
}
|
||||
messaging.isUserInRoom(req.uid, req.params.roomid, next);
|
||||
@@ -62,10 +62,10 @@ chatsController.get = function (req, res, callback) {
|
||||
callerUid: req.uid,
|
||||
uid: uid,
|
||||
roomId: req.params.roomid,
|
||||
isNew: false
|
||||
})
|
||||
isNew: false,
|
||||
}),
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
], function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -87,9 +87,9 @@ chatsController.get = function (req, res, callback) {
|
||||
room.usernames = messaging.generateUsernames(room.users, req.uid);
|
||||
room.title = room.roomName || room.usernames || '[[pages:chats]]';
|
||||
room.breadcrumbs = helpers.buildBreadcrumbs([
|
||||
{text: username, url: '/user/' + req.params.userslug},
|
||||
{text: '[[pages:chats]]', url: '/user/' + req.params.userslug + '/chats'},
|
||||
{text: room.roomName || room.usernames || '[[pages:chats]]'}
|
||||
{ text: username, url: '/user/' + req.params.userslug },
|
||||
{ text: '[[pages:chats]]', url: '/user/' + req.params.userslug + '/chats' },
|
||||
{ text: room.roomName || room.usernames || '[[pages:chats]]' },
|
||||
]);
|
||||
room.maximumUsersInChatRoom = parseInt(meta.config.maximumUsersInChatRoom, 10) || 0;
|
||||
room.maximumChatMessageLength = parseInt(meta.config.maximumChatMessageLength, 10) || 1000;
|
||||
@@ -114,5 +114,4 @@ chatsController.redirectToChat = function (req, res, next) {
|
||||
};
|
||||
|
||||
|
||||
|
||||
module.exports = chatsController;
|
||||
module.exports = chatsController;
|
||||
|
||||
@@ -25,7 +25,7 @@ editController.get = function (req, res, callback) {
|
||||
userData.maximumSignatureLength = parseInt(meta.config.maximumSignatureLength, 10) || 255;
|
||||
userData.maximumAboutMeLength = parseInt(meta.config.maximumAboutMeLength, 10) || 1000;
|
||||
userData.maximumProfileImageSize = parseInt(meta.config.maximumProfileImageSize, 10);
|
||||
userData.allowProfileImageUploads = parseInt(meta.config.allowProfileImageUploads) === 1;
|
||||
userData.allowProfileImageUploads = parseInt(meta.config.allowProfileImageUploads, 10) === 1;
|
||||
userData.allowAccountDelete = parseInt(meta.config.allowAccountDelete, 10) === 1;
|
||||
userData.profileImageDimension = parseInt(meta.config.profileImageDimension, 10) || 128;
|
||||
|
||||
@@ -37,12 +37,15 @@ editController.get = function (req, res, callback) {
|
||||
});
|
||||
|
||||
userData.title = '[[pages:account/edit, ' + userData.username + ']]';
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{
|
||||
text: userData.username,
|
||||
url: '/user/' + userData.userslug
|
||||
}, {
|
||||
text: '[[user:edit]]'
|
||||
}]);
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([
|
||||
{
|
||||
text: userData.username,
|
||||
url: '/user/' + userData.userslug,
|
||||
},
|
||||
{
|
||||
text: '[[user:edit]]',
|
||||
},
|
||||
]);
|
||||
userData.editButtons = [];
|
||||
|
||||
plugins.fireHook('filter:user.account.edit', userData, function (err, userData) {
|
||||
@@ -81,15 +84,19 @@ function renderRoute(name, req, res, next) {
|
||||
}
|
||||
|
||||
userData.title = '[[pages:account/edit/' + name + ', ' + userData.username + ']]';
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{
|
||||
text: userData.username,
|
||||
url: '/user/' + userData.userslug
|
||||
}, {
|
||||
text: '[[user:edit]]',
|
||||
url: '/user/' + userData.userslug + '/edit'
|
||||
}, {
|
||||
text: '[[user:' + name + ']]'
|
||||
}]);
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([
|
||||
{
|
||||
text: userData.username,
|
||||
url: '/user/' + userData.userslug,
|
||||
},
|
||||
{
|
||||
text: '[[user:edit]]',
|
||||
url: '/user/' + userData.userslug + '/edit',
|
||||
},
|
||||
{
|
||||
text: '[[user:' + name + ']]',
|
||||
},
|
||||
]);
|
||||
|
||||
res.render('account/edit/' + name, userData);
|
||||
});
|
||||
@@ -107,7 +114,7 @@ function getUserData(req, next, callback) {
|
||||
return callback();
|
||||
}
|
||||
db.getObjectField('user:' + userData.uid, 'password', next);
|
||||
}
|
||||
},
|
||||
], function (err, password) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -138,7 +145,7 @@ editController.uploadPicture = function (req, res, next) {
|
||||
}
|
||||
|
||||
user.uploadPicture(updateUid, userPhoto, next);
|
||||
}
|
||||
},
|
||||
], function (err, image) {
|
||||
fs.unlink(userPhoto.path, function (err) {
|
||||
if (err) {
|
||||
@@ -151,7 +158,7 @@ editController.uploadPicture = function (req, res, next) {
|
||||
|
||||
res.json([{
|
||||
name: userPhoto.name,
|
||||
url: image.url.startsWith('http') ? image.url : nconf.get('relative_path') + image.url
|
||||
url: image.url.startsWith('http') ? image.url : nconf.get('relative_path') + image.url,
|
||||
}]);
|
||||
});
|
||||
};
|
||||
@@ -161,14 +168,14 @@ editController.uploadCoverPicture = function (req, res, next) {
|
||||
|
||||
user.updateCoverPicture({
|
||||
file: req.files.files[0],
|
||||
uid: params.uid
|
||||
uid: params.uid,
|
||||
}, function (err, image) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.json([{
|
||||
url: image.url
|
||||
url: image.url,
|
||||
}]);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -36,7 +36,7 @@ function getFollow(tpl, name, req, res, callback) {
|
||||
}
|
||||
var method = name === 'following' ? 'getFollowing' : 'getFollowers';
|
||||
user[method](userData.uid, start, stop, next);
|
||||
}
|
||||
},
|
||||
], function (err, users) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -47,10 +47,10 @@ function getFollow(tpl, name, req, res, callback) {
|
||||
var count = name === 'following' ? userData.followingCount : userData.followerCount;
|
||||
var pageCount = Math.ceil(count / resultsPerPage);
|
||||
userData.pagination = pagination.create(page, pageCount);
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: '[[user:' + name + ']]'}]);
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:' + name + ']]' }]);
|
||||
|
||||
res.render(tpl, userData);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = followController;
|
||||
module.exports = followController;
|
||||
|
||||
@@ -38,7 +38,7 @@ groupsController.get = function (req, res, callback) {
|
||||
group.members = members[index];
|
||||
});
|
||||
next();
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -46,9 +46,9 @@ groupsController.get = function (req, res, callback) {
|
||||
|
||||
userData.groups = groupsData;
|
||||
userData.title = '[[pages:account/groups, ' + userData.username + ']]';
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: '[[global:header.groups]]'}]);
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[global:header.groups]]' }]);
|
||||
res.render('account/groups', userData);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = groupsController;
|
||||
module.exports = groupsController;
|
||||
|
||||
@@ -52,14 +52,14 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
|
||||
plugins.fireHook('filter:user.profileLinks', [], next);
|
||||
},
|
||||
profile_menu: function (next) {
|
||||
plugins.fireHook('filter:user.profileMenu', {uid: uid, callerUID: callerUID, links: []}, next);
|
||||
plugins.fireHook('filter:user.profileMenu', { uid: uid, callerUID: callerUID, links: [] }, next);
|
||||
},
|
||||
groups: function (next) {
|
||||
groups.getUserGroups([uid], next);
|
||||
},
|
||||
sso: function (next) {
|
||||
plugins.fireHook('filter:auth.list', {uid: uid, associations: []}, next);
|
||||
}
|
||||
plugins.fireHook('filter:auth.list', { uid: uid, associations: [] }, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -150,7 +150,7 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
|
||||
userData['email:disableEdit'] = !userData.isAdmin && parseInt(meta.config['email:disableEdit'], 10) === 1;
|
||||
|
||||
next(null, userData);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ infoController.get = function (req, res, callback) {
|
||||
history: async.apply(user.getModerationHistory, userData.uid),
|
||||
sessions: async.apply(user.auth.getSessions, userData.uid, req.sessionID),
|
||||
usernames: async.apply(user.getHistory, 'user:' + userData.uid + ':usernames'),
|
||||
emails: async.apply(user.getHistory, 'user:' + userData.uid + ':emails')
|
||||
emails: async.apply(user.getHistory, 'user:' + userData.uid + ':emails'),
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
], function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -36,10 +36,10 @@ infoController.get = function (req, res, callback) {
|
||||
userData.usernames = data.usernames;
|
||||
userData.emails = data.emails;
|
||||
userData.title = '[[pages:account/info]]';
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: '[[user:account_info]]'}]);
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:account_info]]' }]);
|
||||
|
||||
res.render('account/info', userData);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = infoController;
|
||||
module.exports = infoController;
|
||||
|
||||
@@ -14,7 +14,7 @@ notificationsController.get = function (req, res, next) {
|
||||
notifications: notifications,
|
||||
nextStart: 40,
|
||||
title: '[[pages:notifications]]',
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[pages:notifications]]'}])
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{ text: '[[pages:notifications]]' }]),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -18,44 +18,44 @@ var templateToData = {
|
||||
set: 'bookmarks',
|
||||
type: 'posts',
|
||||
noItemsFoundKey: '[[topic:bookmarks.has_no_bookmarks]]',
|
||||
crumb: '[[user:bookmarks]]'
|
||||
crumb: '[[user:bookmarks]]',
|
||||
},
|
||||
'account/posts': {
|
||||
set: 'posts',
|
||||
type: 'posts',
|
||||
noItemsFoundKey: '[[user:has_no_posts]]',
|
||||
crumb: '[[global:posts]]'
|
||||
crumb: '[[global:posts]]',
|
||||
},
|
||||
'account/upvoted': {
|
||||
set: 'upvote',
|
||||
type: 'posts',
|
||||
noItemsFoundKey: '[[user:has_no_upvoted_posts]]',
|
||||
crumb: '[[global:upvoted]]'
|
||||
crumb: '[[global:upvoted]]',
|
||||
},
|
||||
'account/downvoted': {
|
||||
set: 'downvote',
|
||||
type: 'posts',
|
||||
noItemsFoundKey: '[[user:has_no_downvoted_posts]]',
|
||||
crumb: '[[global:downvoted]]'
|
||||
crumb: '[[global:downvoted]]',
|
||||
},
|
||||
'account/best': {
|
||||
set: 'posts:votes',
|
||||
type: 'posts',
|
||||
noItemsFoundKey: '[[user:has_no_voted_posts]]',
|
||||
crumb: '[[global:best]]'
|
||||
crumb: '[[global:best]]',
|
||||
},
|
||||
'account/watched': {
|
||||
set: 'followed_tids',
|
||||
type: 'topics',
|
||||
noItemsFoundKey: '[[user:has_no_watched_topics]]',
|
||||
crumb: '[[user:watched]]'
|
||||
crumb: '[[user:watched]]',
|
||||
},
|
||||
'account/topics': {
|
||||
set: 'topics',
|
||||
type: 'topics',
|
||||
noItemsFoundKey: '[[user:has_no_topics]]',
|
||||
crumb: '[[global:topics]]'
|
||||
}
|
||||
crumb: '[[global:topics]]',
|
||||
},
|
||||
};
|
||||
|
||||
postsController.getBookmarks = function (req, res, next) {
|
||||
@@ -101,7 +101,7 @@ function getFromUserSet(template, req, res, callback) {
|
||||
},
|
||||
userData: function (next) {
|
||||
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -127,9 +127,9 @@ function getFromUserSet(template, req, res, callback) {
|
||||
var start = (page - 1) * itemsPerPage;
|
||||
var stop = start + itemsPerPage - 1;
|
||||
data.method(setName, req.uid, start, stop, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
], function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -143,10 +143,10 @@ function getFromUserSet(template, req, res, callback) {
|
||||
|
||||
userData.noItemsFoundKey = data.noItemsFoundKey;
|
||||
userData.title = '[[pages:' + data.template + ', ' + userData.username + ']]';
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: data.crumb}]);
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: data.crumb }]);
|
||||
|
||||
res.render(data.template, userData);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = postsController;
|
||||
module.exports = postsController;
|
||||
|
||||
@@ -62,7 +62,7 @@ profileController.get = function (req, res, callback) {
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -76,7 +76,7 @@ profileController.get = function (req, res, callback) {
|
||||
userData.hasPrivateChat = results.hasPrivateChat;
|
||||
userData.aboutme = results.aboutme;
|
||||
userData.nextStart = results.posts.nextStart;
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username}]);
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username }]);
|
||||
userData.title = userData.username;
|
||||
var pageCount = Math.ceil(userData.postcount / itemsPerPage);
|
||||
userData.pagination = pagination.create(page, pageCount, req.query);
|
||||
@@ -92,21 +92,21 @@ profileController.get = function (req, res, callback) {
|
||||
|
||||
res.locals.metaTags = [
|
||||
{
|
||||
name: "title",
|
||||
content: userData.fullname || userData.username
|
||||
name: 'title',
|
||||
content: userData.fullname || userData.username,
|
||||
},
|
||||
{
|
||||
name: "description",
|
||||
content: plainAboutMe
|
||||
name: 'description',
|
||||
content: plainAboutMe,
|
||||
},
|
||||
{
|
||||
property: 'og:title',
|
||||
content: userData.fullname || userData.username
|
||||
content: userData.fullname || userData.username,
|
||||
},
|
||||
{
|
||||
property: 'og:description',
|
||||
content: plainAboutMe
|
||||
}
|
||||
content: plainAboutMe,
|
||||
},
|
||||
];
|
||||
|
||||
if (userData.picture) {
|
||||
@@ -114,12 +114,12 @@ profileController.get = function (req, res, callback) {
|
||||
{
|
||||
property: 'og:image',
|
||||
content: userData.picture,
|
||||
noEscape: true
|
||||
noEscape: true,
|
||||
},
|
||||
{
|
||||
property: "og:image:url",
|
||||
property: 'og:image:url',
|
||||
content: userData.picture,
|
||||
noEscape: true
|
||||
noEscape: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -127,8 +127,8 @@ profileController.get = function (req, res, callback) {
|
||||
return group && group.name === userData.groupTitle;
|
||||
});
|
||||
|
||||
plugins.fireHook('filter:user.account', {userData: userData, uid: req.uid}, next);
|
||||
}
|
||||
plugins.fireHook('filter:user.account', { userData: userData, uid: req.uid }, next);
|
||||
},
|
||||
], function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -137,4 +137,4 @@ profileController.get = function (req, res, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = profileController;
|
||||
module.exports = profileController;
|
||||
|
||||
@@ -42,14 +42,13 @@ sessionController.revoke = function (req, res, next) {
|
||||
}
|
||||
|
||||
user.auth.revokeSession(_id, uid, next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return res.status(500).send(err.message);
|
||||
} else {
|
||||
return res.sendStatus(200);
|
||||
}
|
||||
return res.sendStatus(200);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = sessionController;
|
||||
module.exports = sessionController;
|
||||
|
||||
@@ -39,7 +39,7 @@ settingsController.get = function (req, res, callback) {
|
||||
},
|
||||
soundsMapping: function (next) {
|
||||
meta.sounds.getUserSoundMap(userData.uid, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -53,7 +53,7 @@ settingsController.get = function (req, res, callback) {
|
||||
'chat-outgoing',
|
||||
];
|
||||
var aliases = {
|
||||
'notification': 'notificationSound',
|
||||
notification: 'notificationSound',
|
||||
'chat-incoming': 'incomingChatSound',
|
||||
'chat-outgoing': 'outgoingChatSound',
|
||||
};
|
||||
@@ -93,38 +93,38 @@ settingsController.get = function (req, res, callback) {
|
||||
userData.customSettings = data.customSettings;
|
||||
userData.disableEmailSubscriptions = parseInt(meta.config.disableEmailSubscriptions, 10) === 1;
|
||||
next();
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
userData.dailyDigestFreqOptions = [
|
||||
{ value: 'off', name: '[[user:digest_off]]', selected: 'off' === userData.settings.dailyDigestFreq },
|
||||
{ value: 'day', name: '[[user:digest_daily]]', selected: 'day' === userData.settings.dailyDigestFreq },
|
||||
{ value: 'week', name: '[[user:digest_weekly]]', selected: 'week' === userData.settings.dailyDigestFreq },
|
||||
{ value: 'month', name: '[[user:digest_monthly]]', selected: 'month' === userData.settings.dailyDigestFreq }
|
||||
{ value: 'off', name: '[[user:digest_off]]', selected: userData.settings.dailyDigestFreq === 'off' },
|
||||
{ value: 'day', name: '[[user:digest_daily]]', selected: userData.settings.dailyDigestFreq === 'day' },
|
||||
{ value: 'week', name: '[[user:digest_weekly]]', selected: userData.settings.dailyDigestFreq === 'week' },
|
||||
{ value: 'month', name: '[[user:digest_monthly]]', selected: userData.settings.dailyDigestFreq === 'month' },
|
||||
];
|
||||
|
||||
|
||||
userData.bootswatchSkinOptions = [
|
||||
{ "name": "Default", "value": "default" },
|
||||
{ "name": "Cerulean", "value": "cerulean" },
|
||||
{ "name": "Cosmo", "value": "cosmo" },
|
||||
{ "name": "Cyborg", "value": "cyborg" },
|
||||
{ "name": "Darkly", "value": "darkly" },
|
||||
{ "name": "Flatly", "value": "flatly" },
|
||||
{ "name": "Journal", "value": "journal" },
|
||||
{ "name": "Lumen", "value": "lumen" },
|
||||
{ "name": "Paper", "value": "paper" },
|
||||
{ "name": "Readable", "value": "readable" },
|
||||
{ "name": "Sandstone", "value": "sandstone" },
|
||||
{ "name": "Simplex", "value": "simplex" },
|
||||
{ "name": "Slate", "value": "slate" },
|
||||
{ "name": "Spacelab", "value": "spacelab" },
|
||||
{ "name": "Superhero", "value": "superhero" },
|
||||
{ "name": "United", "value": "united" },
|
||||
{ "name": "Yeti", "value": "yeti" }
|
||||
{ name: 'Default', value: 'default' },
|
||||
{ name: 'Cerulean', value: 'cerulean' },
|
||||
{ name: 'Cosmo', value: 'cosmo' },
|
||||
{ name: 'Cyborg', value: 'cyborg' },
|
||||
{ name: 'Darkly', value: 'darkly' },
|
||||
{ name: 'Flatly', value: 'flatly' },
|
||||
{ name: 'Journal', value: 'journal' },
|
||||
{ name: 'Lumen', value: 'lumen' },
|
||||
{ name: 'Paper', value: 'paper' },
|
||||
{ name: 'Readable', value: 'readable' },
|
||||
{ name: 'Sandstone', value: 'sandstone' },
|
||||
{ name: 'Simplex', value: 'simplex' },
|
||||
{ name: 'Slate', value: 'slate' },
|
||||
{ name: 'Spacelab', value: 'spacelab' },
|
||||
{ name: 'Superhero', value: 'superhero' },
|
||||
{ name: 'United', value: 'united' },
|
||||
{ name: 'Yeti', value: 'yeti' },
|
||||
];
|
||||
|
||||
var isCustom = true;
|
||||
@@ -140,9 +140,9 @@ settingsController.get = function (req, res, callback) {
|
||||
}
|
||||
|
||||
userData.homePageRoutes.push({
|
||||
route: 'custom',
|
||||
name: 'Custom',
|
||||
selected: isCustom
|
||||
route: 'custom',
|
||||
name: 'Custom',
|
||||
selected: isCustom,
|
||||
});
|
||||
|
||||
userData.bootswatchSkinOptions.forEach(function (skin) {
|
||||
@@ -160,7 +160,7 @@ settingsController.get = function (req, res, callback) {
|
||||
userData.inTopicSearchAvailable = plugins.hasListeners('filter:topic.search');
|
||||
|
||||
userData.title = '[[pages:account/settings]]';
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: '[[user:settings]]'}]);
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:settings]]' }]);
|
||||
|
||||
res.render('account/settings', userData);
|
||||
});
|
||||
@@ -182,36 +182,36 @@ function getHomePageRoutes(callback) {
|
||||
categoryData = categoryData.map(function (category) {
|
||||
return {
|
||||
route: 'category/' + category.slug,
|
||||
name: 'Category: ' + category.name
|
||||
name: 'Category: ' + category.name,
|
||||
};
|
||||
});
|
||||
|
||||
categoryData = categoryData || [];
|
||||
|
||||
plugins.fireHook('filter:homepage.get', {routes: [
|
||||
plugins.fireHook('filter:homepage.get', { routes: [
|
||||
{
|
||||
route: 'categories',
|
||||
name: 'Categories'
|
||||
name: 'Categories',
|
||||
},
|
||||
{
|
||||
route: 'unread',
|
||||
name: 'Unread'
|
||||
name: 'Unread',
|
||||
},
|
||||
{
|
||||
route: 'recent',
|
||||
name: 'Recent'
|
||||
name: 'Recent',
|
||||
},
|
||||
{
|
||||
route: 'popular',
|
||||
name: 'Popular'
|
||||
}
|
||||
].concat(categoryData)}, next);
|
||||
name: 'Popular',
|
||||
},
|
||||
].concat(categoryData) }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
next(null, data.routes);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
|
||||
module.exports = settingsController;
|
||||
module.exports = settingsController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var adminController = {
|
||||
dashboard: require('./admin/dashboard'),
|
||||
@@ -9,7 +9,7 @@ var adminController = {
|
||||
appearance: require('./admin/appearance'),
|
||||
extend: {
|
||||
widgets: require('./admin/widgets'),
|
||||
rewards: require('./admin/rewards')
|
||||
rewards: require('./admin/rewards'),
|
||||
},
|
||||
events: require('./admin/events'),
|
||||
logs: require('./admin/logs'),
|
||||
@@ -27,7 +27,7 @@ var adminController = {
|
||||
themes: require('./admin/themes'),
|
||||
users: require('./admin/users'),
|
||||
uploads: require('./admin/uploads'),
|
||||
info: require('./admin/info')
|
||||
info: require('./admin/info'),
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var appearanceController = {};
|
||||
|
||||
appearanceController.get = function (req, res, next) {
|
||||
appearanceController.get = function (req, res) {
|
||||
var term = req.params.term ? req.params.term : 'themes';
|
||||
|
||||
res.render('admin/appearance/' + term, {});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var meta = require('../../meta');
|
||||
|
||||
@@ -11,7 +11,7 @@ blacklistController.get = function (req, res, next) {
|
||||
}
|
||||
res.render('admin/manage/ip-blacklist', {
|
||||
rules: rules,
|
||||
title: '[[pages:ip-blacklist]]'
|
||||
title: '[[pages:ip-blacklist]]',
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
var cacheController = {};
|
||||
|
||||
cacheController.get = function (req, res, next) {
|
||||
cacheController.get = function (req, res) {
|
||||
var postCache = require('../../posts/cache');
|
||||
var groupCache = require('../../groups').cache;
|
||||
|
||||
@@ -19,17 +19,17 @@ cacheController.get = function (req, res, next) {
|
||||
max: postCache.max,
|
||||
itemCount: postCache.itemCount,
|
||||
percentFull: percentFull,
|
||||
avgPostSize: avgPostSize
|
||||
avgPostSize: avgPostSize,
|
||||
},
|
||||
groupCache: {
|
||||
length: groupCache.length,
|
||||
max: groupCache.max,
|
||||
itemCount: groupCache.itemCount,
|
||||
percentFull: ((groupCache.length / groupCache.max) * 100).toFixed(2),
|
||||
dump: req.query.debug ? JSON.stringify(groupCache.dump(), null, 4) : false
|
||||
}
|
||||
dump: req.query.debug ? JSON.stringify(groupCache.dump(), null, 4) : false,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
module.exports = cacheController;
|
||||
module.exports = cacheController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
@@ -14,7 +14,7 @@ var categoriesController = {};
|
||||
categoriesController.get = function (req, res, next) {
|
||||
async.parallel({
|
||||
category: async.apply(categories.getCategories, [req.params.category_id], req.user.uid),
|
||||
privileges: async.apply(privileges.categories.list, req.params.category_id)
|
||||
privileges: async.apply(privileges.categories.list, req.params.category_id),
|
||||
}, function (err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -32,13 +32,13 @@ categoriesController.get = function (req, res, next) {
|
||||
data.category.name = translator.escape(String(data.category.name));
|
||||
res.render('admin/manage/category', {
|
||||
category: data.category,
|
||||
privileges: data.privileges
|
||||
privileges: data.privileges,
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
categoriesController.getAll = function (req, res, next) {
|
||||
categoriesController.getAll = function (req, res) {
|
||||
// Categories list will be rendered on client side with recursion, etc.
|
||||
res.render('admin/manage/categories', {});
|
||||
};
|
||||
@@ -46,7 +46,7 @@ categoriesController.getAll = function (req, res, next) {
|
||||
categoriesController.getAnalytics = function (req, res, next) {
|
||||
async.parallel({
|
||||
name: async.apply(categories.getCategoryField, req.params.category_id, 'name'),
|
||||
analytics: async.apply(analytics.getCategoryAnalytics, req.params.category_id)
|
||||
analytics: async.apply(analytics.getCategoryAnalytics, req.params.category_id),
|
||||
}, function (err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
|
||||
@@ -20,26 +20,26 @@ dashboardController.get = function (req, res, next) {
|
||||
{
|
||||
done: !meta.reloadRequired,
|
||||
doneText: '[[admin/general/dashboard:restart-not-required]]',
|
||||
notDoneText:'[[admin/general/dashboard:restart-required]]'
|
||||
notDoneText: '[[admin/general/dashboard:restart-required]]',
|
||||
},
|
||||
{
|
||||
done: plugins.hasListeners('filter:search.query'),
|
||||
doneText: '[[admin/general/dashboard:search-plugin-installed]]',
|
||||
notDoneText:'[[admin/general/dashboard:search-plugin-not-installed]]',
|
||||
notDoneText: '[[admin/general/dashboard:search-plugin-not-installed]]',
|
||||
tooltip: '[[admin/general/dashboard:search-plugin-tooltip]]',
|
||||
link:'/admin/extend/plugins'
|
||||
}
|
||||
link: '/admin/extend/plugins',
|
||||
},
|
||||
];
|
||||
|
||||
if (global.env !== 'production') {
|
||||
notices.push({
|
||||
done: false,
|
||||
notDoneText: '[[admin/general/dashboard:running-in-development]]'
|
||||
notDoneText: '[[admin/general/dashboard:running-in-development]]',
|
||||
});
|
||||
}
|
||||
|
||||
plugins.fireHook('filter:admin.notices', notices, next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -47,7 +47,7 @@ dashboardController.get = function (req, res, next) {
|
||||
res.render('admin/general/dashboard', {
|
||||
version: nconf.get('version'),
|
||||
notices: results.notices,
|
||||
stats: results.stats
|
||||
stats: results.stats,
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -65,7 +65,7 @@ function getStats(callback) {
|
||||
},
|
||||
function (next) {
|
||||
getStatsForSet('topics:tid', 'topicCount', next);
|
||||
}
|
||||
},
|
||||
], function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -83,7 +83,7 @@ function getStatsForSet(set, field, callback) {
|
||||
var terms = {
|
||||
day: 86400000,
|
||||
week: 604800000,
|
||||
month: 2592000000
|
||||
month: 2592000000,
|
||||
};
|
||||
|
||||
var now = Date.now();
|
||||
@@ -99,7 +99,7 @@ function getStatsForSet(set, field, callback) {
|
||||
},
|
||||
alltime: function (next) {
|
||||
getGlobalField(field, next);
|
||||
}
|
||||
},
|
||||
}, callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ var nconf = require('nconf');
|
||||
var databaseController = {};
|
||||
|
||||
|
||||
|
||||
databaseController.get = function (req, res, next) {
|
||||
async.parallel({
|
||||
redis: function (next) {
|
||||
@@ -24,7 +23,7 @@ databaseController.get = function (req, res, next) {
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -33,4 +32,4 @@ databaseController.get = function (req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = databaseController;
|
||||
module.exports = databaseController;
|
||||
|
||||
@@ -11,7 +11,7 @@ var errorsController = {};
|
||||
errorsController.get = function (req, res, next) {
|
||||
async.parallel({
|
||||
'not-found': async.apply(meta.errors.get, true),
|
||||
analytics: async.apply(analytics.getErrorAnalytics)
|
||||
analytics: async.apply(analytics.getErrorAnalytics),
|
||||
}, function (err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -24,7 +24,7 @@ errorsController.get = function (req, res, next) {
|
||||
errorsController.export = function (req, res, next) {
|
||||
async.waterfall([
|
||||
async.apply(meta.errors.get, false),
|
||||
async.apply(json2csv)
|
||||
async.apply(json2csv),
|
||||
], function (err, csv) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -35,4 +35,4 @@ errorsController.export = function (req, res, next) {
|
||||
};
|
||||
|
||||
|
||||
module.exports = errorsController;
|
||||
module.exports = errorsController;
|
||||
|
||||
@@ -10,7 +10,6 @@ var eventsController = {};
|
||||
|
||||
|
||||
eventsController.get = function (req, res, next) {
|
||||
|
||||
var page = parseInt(req.query.page, 10) || 1;
|
||||
var itemsPerPage = 20;
|
||||
var start = (page - 1) * itemsPerPage;
|
||||
@@ -22,7 +21,7 @@ eventsController.get = function (req, res, next) {
|
||||
},
|
||||
events: function (next) {
|
||||
events.getEvents(start, stop, next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -33,10 +32,10 @@ eventsController.get = function (req, res, next) {
|
||||
res.render('admin/advanced/events', {
|
||||
events: results.events,
|
||||
pagination: pagination.create(page, pageCount),
|
||||
next: 20
|
||||
next: 20,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
module.exports = eventsController;
|
||||
module.exports = eventsController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
@@ -6,12 +6,9 @@ var db = require('../../database');
|
||||
var groups = require('../../groups');
|
||||
var meta = require('../../meta');
|
||||
var pagination = require('../../pagination');
|
||||
var helpers = require('../helpers');
|
||||
|
||||
|
||||
var groupsController = {};
|
||||
|
||||
|
||||
groupsController.list = function (req, res, next) {
|
||||
var page = parseInt(req.query.page, 10) || 1;
|
||||
var groupsPerPage = 20;
|
||||
@@ -28,14 +25,14 @@ groupsController.list = function (req, res, next) {
|
||||
pageCount = Math.ceil(groupNames.length / groupsPerPage);
|
||||
|
||||
var start = (page - 1) * groupsPerPage;
|
||||
var stop = start + groupsPerPage - 1;
|
||||
var stop = start + groupsPerPage - 1;
|
||||
|
||||
groupNames = groupNames.slice(start, stop + 1);
|
||||
groups.getGroupsData(groupNames, next);
|
||||
},
|
||||
function (groupData, next) {
|
||||
next(null, {groups: groupData, pagination: pagination.create(page, pageCount)});
|
||||
}
|
||||
next(null, { groups: groupData, pagination: pagination.create(page, pageCount) });
|
||||
},
|
||||
], function (err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -44,7 +41,7 @@ groupsController.list = function (req, res, next) {
|
||||
res.render('admin/manage/groups', {
|
||||
groups: data.groups,
|
||||
pagination: data.pagination,
|
||||
yourid: req.uid
|
||||
yourid: req.uid,
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -59,14 +56,14 @@ groupsController.get = function (req, res, callback) {
|
||||
if (!exists) {
|
||||
return callback();
|
||||
}
|
||||
groups.get(groupName, {uid: req.uid, truncateUserList: true, userListCount: 20}, next);
|
||||
}
|
||||
groups.get(groupName, { uid: req.uid, truncateUserList: true, userListCount: 20 }, next);
|
||||
},
|
||||
], function (err, group) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
group.isOwner = true;
|
||||
res.render('admin/manage/group', {group: group, allowPrivateGroups: parseInt(meta.config.allowPrivateGroups, 10) === 1});
|
||||
res.render('admin/manage/group', { group: group, allowPrivateGroups: parseInt(meta.config.allowPrivateGroups, 10) === 1 });
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -25,37 +25,37 @@ homePageController.get = function (req, res, next) {
|
||||
categoryData = categoryData.map(function (category) {
|
||||
return {
|
||||
route: 'category/' + category.slug,
|
||||
name: 'Category: ' + category.name
|
||||
name: 'Category: ' + category.name,
|
||||
};
|
||||
});
|
||||
next(null, categoryData);
|
||||
}
|
||||
},
|
||||
], function (err, categoryData) {
|
||||
if (err || !categoryData) {
|
||||
categoryData = [];
|
||||
}
|
||||
|
||||
plugins.fireHook('filter:homepage.get', {routes: [
|
||||
plugins.fireHook('filter:homepage.get', { routes: [
|
||||
{
|
||||
route: 'categories',
|
||||
name: 'Categories'
|
||||
name: 'Categories',
|
||||
},
|
||||
{
|
||||
route: 'recent',
|
||||
name: 'Recent'
|
||||
name: 'Recent',
|
||||
},
|
||||
{
|
||||
route: 'popular',
|
||||
name: 'Popular'
|
||||
}
|
||||
].concat(categoryData)}, function (err, data) {
|
||||
name: 'Popular',
|
||||
},
|
||||
].concat(categoryData) }, function (err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
data.routes.push({
|
||||
route: '',
|
||||
name: 'Custom'
|
||||
name: 'Custom',
|
||||
});
|
||||
|
||||
res.render('admin/general/homepage', data);
|
||||
@@ -63,4 +63,4 @@ homePageController.get = function (req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = homePageController;
|
||||
module.exports = homePageController;
|
||||
|
||||
@@ -13,7 +13,7 @@ var infoController = {};
|
||||
|
||||
var info = {};
|
||||
|
||||
infoController.get = function (req, res, next) {
|
||||
infoController.get = function (req, res) {
|
||||
info = {};
|
||||
pubsub.publish('sync:node:info:start');
|
||||
setTimeout(function () {
|
||||
@@ -22,9 +22,15 @@ infoController.get = function (req, res, next) {
|
||||
data.push(info[key]);
|
||||
});
|
||||
data.sort(function (a, b) {
|
||||
return (a.os.hostname < b.os.hostname) ? -1 : (a.os.hostname > b.os.hostname) ? 1 : 0;
|
||||
if (a.os.hostname < b.os.hostname) {
|
||||
return -1;
|
||||
}
|
||||
if (a.os.hostname > b.os.hostname) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
res.render('admin/development/info', {info: data, infoJSON: JSON.stringify(data, null, 4), host: os.hostname(), port: nconf.get('port')});
|
||||
res.render('admin/development/info', { info: data, infoJSON: JSON.stringify(data, null, 4), host: os.hostname(), port: nconf.get('port') });
|
||||
}, 500);
|
||||
};
|
||||
|
||||
@@ -33,7 +39,7 @@ pubsub.on('sync:node:info:start', function () {
|
||||
if (err) {
|
||||
return winston.error(err);
|
||||
}
|
||||
pubsub.publish('sync:node:info:end', {data: data, id: os.hostname() + ':' + nconf.get('port')});
|
||||
pubsub.publish('sync:node:info:end', { data: data, id: os.hostname() + ':' + nconf.get('port') });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -49,7 +55,7 @@ function getNodeInfo(callback) {
|
||||
title: process.title,
|
||||
version: process.version,
|
||||
memoryUsage: process.memoryUsage(),
|
||||
uptime: process.uptime()
|
||||
uptime: process.uptime(),
|
||||
},
|
||||
os: {
|
||||
hostname: os.hostname(),
|
||||
@@ -57,8 +63,8 @@ function getNodeInfo(callback) {
|
||||
platform: os.platform(),
|
||||
arch: os.arch(),
|
||||
release: os.release(),
|
||||
load: os.loadavg().map(function (load) { return load.toFixed(2); }).join(', ')
|
||||
}
|
||||
load: os.loadavg().map(function (load) { return load.toFixed(2); }).join(', '),
|
||||
},
|
||||
};
|
||||
|
||||
async.parallel({
|
||||
@@ -67,7 +73,7 @@ function getNodeInfo(callback) {
|
||||
},
|
||||
gitInfo: function (next) {
|
||||
getGitInfo(next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -79,7 +85,7 @@ function getNodeInfo(callback) {
|
||||
}
|
||||
|
||||
function getGitInfo(callback) {
|
||||
function get(cmd, callback) {
|
||||
function get(cmd, callback) {
|
||||
exec(cmd, function (err, stdout) {
|
||||
if (err) {
|
||||
winston.error(err);
|
||||
@@ -93,8 +99,8 @@ function getGitInfo(callback) {
|
||||
},
|
||||
branch: function (next) {
|
||||
get('git rev-parse --abbrev-ref HEAD', next);
|
||||
}
|
||||
},
|
||||
}, callback);
|
||||
}
|
||||
|
||||
module.exports = infoController;
|
||||
module.exports = infoController;
|
||||
|
||||
@@ -17,9 +17,9 @@ languagesController.get = function (req, res, next) {
|
||||
});
|
||||
|
||||
res.render('admin/general/languages', {
|
||||
languages: languages
|
||||
languages: languages,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = languagesController;
|
||||
module.exports = languagesController;
|
||||
|
||||
@@ -6,4 +6,4 @@ loggerController.get = function (req, res) {
|
||||
res.render('admin/development/logger', {});
|
||||
};
|
||||
|
||||
module.exports = loggerController;
|
||||
module.exports = loggerController;
|
||||
|
||||
@@ -13,10 +13,10 @@ logsController.get = function (req, res, next) {
|
||||
}
|
||||
|
||||
res.render('admin/advanced/logs', {
|
||||
data: validator.escape(logs)
|
||||
data: validator.escape(logs),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
module.exports = logsController;
|
||||
module.exports = logsController;
|
||||
|
||||
@@ -20,4 +20,4 @@ navigationController.get = function (req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = navigationController;
|
||||
module.exports = navigationController;
|
||||
|
||||
@@ -24,22 +24,22 @@ pluginsController.get = function (req, res, next) {
|
||||
|
||||
next(null, plugins);
|
||||
});
|
||||
}
|
||||
},
|
||||
}, function (err, payload) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
var compatiblePkgNames = payload.compatible.map(function (pkgData) {
|
||||
return pkgData.name;
|
||||
});
|
||||
return pkgData.name;
|
||||
});
|
||||
|
||||
res.render('admin/extend/plugins' , {
|
||||
res.render('admin/extend/plugins', {
|
||||
installed: payload.compatible.filter(function (plugin) {
|
||||
return plugin.installed;
|
||||
}),
|
||||
upgradeCount: payload.compatible.reduce(function (count, current) {
|
||||
if (current.installed && current.outdated) {
|
||||
++count;
|
||||
count += 1;
|
||||
}
|
||||
return count;
|
||||
}, 0),
|
||||
@@ -48,9 +48,9 @@ pluginsController.get = function (req, res, next) {
|
||||
}),
|
||||
incompatible: payload.all.filter(function (plugin) {
|
||||
return compatiblePkgNames.indexOf(plugin.name) === -1;
|
||||
})
|
||||
}),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = pluginsController;
|
||||
module.exports = pluginsController;
|
||||
|
||||
@@ -13,5 +13,4 @@ rewardsController.get = function (req, res, next) {
|
||||
};
|
||||
|
||||
|
||||
|
||||
module.exports = rewardsController;
|
||||
module.exports = rewardsController;
|
||||
|
||||
@@ -11,12 +11,12 @@ settingsController.get = function (req, res, next) {
|
||||
var term = req.params.term ? req.params.term : 'general';
|
||||
|
||||
switch (req.params.term) {
|
||||
case 'email':
|
||||
renderEmail(req, res, next);
|
||||
break;
|
||||
case 'email':
|
||||
renderEmail(req, res, next);
|
||||
break;
|
||||
|
||||
default:
|
||||
res.render('admin/settings/' + term);
|
||||
default:
|
||||
res.render('admin/settings/' + term);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -47,11 +47,11 @@ function renderEmail(req, res, next) {
|
||||
path: path,
|
||||
fullpath: email,
|
||||
text: text,
|
||||
original: original.toString()
|
||||
original: original.toString(),
|
||||
});
|
||||
});
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
], function (err, emails) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -61,7 +61,7 @@ function renderEmail(req, res, next) {
|
||||
emails: emails,
|
||||
sendable: emails.filter(function (email) {
|
||||
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1;
|
||||
})
|
||||
}),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ socialController.get = function (req, res, next) {
|
||||
}
|
||||
|
||||
res.render('admin/general/social', {
|
||||
posts: posts
|
||||
posts: posts,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = socialController;
|
||||
module.exports = socialController;
|
||||
|
||||
@@ -10,7 +10,7 @@ soundsController.get = function (req, res, next) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
|
||||
settings = settings || {};
|
||||
|
||||
var types = [
|
||||
@@ -44,4 +44,4 @@ soundsController.get = function (req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = soundsController;
|
||||
module.exports = soundsController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var topics = require('../../topics');
|
||||
|
||||
@@ -10,7 +10,7 @@ tagsController.get = function (req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.render('admin/manage/tags', {tags: tags});
|
||||
res.render('admin/manage/tags', { tags: tags });
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ themesController.get = function (req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var themeConfig = require(path.join(themeDir, 'theme.json')),
|
||||
screenshotPath = path.join(themeDir, themeConfig.screenshot);
|
||||
var themeConfig = require(path.join(themeDir, 'theme.json'));
|
||||
var screenshotPath = path.join(themeDir, themeConfig.screenshot);
|
||||
if (themeConfig.screenshot && file.existsSync(screenshotPath)) {
|
||||
res.sendFile(screenshotPath);
|
||||
} else {
|
||||
@@ -22,4 +22,4 @@ themesController.get = function (req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = themesController;
|
||||
module.exports = themesController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
@@ -31,7 +31,7 @@ uploadsController.uploadCategoryPicture = function (req, res, next) {
|
||||
}
|
||||
|
||||
if (validateUpload(req, res, next, uploadedFile, allowedImageTypes)) {
|
||||
var filename = 'category-' + params.cid + path.extname(uploadedFile.name);
|
||||
var filename = 'category-' + params.cid + path.extname(uploadedFile.name);
|
||||
uploadImage(filename, 'category', uploadedFile, req, res, next);
|
||||
}
|
||||
};
|
||||
@@ -51,15 +51,15 @@ uploadsController.uploadFavicon = function (req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.json([{name: uploadedFile.name, url: image.url}]);
|
||||
res.json([{ name: uploadedFile.name, url: image.url }]);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
uploadsController.uploadTouchIcon = function (req, res, next) {
|
||||
var uploadedFile = req.files.files[0],
|
||||
allowedTypes = ['image/png'],
|
||||
sizes = [36, 48, 72, 96, 144, 192];
|
||||
var uploadedFile = req.files.files[0];
|
||||
var allowedTypes = ['image/png'];
|
||||
var sizes = [36, 48, 72, 96, 144, 192];
|
||||
|
||||
if (validateUpload(req, res, next, uploadedFile, allowedTypes)) {
|
||||
file.saveFileToLocal('touchicon-orig.png', 'system', uploadedFile.path, function (err, imageObj) {
|
||||
@@ -75,8 +75,8 @@ uploadsController.uploadTouchIcon = function (req, res, next) {
|
||||
path: path.join(nconf.get('upload_path'), 'system', 'touchicon-' + size + '.png'),
|
||||
extension: 'png',
|
||||
width: size,
|
||||
height: size
|
||||
})
|
||||
height: size,
|
||||
}),
|
||||
], next);
|
||||
}, function (err) {
|
||||
fs.unlink(uploadedFile.path, function (err) {
|
||||
@@ -89,7 +89,7 @@ uploadsController.uploadTouchIcon = function (req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.json([{name: uploadedFile.name, url: imageObj.url}]);
|
||||
res.json([{ name: uploadedFile.name, url: imageObj.url }]);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -142,7 +142,7 @@ function validateUpload(req, res, next, uploadedFile, allowedTypes) {
|
||||
}
|
||||
});
|
||||
|
||||
res.json({error: '[[error:invalid-image-type, ' + allowedTypes.join(', ') + ']]'});
|
||||
res.json({ error: '[[error:invalid-image-type, ' + allowedTypes.join(', ') + ']]' });
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -160,11 +160,11 @@ function uploadImage(filename, folder, uploadedFile, req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.json([{name: uploadedFile.name, url: image.url.startsWith('http') ? image.url : nconf.get('relative_path') + image.url}]);
|
||||
res.json([{ name: uploadedFile.name, url: image.url.startsWith('http') ? image.url : nconf.get('relative_path') + image.url }]);
|
||||
}
|
||||
|
||||
if (plugins.hasListeners('filter:uploadImage')) {
|
||||
plugins.fireHook('filter:uploadImage', {image: uploadedFile, uid: req.user.uid}, done);
|
||||
plugins.fireHook('filter:uploadImage', { image: uploadedFile, uid: req.user.uid }, done);
|
||||
} else {
|
||||
file.saveFileToLocal(filename, folder, uploadedFile.path, done);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var validator = require('validator');
|
||||
@@ -15,10 +15,10 @@ var usersController = {};
|
||||
var userFields = ['uid', 'username', 'userslug', 'email', 'postcount', 'joindate', 'banned',
|
||||
'reputation', 'picture', 'flags', 'lastonline', 'email:confirmed'];
|
||||
|
||||
usersController.search = function (req, res, next) {
|
||||
usersController.search = function (req, res) {
|
||||
res.render('admin/manage/users', {
|
||||
search_display: '',
|
||||
users: []
|
||||
users: [],
|
||||
});
|
||||
};
|
||||
|
||||
@@ -71,7 +71,7 @@ usersController.registrationQueue = function (req, res, next) {
|
||||
user.getRegistrationQueue(start, stop, next);
|
||||
},
|
||||
customHeaders: function (next) {
|
||||
plugins.fireHook('filter:admin.registrationQueue.customHeaders', {headers: []}, next);
|
||||
plugins.fireHook('filter:admin.registrationQueue.customHeaders', { headers: [] }, next);
|
||||
},
|
||||
invites: function (next) {
|
||||
async.waterfall([
|
||||
@@ -97,14 +97,14 @@ usersController.registrationQueue = function (req, res, next) {
|
||||
invites.invitations = invites.invitations.map(function (email, i) {
|
||||
return {
|
||||
email: email,
|
||||
username: usernames[index][i] === '[[global:guest]]' ? '' : usernames[index][i]
|
||||
username: usernames[index][i] === '[[global:guest]]' ? '' : usernames[index][i],
|
||||
};
|
||||
});
|
||||
});
|
||||
next(null, invitations);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
}
|
||||
},
|
||||
}, function (err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -146,9 +146,9 @@ function getUsers(set, section, min, max, req, res, next) {
|
||||
},
|
||||
function (uids, next) {
|
||||
user.getUsersWithFields(uids, userFields, req.uid, next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -161,7 +161,7 @@ function getUsers(set, section, min, max, req, res, next) {
|
||||
var data = {
|
||||
users: results.users,
|
||||
page: page,
|
||||
pageCount: Math.max(1, Math.ceil(results.count / resultsPerPage))
|
||||
pageCount: Math.max(1, Math.ceil(results.count / resultsPerPage)),
|
||||
};
|
||||
data[section] = true;
|
||||
render(req, res, data);
|
||||
@@ -185,7 +185,7 @@ usersController.getCSV = function (req, res, next) {
|
||||
events.log({
|
||||
type: 'getUsersCSV',
|
||||
uid: req.user.uid,
|
||||
ip: req.ip
|
||||
ip: req.ip,
|
||||
});
|
||||
|
||||
user.getUsersCSV(function (err, data) {
|
||||
|
||||
@@ -13,4 +13,4 @@ widgetsController.get = function (req, res, next) {
|
||||
};
|
||||
|
||||
|
||||
module.exports = widgetsController;
|
||||
module.exports = widgetsController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var validator = require('validator');
|
||||
@@ -71,7 +71,7 @@ apiController.getConfig = function (req, res, next) {
|
||||
enabled: parseInt(meta.config.cookieConsentEnabled, 10) === 1,
|
||||
message: translator.escape(meta.config.cookieConsentMessage || '[[global:cookies.message]]').replace(/\\/g, '\\\\'),
|
||||
dismiss: translator.escape(meta.config.cookieConsentDismiss || '[[global:cookies.accept]]').replace(/\\/g, '\\\\'),
|
||||
link: translator.escape(meta.config.cookieConsentLink || '[[global:cookies.learn_more]]').replace(/\\/g, '\\\\')
|
||||
link: translator.escape(meta.config.cookieConsentLink || '[[global:cookies.learn_more]]').replace(/\\/g, '\\\\'),
|
||||
};
|
||||
|
||||
async.waterfall([
|
||||
@@ -93,7 +93,7 @@ apiController.getConfig = function (req, res, next) {
|
||||
config.delayImageLoading = settings.delayImageLoading !== undefined ? settings.delayImageLoading : true;
|
||||
config.bootswatchSkin = settings.bootswatchSkin || config.bootswatchSkin;
|
||||
plugins.fireHook('filter:config.get', config, next);
|
||||
}
|
||||
},
|
||||
], function (err, config) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -119,16 +119,16 @@ apiController.renderWidgets = function (req, res, next) {
|
||||
url: req.query.url,
|
||||
locations: req.query.locations,
|
||||
isMobile: req.query.isMobile === 'true',
|
||||
cid: req.query.cid
|
||||
cid: req.query.cid,
|
||||
},
|
||||
req,
|
||||
res,
|
||||
function (err, widgets) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.status(200).json(widgets);
|
||||
});
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.status(200).json(widgets);
|
||||
});
|
||||
};
|
||||
|
||||
apiController.getPostData = function (pid, uid, callback) {
|
||||
@@ -138,7 +138,7 @@ apiController.getPostData = function (pid, uid, callback) {
|
||||
},
|
||||
post: function (next) {
|
||||
posts.getPostData(pid, next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err || !results.post) {
|
||||
return callback(err);
|
||||
@@ -167,7 +167,7 @@ apiController.getTopicData = function (tid, uid, callback) {
|
||||
},
|
||||
topic: function (next) {
|
||||
topics.getTopicData(tid, next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err || !results.topic) {
|
||||
return callback(err);
|
||||
@@ -187,7 +187,7 @@ apiController.getCategoryData = function (cid, uid, callback) {
|
||||
},
|
||||
category: function (next) {
|
||||
categories.getCategoryData(cid, next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err || !results.category) {
|
||||
return callback(err);
|
||||
@@ -205,7 +205,7 @@ apiController.getObject = function (req, res, next) {
|
||||
var methods = {
|
||||
post: apiController.getPostData,
|
||||
topic: apiController.getTopicData,
|
||||
category: apiController.getCategoryData
|
||||
category: apiController.getCategoryData,
|
||||
};
|
||||
var method = methods[req.params.type];
|
||||
if (!method) {
|
||||
@@ -230,7 +230,7 @@ apiController.getCurrentUser = function (req, res, next) {
|
||||
},
|
||||
function (userslug, next) {
|
||||
accountHelpers.getUserDataByUserSlug(userslug, req.uid, next);
|
||||
}
|
||||
},
|
||||
], function (err, userData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -278,7 +278,7 @@ apiController.getUserDataByField = function (callerUid, field, fieldValue, callb
|
||||
return next();
|
||||
}
|
||||
apiController.getUserDataByUID(callerUid, uid, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -293,7 +293,7 @@ apiController.getUserDataByUID = function (callerUid, uid, callback) {
|
||||
|
||||
async.parallel({
|
||||
userData: async.apply(user.getUserData, uid),
|
||||
settings: async.apply(user.getSettings, uid)
|
||||
settings: async.apply(user.getSettings, uid),
|
||||
}, function (err, results) {
|
||||
if (err || !results.userData) {
|
||||
return callback(err || new Error('[[error:no-user]]'));
|
||||
@@ -311,7 +311,7 @@ apiController.getModerators = function (req, res, next) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.json({moderators: moderators});
|
||||
res.json({ moderators: moderators });
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var winston = require('winston');
|
||||
@@ -6,7 +6,6 @@ var passport = require('passport');
|
||||
var nconf = require('nconf');
|
||||
var validator = require('validator');
|
||||
var _ = require('underscore');
|
||||
var url = require('url');
|
||||
|
||||
var db = require('../database');
|
||||
var meta = require('../meta');
|
||||
@@ -19,7 +18,7 @@ var sockets = require('../socket.io');
|
||||
|
||||
var authenticationController = {};
|
||||
|
||||
authenticationController.register = function (req, res, next) {
|
||||
authenticationController.register = function (req, res) {
|
||||
var registrationType = meta.config.registrationType || 'normal';
|
||||
|
||||
if (registrationType === 'disabled') {
|
||||
@@ -74,7 +73,7 @@ authenticationController.register = function (req, res, next) {
|
||||
},
|
||||
function (queue, next) {
|
||||
res.locals.processLogin = true; // set it to false in plugin if you wish to just register only
|
||||
plugins.fireHook('filter:register.check', {req: req, res: res, userData: userData, queue: queue}, next);
|
||||
plugins.fireHook('filter:register.check', { req: req, res: res, userData: userData, queue: queue }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
if (data.queue) {
|
||||
@@ -82,7 +81,7 @@ authenticationController.register = function (req, res, next) {
|
||||
} else {
|
||||
registerAndLoginUser(req, res, userData, next);
|
||||
}
|
||||
}
|
||||
},
|
||||
], function (err, data) {
|
||||
if (err) {
|
||||
return res.status(400).send(err.message);
|
||||
@@ -102,7 +101,7 @@ function registerAndLoginUser(req, res, userData, callback) {
|
||||
function (next) {
|
||||
plugins.fireHook('filter:register.interstitial', {
|
||||
userData: userData,
|
||||
interstitials: []
|
||||
interstitials: [],
|
||||
}, function (err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -113,11 +112,10 @@ function registerAndLoginUser(req, res, userData, callback) {
|
||||
|
||||
if (!deferRegistration) {
|
||||
return next();
|
||||
} else {
|
||||
userData.register = true;
|
||||
req.session.registration = userData;
|
||||
return res.json({ referrer: nconf.get('relative_path') + '/register/complete' });
|
||||
}
|
||||
userData.register = true;
|
||||
req.session.registration = userData;
|
||||
return res.json({ referrer: nconf.get('relative_path') + '/register/complete' });
|
||||
});
|
||||
},
|
||||
function (next) {
|
||||
@@ -133,8 +131,8 @@ function registerAndLoginUser(req, res, userData, callback) {
|
||||
},
|
||||
function (next) {
|
||||
user.deleteInvitationKey(userData.email);
|
||||
plugins.fireHook('filter:register.complete', {uid: uid, referrer: req.body.referrer || nconf.get('relative_path') + '/'}, next);
|
||||
}
|
||||
plugins.fireHook('filter:register.complete', { uid: uid, referrer: req.body.referrer || nconf.get('relative_path') + '/' }, next);
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -145,8 +143,8 @@ function addToApprovalQueue(req, userData, callback) {
|
||||
user.addToApprovalQueue(userData, next);
|
||||
},
|
||||
function (next) {
|
||||
next(null, {message: '[[register:registration-added-to-queue]]'});
|
||||
}
|
||||
next(null, { message: '[[register:registration-added-to-queue]]' });
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -154,7 +152,7 @@ authenticationController.registerComplete = function (req, res, next) {
|
||||
// For the interstitials that respond, execute the callback with the form body
|
||||
plugins.fireHook('filter:register.interstitial', {
|
||||
userData: req.session.registration,
|
||||
interstitials: []
|
||||
interstitials: [],
|
||||
}, function (err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -214,7 +212,7 @@ authenticationController.login = function (req, res, next) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
req.body.username = username ? username : req.body.username;
|
||||
req.body.username = username || req.body.username;
|
||||
continueLogin(req, res, next);
|
||||
});
|
||||
} else if (loginWith.indexOf('username') !== -1 && !validator.isEmail(req.body.username)) {
|
||||
@@ -284,7 +282,7 @@ authenticationController.doLogin = function (req, uid, callback) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
req.login({uid: uid}, function (err) {
|
||||
req.login({ uid: uid }, function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -310,7 +308,7 @@ authenticationController.onSuccessfulLogin = function (req, uid, callback) {
|
||||
datetime: Date.now(),
|
||||
platform: req.useragent.platform,
|
||||
browser: req.useragent.browser,
|
||||
version: req.useragent.version
|
||||
version: req.useragent.version,
|
||||
});
|
||||
|
||||
// Associate login session with user
|
||||
@@ -323,7 +321,7 @@ authenticationController.onSuccessfulLogin = function (req, uid, callback) {
|
||||
},
|
||||
function (next) {
|
||||
user.updateLastOnlineTime(uid, next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -343,7 +341,8 @@ authenticationController.localLogin = function (req, username, password, next) {
|
||||
}
|
||||
|
||||
var userslug = utils.slugify(username);
|
||||
var uid, userData = {};
|
||||
var uid;
|
||||
var userData = {};
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
@@ -369,7 +368,7 @@ authenticationController.localLogin = function (req, username, password, next) {
|
||||
},
|
||||
banned: function (next) {
|
||||
user.isBanned(uid, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (result, next) {
|
||||
@@ -408,7 +407,7 @@ authenticationController.localLogin = function (req, username, password, next) {
|
||||
}
|
||||
user.auth.clearLoginAttempts(uid);
|
||||
next(null, userData, '[[success:authentication-successful]]');
|
||||
}
|
||||
},
|
||||
], next);
|
||||
};
|
||||
|
||||
@@ -426,7 +425,7 @@ authenticationController.logout = function (req, res, next) {
|
||||
|
||||
user.setUserField(uid, 'lastonline', Date.now() - 300000);
|
||||
|
||||
plugins.fireHook('static:user.loggedOut', {req: req, res: res, uid: uid}, function () {
|
||||
plugins.fireHook('static:user.loggedOut', { req: req, res: res, uid: uid }, function () {
|
||||
res.status(200).send('');
|
||||
|
||||
// Force session check for all connected socket.io clients with the same session id
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
@@ -12,17 +12,17 @@ var categoriesController = {};
|
||||
|
||||
categoriesController.list = function (req, res, next) {
|
||||
res.locals.metaTags = [{
|
||||
name: "title",
|
||||
content: validator.escape(String(meta.config.title || 'NodeBB'))
|
||||
name: 'title',
|
||||
content: validator.escape(String(meta.config.title || 'NodeBB')),
|
||||
}, {
|
||||
name: "description",
|
||||
content: validator.escape(String(meta.config.description || ''))
|
||||
name: 'description',
|
||||
content: validator.escape(String(meta.config.description || '')),
|
||||
}, {
|
||||
property: 'og:title',
|
||||
content: '[[pages:categories]]'
|
||||
content: '[[pages:categories]]',
|
||||
}, {
|
||||
property: 'og:type',
|
||||
content: 'website'
|
||||
content: 'website',
|
||||
}];
|
||||
|
||||
var ogImage = meta.config['og:image'] || meta.config['brand:logo'] || '';
|
||||
@@ -32,7 +32,7 @@ categoriesController.list = function (req, res, next) {
|
||||
}
|
||||
res.locals.metaTags.push({
|
||||
property: 'og:image',
|
||||
content: ogImage
|
||||
content: ogImage,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ categoriesController.list = function (req, res, next) {
|
||||
categories.flattenCategories(allCategories, categoryData);
|
||||
|
||||
categories.getRecentTopicReplies(allCategories, req.uid, next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -56,11 +56,11 @@ categoriesController.list = function (req, res, next) {
|
||||
|
||||
var data = {
|
||||
title: '[[pages:categories]]',
|
||||
categories: categoryData
|
||||
categories: categoryData,
|
||||
};
|
||||
|
||||
if (req.path.startsWith('/api/categories') || req.path.startsWith('/categories')) {
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs([{text: data.title}]);
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: data.title }]);
|
||||
}
|
||||
|
||||
data.categories.forEach(function (category) {
|
||||
@@ -68,7 +68,7 @@ categoriesController.list = function (req, res, next) {
|
||||
category.teaser = {
|
||||
url: nconf.get('relative_path') + '/topic/' + category.posts[0].topic.slug + '/' + category.posts[0].index,
|
||||
timestampISO: category.posts[0].timestampISO,
|
||||
pid: category.posts[0].pid
|
||||
pid: category.posts[0].pid,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
|
||||
var async = require('async');
|
||||
@@ -37,7 +37,7 @@ categoryController.get = function (req, res, callback) {
|
||||
},
|
||||
userSettings: function (next) {
|
||||
user.getSettings(req.uid, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -87,7 +87,7 @@ categoryController.get = function (req, res, callback) {
|
||||
set = 'cid:' + cid + ':tids:posts';
|
||||
}
|
||||
|
||||
var start = (currentPage - 1) * settings.topicsPerPage + topicIndex;
|
||||
var start = ((currentPage - 1) * settings.topicsPerPage) + topicIndex;
|
||||
var stop = start + settings.topicsPerPage - 1;
|
||||
|
||||
var payload = {
|
||||
@@ -97,7 +97,7 @@ categoryController.get = function (req, res, callback) {
|
||||
start: start,
|
||||
stop: stop,
|
||||
uid: req.uid,
|
||||
settings: settings
|
||||
settings: settings,
|
||||
};
|
||||
|
||||
async.waterfall([
|
||||
@@ -120,11 +120,10 @@ categoryController.get = function (req, res, callback) {
|
||||
}
|
||||
}
|
||||
categories.getCategoryById(payload, next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
},
|
||||
function (categoryData, next) {
|
||||
|
||||
categories.modifyTopicsByPrivilege(categoryData.topics, userPrivileges);
|
||||
|
||||
if (categoryData.link) {
|
||||
@@ -135,8 +134,8 @@ categoryController.get = function (req, res, callback) {
|
||||
var breadcrumbs = [
|
||||
{
|
||||
text: categoryData.name,
|
||||
url: nconf.get('relative_path') + '/category/' + categoryData.slug
|
||||
}
|
||||
url: nconf.get('relative_path') + '/category/' + categoryData.slug,
|
||||
},
|
||||
];
|
||||
helpers.buildCategoryBreadcrumbs(categoryData.parentCid, function (err, crumbs) {
|
||||
if (err) {
|
||||
@@ -155,7 +154,7 @@ categoryController.get = function (req, res, callback) {
|
||||
categories.getRecentTopicReplies(allCategories, req.uid, function (err) {
|
||||
next(err, categoryData);
|
||||
});
|
||||
}
|
||||
},
|
||||
], function (err, categoryData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -167,26 +166,26 @@ categoryController.get = function (req, res, callback) {
|
||||
res.locals.metaTags = [
|
||||
{
|
||||
name: 'title',
|
||||
content: categoryData.name
|
||||
content: categoryData.name,
|
||||
},
|
||||
{
|
||||
property: 'og:title',
|
||||
content: categoryData.name
|
||||
content: categoryData.name,
|
||||
},
|
||||
{
|
||||
name: 'description',
|
||||
content: categoryData.description
|
||||
content: categoryData.description,
|
||||
},
|
||||
{
|
||||
property: "og:type",
|
||||
content: 'website'
|
||||
}
|
||||
property: 'og:type',
|
||||
content: 'website',
|
||||
},
|
||||
];
|
||||
|
||||
if (categoryData.backgroundImage) {
|
||||
res.locals.metaTags.push({
|
||||
name: 'og:image',
|
||||
content: categoryData.backgroundImage
|
||||
content: categoryData.backgroundImage,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -194,12 +193,12 @@ categoryController.get = function (req, res, callback) {
|
||||
{
|
||||
rel: 'alternate',
|
||||
type: 'application/rss+xml',
|
||||
href: nconf.get('url') + '/category/' + cid + '.rss'
|
||||
href: nconf.get('url') + '/category/' + cid + '.rss',
|
||||
},
|
||||
{
|
||||
rel: 'up',
|
||||
href: nconf.get('url')
|
||||
}
|
||||
href: nconf.get('url'),
|
||||
},
|
||||
];
|
||||
|
||||
if (parseInt(req.uid, 10)) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var user = require('../user');
|
||||
var adminBlacklistController = require('./admin/blacklist');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
@@ -19,7 +19,7 @@ groupsController.list = function (req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
data.title = '[[pages:groups]]';
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[pages:groups]]'}]);
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[pages:groups]]' }]);
|
||||
res.render('groups/list', data);
|
||||
});
|
||||
};
|
||||
@@ -32,17 +32,18 @@ groupsController.getGroupsFromSet = function (uid, sort, start, stop, callback)
|
||||
set = 'groups:visible:createtime';
|
||||
}
|
||||
|
||||
groups.getGroupsFromSet(set, uid, start, stop, function (err, groups) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null, {
|
||||
groups: groups,
|
||||
allowGroupCreation: parseInt(meta.config.allowGroupCreation, 10) === 1,
|
||||
nextStart: stop + 1
|
||||
});
|
||||
});
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
groups.getGroupsFromSet(set, uid, start, stop, next);
|
||||
},
|
||||
function (groupsData, next) {
|
||||
next(null, {
|
||||
groups: groupsData,
|
||||
allowGroupCreation: parseInt(meta.config.allowGroupCreation, 10) === 1,
|
||||
nextStart: stop + 1,
|
||||
});
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
groupsController.details = function (req, res, callback) {
|
||||
@@ -58,7 +59,7 @@ groupsController.details = function (req, res, callback) {
|
||||
}
|
||||
async.parallel({
|
||||
exists: async.apply(groups.exists, groupName),
|
||||
hidden: async.apply(groups.isHidden, groupName)
|
||||
hidden: async.apply(groups.isHidden, groupName),
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -70,7 +71,7 @@ groupsController.details = function (req, res, callback) {
|
||||
}
|
||||
async.parallel({
|
||||
isMember: async.apply(groups.isMember, req.uid, groupName),
|
||||
isInvited: async.apply(groups.isInvited, req.uid, groupName)
|
||||
isInvited: async.apply(groups.isInvited, req.uid, groupName),
|
||||
}, function (err, checks) {
|
||||
if (err || checks.isMember || checks.isInvited) {
|
||||
return next(err);
|
||||
@@ -84,20 +85,20 @@ groupsController.details = function (req, res, callback) {
|
||||
groups.get(groupName, {
|
||||
uid: req.uid,
|
||||
truncateUserList: true,
|
||||
userListCount: 20
|
||||
userListCount: 20,
|
||||
}, next);
|
||||
},
|
||||
posts: function (next) {
|
||||
groups.getLatestMemberPosts(groupName, 10, req.uid, next);
|
||||
},
|
||||
isAdmin:function (next) {
|
||||
isAdmin: function (next) {
|
||||
user.isAdministrator(req.uid, next);
|
||||
},
|
||||
isGlobalMod: function (next) {
|
||||
user.isGlobalModerator(req.uid, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
], function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -108,7 +109,7 @@ groupsController.details = function (req, res, callback) {
|
||||
}
|
||||
results.group.isOwner = results.group.isOwner || results.isAdmin || (results.isGlobalMod && !results.group.system);
|
||||
results.title = '[[pages:group, ' + results.group.displayName + ']]';
|
||||
results.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[pages:groups]]', url: '/groups' }, {text: results.group.displayName}]);
|
||||
results.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[pages:groups]]', url: '/groups' }, { text: results.group.displayName }]);
|
||||
results.allowPrivateGroups = parseInt(meta.config.allowPrivateGroups, 10) === 1;
|
||||
|
||||
res.render('groups/details', results);
|
||||
@@ -129,7 +130,7 @@ groupsController.members = function (req, res, callback) {
|
||||
async.parallel({
|
||||
isAdminOrGlobalMod: async.apply(user.isAdminOrGlobalMod, req.uid),
|
||||
isMember: async.apply(groups.isMember, req.uid, groupName),
|
||||
isHidden: async.apply(groups.isHidden, groupName)
|
||||
isHidden: async.apply(groups.isHidden, groupName),
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -145,16 +146,16 @@ groupsController.members = function (req, res, callback) {
|
||||
}
|
||||
|
||||
var breadcrumbs = helpers.buildBreadcrumbs([
|
||||
{text: '[[pages:groups]]', url: '/groups' },
|
||||
{text: validator.escape(String(groupName)), url: '/groups/' + req.params.slug},
|
||||
{text: '[[groups:details.members]]'}
|
||||
{ text: '[[pages:groups]]', url: '/groups' },
|
||||
{ text: validator.escape(String(groupName)), url: '/groups/' + req.params.slug },
|
||||
{ text: '[[groups:details.members]]' },
|
||||
]);
|
||||
|
||||
res.render('groups/members', {
|
||||
users: users,
|
||||
nextStart: 50,
|
||||
loadmore_display: users.length > 50 ? 'block' : 'hide',
|
||||
breadcrumbs: breadcrumbs
|
||||
breadcrumbs: breadcrumbs,
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -173,14 +174,14 @@ groupsController.uploadCover = function (req, res, next) {
|
||||
|
||||
groups.updateCover(req.uid, {
|
||||
file: req.files.files[0].path,
|
||||
groupName: params.groupName
|
||||
groupName: params.groupName,
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
], function (err, image) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.json([{url: image.url.startsWith('http') ? image.url : nconf.get('relative_path') + image.url}]);
|
||||
res.json([{ url: image.url.startsWith('http') ? image.url : nconf.get('relative_path') + image.url }]);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ helpers.notAllowed = function (req, res, error) {
|
||||
plugins.fireHook('filter:helpers.notAllowed', {
|
||||
req: req,
|
||||
res: res,
|
||||
error: error
|
||||
}, function (err, data) {
|
||||
error: error,
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
return winston.error(err);
|
||||
}
|
||||
@@ -28,24 +28,22 @@ helpers.notAllowed = function (req, res, error) {
|
||||
path: req.path.replace(/^\/api/, ''),
|
||||
loggedIn: !!req.uid,
|
||||
error: error,
|
||||
title: '[[global:403.title]]'
|
||||
title: '[[global:403.title]]',
|
||||
});
|
||||
} else {
|
||||
res.status(403).render('403', {
|
||||
path: req.path,
|
||||
loggedIn: !!req.uid,
|
||||
error: error,
|
||||
title: '[[global:403.title]]'
|
||||
title: '[[global:403.title]]',
|
||||
});
|
||||
}
|
||||
} else if (res.locals.isAPI) {
|
||||
req.session.returnTo = nconf.get('relative_path') + req.url.replace(/^\/api/, '');
|
||||
res.status(401).json('not-authorized');
|
||||
} else {
|
||||
if (res.locals.isAPI) {
|
||||
req.session.returnTo = nconf.get('relative_path') + req.url.replace(/^\/api/, '');
|
||||
res.status(401).json('not-authorized');
|
||||
} else {
|
||||
req.session.returnTo = nconf.get('relative_path') + req.url;
|
||||
res.redirect(nconf.get('relative_path') + '/login');
|
||||
}
|
||||
req.session.returnTo = nconf.get('relative_path') + req.url;
|
||||
res.redirect(nconf.get('relative_path') + '/login');
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -72,7 +70,7 @@ helpers.buildCategoryBreadcrumbs = function (cid, callback) {
|
||||
if (!parseInt(data.disabled, 10)) {
|
||||
breadcrumbs.unshift({
|
||||
text: validator.escape(String(data.name)),
|
||||
url: nconf.get('relative_path') + '/category/' + data.slug
|
||||
url: nconf.get('relative_path') + '/category/' + data.slug,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -87,13 +85,13 @@ helpers.buildCategoryBreadcrumbs = function (cid, callback) {
|
||||
if (!meta.config.homePageRoute && meta.config.homePageCustom) {
|
||||
breadcrumbs.unshift({
|
||||
text: '[[global:header.categories]]',
|
||||
url: nconf.get('relative_path') + '/categories'
|
||||
url: nconf.get('relative_path') + '/categories',
|
||||
});
|
||||
}
|
||||
|
||||
breadcrumbs.unshift({
|
||||
text: '[[global:home]]',
|
||||
url: nconf.get('relative_path') + '/'
|
||||
url: nconf.get('relative_path') + '/',
|
||||
});
|
||||
|
||||
callback(null, breadcrumbs);
|
||||
@@ -104,8 +102,8 @@ helpers.buildBreadcrumbs = function (crumbs) {
|
||||
var breadcrumbs = [
|
||||
{
|
||||
text: '[[global:home]]',
|
||||
url: nconf.get('relative_path') + '/'
|
||||
}
|
||||
url: nconf.get('relative_path') + '/',
|
||||
},
|
||||
];
|
||||
|
||||
crumbs.forEach(function (crumb) {
|
||||
@@ -164,8 +162,8 @@ helpers.getWatchedCategories = function (uid, selectedCid, callback) {
|
||||
recursive(category, categoriesData, '');
|
||||
});
|
||||
|
||||
next(null, {categories: categoriesData, selectedCategory: selectedCategory});
|
||||
}
|
||||
next(null, { categories: categoriesData, selectedCategory: selectedCategory });
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
@@ -28,7 +28,7 @@ var Controllers = {
|
||||
admin: require('./admin'),
|
||||
globalMods: require('./globalmods'),
|
||||
mods: require('./mods'),
|
||||
sitemap: require('./sitemap')
|
||||
sitemap: require('./sitemap'),
|
||||
};
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ Controllers.home = function (req, res, next) {
|
||||
var hook = 'action:homepage.get:' + route;
|
||||
|
||||
if (plugins.hasListeners(hook)) {
|
||||
return plugins.fireHook(hook, {req: req, res: res, next: next});
|
||||
return plugins.fireHook(hook, { req: req, res: res, next: next });
|
||||
}
|
||||
|
||||
if (route === 'categories' || route === '/') {
|
||||
@@ -61,7 +61,7 @@ Controllers.home = function (req, res, next) {
|
||||
var match = /^category\/(\d+)\/(.*)$/.exec(route);
|
||||
|
||||
if (match) {
|
||||
req.params.topic_index = "1";
|
||||
req.params.topic_index = '1';
|
||||
req.params.category_id = match[1];
|
||||
req.params.slug = match[2];
|
||||
Controllers.category.get(req, res, next);
|
||||
@@ -83,8 +83,8 @@ Controllers.reset = function (req, res, next) {
|
||||
displayExpiryNotice: req.session.passwordExpired,
|
||||
code: req.params.code,
|
||||
minimumPasswordLength: parseInt(meta.config.minimumPasswordLength, 10),
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[reset_password:reset_password]]', url: '/reset'}, {text: '[[reset_password:update_password]]'}]),
|
||||
title: '[[pages:reset]]'
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{ text: '[[reset_password:reset_password]]', url: '/reset' }, { text: '[[reset_password:update_password]]' }]),
|
||||
title: '[[pages:reset]]',
|
||||
});
|
||||
|
||||
delete req.session.passwordExpired;
|
||||
@@ -92,8 +92,8 @@ Controllers.reset = function (req, res, next) {
|
||||
} else {
|
||||
res.render('reset', {
|
||||
code: null,
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[reset_password:reset_password]]'}]),
|
||||
title: '[[pages:reset]]'
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{ text: '[[reset_password:reset_password]]' }]),
|
||||
title: '[[pages:reset]]',
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -122,18 +122,17 @@ Controllers.login = function (req, res, next) {
|
||||
data.allowLocalLogin = parseInt(meta.config.allowLocalLogin, 10) === 1 || parseInt(req.query.local, 10) === 1;
|
||||
data.allowRegistration = registrationType === 'normal' || registrationType === 'admin-approval' || registrationType === 'admin-approval-ip';
|
||||
data.allowLoginWith = '[[login:' + allowLoginWith + ']]';
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:login]]'}]);
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[global:login]]' }]);
|
||||
data.error = req.flash('error')[0] || errorText;
|
||||
data.title = '[[pages:login]]';
|
||||
|
||||
if (!data.allowLocalLogin && !data.allowRegistration && data.alternate_logins && data.authentication.length === 1) {
|
||||
if (res.locals.isAPI) {
|
||||
return helpers.redirect(res, {
|
||||
external: data.authentication[0].url
|
||||
external: data.authentication[0].url,
|
||||
});
|
||||
} else {
|
||||
return res.redirect(nconf.get('relative_path') + data.authentication[0].url);
|
||||
}
|
||||
return res.redirect(nconf.get('relative_path') + data.authentication[0].url);
|
||||
}
|
||||
if (req.uid) {
|
||||
user.getUserFields(req.uid, ['username', 'email'], function (err, user) {
|
||||
@@ -147,7 +146,6 @@ Controllers.login = function (req, res, next) {
|
||||
} else {
|
||||
res.render('login', data);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Controllers.register = function (req, res, next) {
|
||||
@@ -171,8 +169,8 @@ Controllers.register = function (req, res, next) {
|
||||
}
|
||||
},
|
||||
function (next) {
|
||||
plugins.fireHook('filter:parse.post', {postData: {content: meta.config.termsOfUse || ''}}, next);
|
||||
}
|
||||
plugins.fireHook('filter:parse.post', { postData: { content: meta.config.termsOfUse || '' } }, next);
|
||||
},
|
||||
], function (err, termsOfUse) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -180,7 +178,7 @@ Controllers.register = function (req, res, next) {
|
||||
var loginStrategies = require('../routes/authentication').getLoginStrategies();
|
||||
var data = {
|
||||
'register_window:spansize': loginStrategies.length ? 'col-md-6' : 'col-md-12',
|
||||
'alternate_logins': !!loginStrategies.length
|
||||
alternate_logins: !!loginStrategies.length,
|
||||
};
|
||||
|
||||
data.authentication = loginStrategies;
|
||||
@@ -189,7 +187,7 @@ Controllers.register = function (req, res, next) {
|
||||
data.maximumUsernameLength = parseInt(meta.config.maximumUsernameLength, 10);
|
||||
data.minimumPasswordLength = parseInt(meta.config.minimumPasswordLength, 10);
|
||||
data.termsOfUse = termsOfUse.postData.content;
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[register:register]]'}]);
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[register:register]]' }]);
|
||||
data.regFormEntry = [];
|
||||
data.error = req.flash('error')[0] || errorText;
|
||||
data.title = '[[pages:register]]';
|
||||
@@ -205,7 +203,7 @@ Controllers.registerInterstitial = function (req, res, next) {
|
||||
|
||||
plugins.fireHook('filter:register.interstitial', {
|
||||
userData: req.session.registration,
|
||||
interstitials: []
|
||||
interstitials: [],
|
||||
}, function (err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -230,7 +228,7 @@ Controllers.registerInterstitial = function (req, res, next) {
|
||||
res.render('registerComplete', {
|
||||
title: '[[pages:registration-complete]]',
|
||||
errors: errors,
|
||||
sections: sections
|
||||
sections: sections,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -241,7 +239,7 @@ Controllers.compose = function (req, res, next) {
|
||||
req: req,
|
||||
res: res,
|
||||
next: next,
|
||||
templateData: {}
|
||||
templateData: {},
|
||||
}, function (err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -249,7 +247,7 @@ Controllers.compose = function (req, res, next) {
|
||||
|
||||
if (data.templateData.disabled) {
|
||||
res.render('', {
|
||||
title: '[[modules:composer.compose]]'
|
||||
title: '[[modules:composer.compose]]',
|
||||
});
|
||||
} else {
|
||||
data.templateData.title = '[[modules:composer.compose]]';
|
||||
@@ -270,12 +268,12 @@ Controllers.confirmEmail = function (req, res) {
|
||||
Controllers.robots = function (req, res) {
|
||||
res.set('Content-Type', 'text/plain');
|
||||
|
||||
if (meta.config["robots.txt"]) {
|
||||
res.send(meta.config["robots.txt"]);
|
||||
if (meta.config['robots.txt']) {
|
||||
res.send(meta.config['robots.txt']);
|
||||
} else {
|
||||
res.send("User-agent: *\n" +
|
||||
"Disallow: " + nconf.get('relative_path') + "/admin/\n" +
|
||||
"Sitemap: " + nconf.get('url') + "/sitemap.xml");
|
||||
res.send('User-agent: *\n' +
|
||||
'Disallow: ' + nconf.get('relative_path') + '/admin/\n' +
|
||||
'Sitemap: ' + nconf.get('url') + '/sitemap.xml');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -285,7 +283,7 @@ Controllers.manifest = function (req, res) {
|
||||
start_url: nconf.get('relative_path') + '/',
|
||||
display: 'standalone',
|
||||
orientation: 'portrait',
|
||||
icons: []
|
||||
icons: [],
|
||||
};
|
||||
|
||||
if (meta.config['brand:touchIcon']) {
|
||||
@@ -293,32 +291,32 @@ Controllers.manifest = function (req, res) {
|
||||
src: nconf.get('relative_path') + '/assets/uploads/system/touchicon-36.png',
|
||||
sizes: '36x36',
|
||||
type: 'image/png',
|
||||
density: 0.75
|
||||
density: 0.75,
|
||||
}, {
|
||||
src: nconf.get('relative_path') + '/assets/uploads/system/touchicon-48.png',
|
||||
sizes: '48x48',
|
||||
type: 'image/png',
|
||||
density: 1.0
|
||||
density: 1.0,
|
||||
}, {
|
||||
src: nconf.get('relative_path') + '/assets/uploads/system/touchicon-72.png',
|
||||
sizes: '72x72',
|
||||
type: 'image/png',
|
||||
density: 1.5
|
||||
density: 1.5,
|
||||
}, {
|
||||
src: nconf.get('relative_path') + '/assets/uploads/system/touchicon-96.png',
|
||||
sizes: '96x96',
|
||||
type: 'image/png',
|
||||
density: 2.0
|
||||
density: 2.0,
|
||||
}, {
|
||||
src: nconf.get('relative_path') + '/assets/uploads/system/touchicon-144.png',
|
||||
sizes: '144x144',
|
||||
type: 'image/png',
|
||||
density: 3.0
|
||||
density: 3.0,
|
||||
}, {
|
||||
src: nconf.get('relative_path') + '/assets/uploads/system/touchicon-192.png',
|
||||
sizes: '192x192',
|
||||
type: 'image/png',
|
||||
density: 4.0
|
||||
density: 4.0,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -330,7 +328,7 @@ Controllers.outgoing = function (req, res) {
|
||||
var data = {
|
||||
outgoing: validator.escape(String(url)),
|
||||
title: meta.config.title,
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[notifications:outgoing_link]]'}])
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{ text: '[[notifications:outgoing_link]]' }]),
|
||||
};
|
||||
|
||||
if (url) {
|
||||
@@ -344,7 +342,7 @@ Controllers.termsOfUse = function (req, res, next) {
|
||||
if (!meta.config.termsOfUse) {
|
||||
return next();
|
||||
}
|
||||
res.render('tos', {termsOfUse: meta.config.termsOfUse});
|
||||
res.render('tos', { termsOfUse: meta.config.termsOfUse });
|
||||
};
|
||||
|
||||
Controllers.ping = function (req, res) {
|
||||
@@ -359,7 +357,7 @@ Controllers.handle404 = function (req, res) {
|
||||
return plugins.fireHook('action:meta.override404', {
|
||||
req: req,
|
||||
res: res,
|
||||
error: {}
|
||||
error: {},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -379,11 +377,11 @@ Controllers.handle404 = function (req, res) {
|
||||
var path = String(req.path || '');
|
||||
|
||||
if (res.locals.isAPI) {
|
||||
return res.json({path: validator.escape(path.replace(/^\/api/, '')), title: '[[global:404.title]]'});
|
||||
return res.json({ path: validator.escape(path.replace(/^\/api/, '')), title: '[[global:404.title]]' });
|
||||
}
|
||||
var middleware = require('../middleware');
|
||||
middleware.buildHeader(req, res, function () {
|
||||
res.render('404', {path: validator.escape(path), title: '[[global:404.title]]'});
|
||||
res.render('404', { path: validator.escape(path), title: '[[global:404.title]]' });
|
||||
});
|
||||
} else {
|
||||
res.status(404).type('txt').send('Not found');
|
||||
@@ -404,7 +402,7 @@ Controllers.handleURIErrors = function (err, req, res, next) {
|
||||
winston.warn('[controller] Bad request: ' + req.path);
|
||||
if (res.locals.isAPI) {
|
||||
res.status(400).json({
|
||||
error: '[[global:400.title]]'
|
||||
error: '[[global:400.title]]',
|
||||
});
|
||||
} else {
|
||||
var middleware = require('../middleware');
|
||||
@@ -413,20 +411,20 @@ Controllers.handleURIErrors = function (err, req, res, next) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
} else {
|
||||
next(err);
|
||||
}
|
||||
};
|
||||
|
||||
Controllers.handleErrors = function (err, req, res, next) {
|
||||
// this needs to have four arguments or express treats it as `(req, res, next)`
|
||||
// don't remove `next`!
|
||||
Controllers.handleErrors = function (err, req, res, next) { // eslint-disable-line no-unused-vars
|
||||
switch (err.code) {
|
||||
case 'EBADCSRFTOKEN':
|
||||
winston.error(req.path + '\n', err.message);
|
||||
return res.sendStatus(403);
|
||||
case 'blacklisted-ip':
|
||||
return res.status(403).type('text/plain').send(err.message);
|
||||
case 'EBADCSRFTOKEN':
|
||||
winston.error(req.path + '\n', err.message);
|
||||
return res.sendStatus(403);
|
||||
case 'blacklisted-ip':
|
||||
return res.status(403).type('text/plain').send(err.message);
|
||||
}
|
||||
|
||||
if (parseInt(err.status, 10) === 302 && err.path) {
|
||||
@@ -439,7 +437,7 @@ Controllers.handleErrors = function (err, req, res, next) {
|
||||
|
||||
var path = String(req.path || '');
|
||||
if (res.locals.isAPI) {
|
||||
res.json({path: validator.escape(path), error: err.message});
|
||||
res.json({ path: validator.escape(path), error: err.message });
|
||||
} else {
|
||||
var middleware = require('../middleware');
|
||||
middleware.buildHeader(req, res, function () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
@@ -14,7 +14,7 @@ var modsController = {
|
||||
modsController.flags.list = function (req, res, next) {
|
||||
async.parallel({
|
||||
isAdminOrGlobalMod: async.apply(user.isAdminOrGlobalMod, req.uid),
|
||||
moderatedCids: async.apply(user.getModeratedCids, req.uid)
|
||||
moderatedCids: async.apply(user.getModeratedCids, req.uid),
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
|
||||
@@ -14,11 +14,10 @@ var lastUpdateTime = 0;
|
||||
var terms = {
|
||||
daily: 'day',
|
||||
weekly: 'week',
|
||||
monthly: 'month'
|
||||
monthly: 'month',
|
||||
};
|
||||
|
||||
popularController.get = function (req, res, next) {
|
||||
|
||||
var term = terms[req.params.term];
|
||||
|
||||
if (!term && req.params.term) {
|
||||
@@ -30,7 +29,7 @@ popularController.get = function (req, res, next) {
|
||||
day: '[[recent:day]]',
|
||||
week: '[[recent:week]]',
|
||||
month: '[[recent:month]]',
|
||||
alltime: '[[global:header.popular]]'
|
||||
alltime: '[[global:header.popular]]',
|
||||
};
|
||||
|
||||
if (!req.uid) {
|
||||
@@ -49,14 +48,14 @@ popularController.get = function (req, res, next) {
|
||||
'feeds:disableRSS': parseInt(meta.config['feeds:disableRSS'], 10) === 1,
|
||||
rssFeedUrl: nconf.get('relative_path') + '/popular/' + (req.params.term || 'daily') + '.rss',
|
||||
title: '[[pages:popular-' + term + ']]',
|
||||
term: term
|
||||
term: term,
|
||||
};
|
||||
|
||||
if (req.path.startsWith('/api/popular') || req.path.startsWith('/popular')) {
|
||||
var breadcrumbs = [{text: termToBreadcrumb[term]}];
|
||||
var breadcrumbs = [{ text: termToBreadcrumb[term] }];
|
||||
|
||||
if (req.params.term) {
|
||||
breadcrumbs.unshift({text: '[[global:header.popular]]', url: '/popular'});
|
||||
breadcrumbs.unshift({ text: '[[global:header.popular]]', url: '/popular' });
|
||||
}
|
||||
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs(breadcrumbs);
|
||||
@@ -71,4 +70,4 @@ popularController.get = function (req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = popularController;
|
||||
module.exports = popularController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var posts = require('../posts');
|
||||
var helpers = require('./helpers');
|
||||
|
||||
@@ -13,7 +13,7 @@ var pagination = require('../pagination');
|
||||
|
||||
var recentController = {};
|
||||
|
||||
var validFilter = {'': true, 'new': true, 'watched': true};
|
||||
var validFilter = { '': true, new: true, watched: true };
|
||||
|
||||
recentController.get = function (req, res, next) {
|
||||
var page = parseInt(req.query.page, 10) || 1;
|
||||
@@ -35,7 +35,7 @@ recentController.get = function (req, res, next) {
|
||||
},
|
||||
watchedCategories: function (next) {
|
||||
helpers.getWatchedCategories(req.uid, cid, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -46,7 +46,7 @@ recentController.get = function (req, res, next) {
|
||||
stop = start + settings.topicsPerPage - 1;
|
||||
|
||||
topics.getRecentTopics(cid, req.uid, start, stop, filter, next);
|
||||
}
|
||||
},
|
||||
], function (err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -63,17 +63,17 @@ recentController.get = function (req, res, next) {
|
||||
name: '[[unread:all-topics]]',
|
||||
url: 'recent',
|
||||
selected: filter === '',
|
||||
filter: ''
|
||||
filter: '',
|
||||
}, {
|
||||
name: '[[unread:new-topics]]',
|
||||
url: 'recent/new',
|
||||
selected: filter === 'new',
|
||||
filter: 'new'
|
||||
filter: 'new',
|
||||
}, {
|
||||
name: '[[unread:watched-topics]]',
|
||||
url: 'recent/watched',
|
||||
selected: filter === 'watched',
|
||||
filter: 'watched'
|
||||
filter: 'watched',
|
||||
}];
|
||||
|
||||
data.selectedFilter = data.filters.find(function (filter) {
|
||||
@@ -84,7 +84,7 @@ recentController.get = function (req, res, next) {
|
||||
data.pagination = pagination.create(page, pageCount, req.query);
|
||||
|
||||
if (req.path.startsWith('/api/recent') || req.path.startsWith('/recent')) {
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[recent:title]]'}]);
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[recent:title]]' }]);
|
||||
}
|
||||
|
||||
data.querystring = cid ? ('?cid=' + validator.escape(String(cid))) : '';
|
||||
@@ -92,4 +92,4 @@ recentController.get = function (req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = recentController;
|
||||
module.exports = recentController;
|
||||
|
||||
@@ -42,20 +42,20 @@ searchController.search = function (req, res, next) {
|
||||
sortDirection: req.query.sortDirection,
|
||||
page: page,
|
||||
uid: req.uid,
|
||||
qs: req.query
|
||||
qs: req.query,
|
||||
};
|
||||
|
||||
async.parallel({
|
||||
categories: async.apply(categories.buildForSelect, req.uid),
|
||||
search: async.apply(search.search, data)
|
||||
search: async.apply(search.search, data),
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var categoriesData = [
|
||||
{value: 'all', text: '[[unread:all_categories]]'},
|
||||
{value: 'watched', text: '[[category:watched-categories]]'}
|
||||
{ value: 'all', text: '[[unread:all_categories]]' },
|
||||
{ value: 'watched', text: '[[category:watched-categories]]' },
|
||||
].concat(results.categories);
|
||||
|
||||
var searchData = results.search;
|
||||
@@ -65,7 +65,7 @@ searchController.search = function (req, res, next) {
|
||||
searchData.showAsPosts = !req.query.showAs || req.query.showAs === 'posts';
|
||||
searchData.showAsTopics = req.query.showAs === 'topics';
|
||||
searchData.title = '[[global:header.search]]';
|
||||
searchData.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:search]]'}]);
|
||||
searchData.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[global:search]]' }]);
|
||||
searchData.expandSearch = !req.query.term;
|
||||
searchData.searchDefaultSortBy = meta.config.searchDefaultSortBy || '';
|
||||
|
||||
|
||||
@@ -65,4 +65,4 @@ sitemapController.getTopicPage = function (req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = sitemapController;
|
||||
module.exports = sitemapController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
|
||||
var async = require('async');
|
||||
@@ -8,7 +8,7 @@ var validator = require('validator');
|
||||
var user = require('../user');
|
||||
var topics = require('../topics');
|
||||
var pagination = require('../pagination');
|
||||
var helpers = require('./helpers');
|
||||
var helpers = require('./helpers');
|
||||
|
||||
var tagsController = {};
|
||||
|
||||
@@ -19,8 +19,8 @@ tagsController.getTag = function (req, res, next) {
|
||||
var templateData = {
|
||||
topics: [],
|
||||
tag: tag,
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[tags:tags]]', url: '/tags'}, {text: tag}]),
|
||||
title: '[[pages:tag, ' + tag + ']]'
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{ text: '[[tags:tags]]', url: '/tags' }, { text: tag }]),
|
||||
title: '[[pages:tag, ' + tag + ']]',
|
||||
};
|
||||
var settings;
|
||||
var topicCount = 0;
|
||||
@@ -39,7 +39,7 @@ tagsController.getTag = function (req, res, next) {
|
||||
},
|
||||
tids: function (next) {
|
||||
topics.getTagTids(req.params.tag, start, stop, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -48,7 +48,7 @@ tagsController.getTag = function (req, res, next) {
|
||||
}
|
||||
topicCount = results.topicCount;
|
||||
topics.getTopics(results.tids, req.uid, next);
|
||||
}
|
||||
},
|
||||
], function (err, topics) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -57,16 +57,16 @@ tagsController.getTag = function (req, res, next) {
|
||||
res.locals.metaTags = [
|
||||
{
|
||||
name: 'title',
|
||||
content: tag
|
||||
content: tag,
|
||||
},
|
||||
{
|
||||
property: 'og:title',
|
||||
content: tag
|
||||
content: tag,
|
||||
},
|
||||
{
|
||||
property: 'og:url',
|
||||
content: nconf.get('url') + '/tags/' + tag
|
||||
}
|
||||
content: nconf.get('url') + '/tags/' + tag,
|
||||
},
|
||||
];
|
||||
templateData.topics = topics;
|
||||
|
||||
@@ -86,8 +86,8 @@ tagsController.getTags = function (req, res, next) {
|
||||
var data = {
|
||||
tags: tags,
|
||||
nextStart: 100,
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[tags:tags]]'}]),
|
||||
title: '[[pages:tags]]'
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{ text: '[[tags:tags]]' }]),
|
||||
title: '[[pages:tags]]',
|
||||
};
|
||||
res.render('tags', data);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
|
||||
var async = require('async');
|
||||
@@ -39,7 +39,7 @@ topicsController.get = function (req, res, callback) {
|
||||
},
|
||||
topic: function (next) {
|
||||
topics.getTopicData(tid, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -113,7 +113,7 @@ topicsController.get = function (req, res, callback) {
|
||||
currentPage = Math.max(1, Math.ceil(index / settings.postsPerPage));
|
||||
}
|
||||
|
||||
var start = (currentPage - 1) * settings.postsPerPage + postIndex;
|
||||
var start = ((currentPage - 1) * settings.postsPerPage) + postIndex;
|
||||
var stop = start + settings.postsPerPage - 1;
|
||||
|
||||
topics.getTopicWithPosts(results.topic, set, req.uid, start, stop, reverse, next);
|
||||
@@ -125,18 +125,17 @@ topicsController.get = function (req, res, callback) {
|
||||
|
||||
topics.modifyPostsByPrivilege(topicData, userPrivileges);
|
||||
|
||||
plugins.fireHook('filter:controllers.topic.get', {topicData: topicData, uid: req.uid}, next);
|
||||
plugins.fireHook('filter:controllers.topic.get', { topicData: topicData, uid: req.uid }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
|
||||
var breadcrumbs = [
|
||||
{
|
||||
text: data.topicData.category.name,
|
||||
url: nconf.get('relative_path') + '/category/' + data.topicData.category.slug
|
||||
url: nconf.get('relative_path') + '/category/' + data.topicData.category.slug,
|
||||
},
|
||||
{
|
||||
text: data.topicData.title
|
||||
}
|
||||
text: data.topicData.title,
|
||||
},
|
||||
];
|
||||
|
||||
helpers.buildCategoryBreadcrumbs(data.topicData.category.parentCid, function (err, crumbs) {
|
||||
@@ -149,7 +148,7 @@ topicsController.get = function (req, res, callback) {
|
||||
},
|
||||
function (topicData, next) {
|
||||
function findPost(index) {
|
||||
for(var i = 0; i < topicData.posts.length; ++i) {
|
||||
for (var i = 0; i < topicData.posts.length; i += 1) {
|
||||
if (parseInt(topicData.posts[i].index, 10) === parseInt(index, 10)) {
|
||||
return topicData.posts[i];
|
||||
}
|
||||
@@ -187,71 +186,71 @@ topicsController.get = function (req, res, callback) {
|
||||
|
||||
res.locals.metaTags = [
|
||||
{
|
||||
name: "title",
|
||||
content: topicData.titleRaw
|
||||
name: 'title',
|
||||
content: topicData.titleRaw,
|
||||
},
|
||||
{
|
||||
name: "description",
|
||||
content: description
|
||||
name: 'description',
|
||||
content: description,
|
||||
},
|
||||
{
|
||||
property: 'og:title',
|
||||
content: topicData.titleRaw
|
||||
content: topicData.titleRaw,
|
||||
},
|
||||
{
|
||||
property: 'og:description',
|
||||
content: description
|
||||
content: description,
|
||||
},
|
||||
{
|
||||
property: "og:type",
|
||||
content: 'article'
|
||||
property: 'og:type',
|
||||
content: 'article',
|
||||
},
|
||||
{
|
||||
property: "og:url",
|
||||
property: 'og:url',
|
||||
content: nconf.get('url') + '/topic/' + topicData.slug + (req.params.post_index ? ('/' + req.params.post_index) : ''),
|
||||
noEscape: true
|
||||
noEscape: true,
|
||||
},
|
||||
{
|
||||
property: 'og:image',
|
||||
content: ogImageUrl,
|
||||
noEscape: true
|
||||
noEscape: true,
|
||||
},
|
||||
{
|
||||
property: "og:image:url",
|
||||
property: 'og:image:url',
|
||||
content: ogImageUrl,
|
||||
noEscape: true
|
||||
noEscape: true,
|
||||
},
|
||||
{
|
||||
property: "article:published_time",
|
||||
content: utils.toISOString(topicData.timestamp)
|
||||
property: 'article:published_time',
|
||||
content: utils.toISOString(topicData.timestamp),
|
||||
},
|
||||
{
|
||||
property: 'article:modified_time',
|
||||
content: utils.toISOString(topicData.lastposttime)
|
||||
content: utils.toISOString(topicData.lastposttime),
|
||||
},
|
||||
{
|
||||
property: 'article:section',
|
||||
content: topicData.category ? topicData.category.name : ''
|
||||
}
|
||||
content: topicData.category ? topicData.category.name : '',
|
||||
},
|
||||
];
|
||||
|
||||
res.locals.linkTags = [
|
||||
{
|
||||
rel: 'alternate',
|
||||
type: 'application/rss+xml',
|
||||
href: nconf.get('url') + '/topic/' + tid + '.rss'
|
||||
}
|
||||
href: nconf.get('url') + '/topic/' + tid + '.rss',
|
||||
},
|
||||
];
|
||||
|
||||
if (topicData.category) {
|
||||
res.locals.linkTags.push({
|
||||
rel: 'up',
|
||||
href: nconf.get('url') + '/category/' + topicData.category.slug
|
||||
href: nconf.get('url') + '/category/' + topicData.category.slug,
|
||||
});
|
||||
}
|
||||
|
||||
next(null, topicData);
|
||||
}
|
||||
},
|
||||
], function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -299,7 +298,7 @@ topicsController.teaser = function (req, res, next) {
|
||||
var tid = req.params.topic_id;
|
||||
|
||||
if (!utils.isNumber(tid)) {
|
||||
return next(new Error('[[error:invalid-tid]]'));
|
||||
return next();
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
@@ -316,8 +315,8 @@ topicsController.teaser = function (req, res, next) {
|
||||
if (!pid) {
|
||||
return res.status(404).json('not-found');
|
||||
}
|
||||
posts.getPostSummaryByPids([pid], req.uid, {stripTags: false}, next);
|
||||
}
|
||||
posts.getPostSummaryByPids([pid], req.uid, { stripTags: false }, next);
|
||||
},
|
||||
], function (err, posts) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -341,7 +340,7 @@ topicsController.pagination = function (req, res, callback) {
|
||||
async.parallel({
|
||||
privileges: async.apply(privileges.topics.get, tid, req.uid),
|
||||
settings: async.apply(user.getSettings, req.uid),
|
||||
topic: async.apply(topics.getTopicData, tid)
|
||||
topic: async.apply(topics.getTopicData, tid),
|
||||
}, function (err, results) {
|
||||
if (err || !results.topic) {
|
||||
return callback(err);
|
||||
|
||||
@@ -12,7 +12,7 @@ var helpers = require('./helpers');
|
||||
|
||||
var unreadController = {};
|
||||
|
||||
var validFilter = {'': true, 'new': true, 'watched': true};
|
||||
var validFilter = { '': true, new: true, watched: true };
|
||||
|
||||
unreadController.get = function (req, res, next) {
|
||||
var page = parseInt(req.query.page, 10) || 1;
|
||||
@@ -32,7 +32,7 @@ unreadController.get = function (req, res, next) {
|
||||
},
|
||||
settings: function (next) {
|
||||
user.getSettings(req.uid, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (_results, next) {
|
||||
@@ -47,9 +47,9 @@ unreadController.get = function (req, res, next) {
|
||||
start: start,
|
||||
stop: stop,
|
||||
filter: filter,
|
||||
cutoff: cutoff
|
||||
cutoff: cutoff,
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
], function (err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -67,7 +67,7 @@ unreadController.get = function (req, res, next) {
|
||||
data.selectedCategory = results.watchedCategories.selectedCategory;
|
||||
|
||||
if (req.path.startsWith('/api/unread') || req.path.startsWith('/unread')) {
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[unread:title]]'}]);
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[unread:title]]' }]);
|
||||
}
|
||||
|
||||
data.title = '[[pages:unread]]';
|
||||
@@ -75,17 +75,17 @@ unreadController.get = function (req, res, next) {
|
||||
name: '[[unread:all-topics]]',
|
||||
url: 'unread',
|
||||
selected: filter === '',
|
||||
filter: ''
|
||||
filter: '',
|
||||
}, {
|
||||
name: '[[unread:new-topics]]',
|
||||
url: 'unread/new',
|
||||
selected: filter === 'new',
|
||||
filter: 'new'
|
||||
filter: 'new',
|
||||
}, {
|
||||
name: '[[unread:watched-topics]]',
|
||||
url: 'unread/watched',
|
||||
selected: filter === 'watched',
|
||||
filter: 'watched'
|
||||
filter: 'watched',
|
||||
}];
|
||||
|
||||
data.selectedFilter = data.filters.find(function (filter) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
@@ -6,7 +6,6 @@ var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
var validator = require('validator');
|
||||
var winston = require('winston');
|
||||
var mime = require('mime');
|
||||
|
||||
var meta = require('../meta');
|
||||
var file = require('../file');
|
||||
@@ -31,7 +30,7 @@ uploadsController.upload = function (req, res, filesIterator) {
|
||||
deleteTempFiles(files);
|
||||
|
||||
if (err) {
|
||||
return res.status(500).send(err.message);
|
||||
return res.status(500).json({ path: req.path, error: err.message });
|
||||
}
|
||||
|
||||
res.status(200).send(images);
|
||||
@@ -61,7 +60,7 @@ function uploadAsImage(req, uploadedFile, callback) {
|
||||
if (plugins.hasListeners('filter:uploadImage')) {
|
||||
return plugins.fireHook('filter:uploadImage', {
|
||||
image: uploadedFile,
|
||||
uid: req.uid
|
||||
uid: req.uid,
|
||||
}, callback);
|
||||
}
|
||||
file.isFileTypeAllowed(uploadedFile.path, next);
|
||||
@@ -75,7 +74,7 @@ function uploadAsImage(req, uploadedFile, callback) {
|
||||
}
|
||||
|
||||
resizeImage(fileObj, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -92,7 +91,7 @@ function uploadAsFile(req, uploadedFile, callback) {
|
||||
return next(new Error('[[error:uploads-are-disabled]]'));
|
||||
}
|
||||
uploadFile(req.uid, uploadedFile, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -114,11 +113,10 @@ function resizeImage(fileObj, callback) {
|
||||
path: fileObj.path,
|
||||
target: path.join(dirname, basename + '-resized' + extname),
|
||||
extension: extname,
|
||||
width: parseInt(meta.config.maximumImageWidth, 10) || 760
|
||||
width: parseInt(meta.config.maximumImageWidth, 10) || 760,
|
||||
}, next);
|
||||
},
|
||||
function (next) {
|
||||
|
||||
// Return the resized version to the composer/postData
|
||||
var dirname = path.dirname(fileObj.url);
|
||||
var extname = path.extname(fileObj.url);
|
||||
@@ -127,7 +125,7 @@ function resizeImage(fileObj, callback) {
|
||||
fileObj.url = path.join(dirname, basename + '-resized' + extname);
|
||||
|
||||
next(null, fileObj);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -138,36 +136,34 @@ uploadsController.uploadThumb = function (req, res, next) {
|
||||
}
|
||||
|
||||
uploadsController.upload(req, res, function (uploadedFile, next) {
|
||||
file.isFileTypeAllowed(uploadedFile.path, function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!uploadedFile.type.match(/image./)) {
|
||||
return next(new Error('[[error:invalid-file]]'));
|
||||
}
|
||||
|
||||
var size = parseInt(meta.config.topicThumbSize, 10) || 120;
|
||||
image.resizeImage({
|
||||
path: uploadedFile.path,
|
||||
extension: path.extname(uploadedFile.name),
|
||||
width: size,
|
||||
height: size
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
if (!uploadedFile.type.match(/image./)) {
|
||||
return next(new Error('[[error:invalid-file]]'));
|
||||
}
|
||||
|
||||
file.isFileTypeAllowed(uploadedFile.path, next);
|
||||
},
|
||||
function (next) {
|
||||
var size = parseInt(meta.config.topicThumbSize, 10) || 120;
|
||||
image.resizeImage({
|
||||
path: uploadedFile.path,
|
||||
extension: path.extname(uploadedFile.name),
|
||||
width: size,
|
||||
height: size,
|
||||
}, next);
|
||||
},
|
||||
function (next) {
|
||||
if (plugins.hasListeners('filter:uploadImage')) {
|
||||
return plugins.fireHook('filter:uploadImage', {
|
||||
image: uploadedFile,
|
||||
uid: req.uid
|
||||
uid: req.uid,
|
||||
}, next);
|
||||
}
|
||||
|
||||
uploadFile(req.uid, uploadedFile, next);
|
||||
});
|
||||
});
|
||||
},
|
||||
], next);
|
||||
}, next);
|
||||
};
|
||||
|
||||
@@ -175,30 +171,32 @@ uploadsController.uploadGroupCover = function (uid, uploadedFile, callback) {
|
||||
if (plugins.hasListeners('filter:uploadImage')) {
|
||||
return plugins.fireHook('filter:uploadImage', {
|
||||
image: uploadedFile,
|
||||
uid: uid
|
||||
uid: uid,
|
||||
}, callback);
|
||||
}
|
||||
|
||||
if (plugins.hasListeners('filter:uploadFile')) {
|
||||
return plugins.fireHook('filter:uploadFile', {
|
||||
file: uploadedFile,
|
||||
uid: uid
|
||||
uid: uid,
|
||||
}, callback);
|
||||
}
|
||||
|
||||
file.isFileTypeAllowed(uploadedFile.path, function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
saveFileToLocal(uploadedFile, callback);
|
||||
});
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
file.isFileTypeAllowed(uploadedFile.path, next);
|
||||
},
|
||||
function (next) {
|
||||
saveFileToLocal(uploadedFile, next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
function uploadFile(uid, uploadedFile, callback) {
|
||||
if (plugins.hasListeners('filter:uploadFile')) {
|
||||
return plugins.fireHook('filter:uploadFile', {
|
||||
file: uploadedFile,
|
||||
uid: uid
|
||||
uid: uid,
|
||||
}, callback);
|
||||
}
|
||||
|
||||
@@ -230,17 +228,18 @@ function saveFileToLocal(uploadedFile, callback) {
|
||||
|
||||
filename = Date.now() + '-' + validator.escape(filename.replace(path.extname(uploadedFile.name) || '', '')).substr(0, 255) + extension;
|
||||
|
||||
file.saveFileToLocal(filename, 'files', uploadedFile.path, function (err, upload) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null, {
|
||||
url: nconf.get('relative_path') + upload.url,
|
||||
path: upload.path,
|
||||
name: uploadedFile.name
|
||||
});
|
||||
});
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
file.saveFileToLocal(filename, 'files', uploadedFile.path, next);
|
||||
},
|
||||
function (upload, next) {
|
||||
next(null, {
|
||||
url: nconf.get('relative_path') + upload.url,
|
||||
path: upload.path,
|
||||
name: uploadedFile.name,
|
||||
});
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
function deleteTempFiles(files) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var user = require('../user');
|
||||
@@ -20,7 +20,7 @@ usersController.index = function (req, res, next) {
|
||||
'sort-posts': usersController.getUsersSortedByPosts,
|
||||
'sort-reputation': usersController.getUsersSortedByReputation,
|
||||
banned: usersController.getBannedUsers,
|
||||
flagged: usersController.getFlaggedUsers
|
||||
flagged: usersController.getFlaggedUsers,
|
||||
};
|
||||
|
||||
if (req.query.term) {
|
||||
@@ -42,12 +42,12 @@ usersController.search = function (req, res, next) {
|
||||
sortBy: req.query.sortBy,
|
||||
onlineOnly: req.query.onlineOnly === 'true',
|
||||
bannedOnly: req.query.bannedOnly === 'true',
|
||||
flaggedOnly: req.query.flaggedOnly === 'true'
|
||||
flaggedOnly: req.query.flaggedOnly === 'true',
|
||||
}, next);
|
||||
},
|
||||
isAdminOrGlobalMod: function (next) {
|
||||
user.isAdminOrGlobalMod(req.uid, next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -69,7 +69,7 @@ usersController.getOnlineUsers = function (req, res, next) {
|
||||
},
|
||||
guests: function (next) {
|
||||
require('../socket.io/admin/rooms').getTotalGuestCount(next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -79,7 +79,7 @@ usersController.getOnlineUsers = function (req, res, next) {
|
||||
if (!userData.isAdminOrGlobalMod) {
|
||||
userData.users = userData.users.filter(function (user) {
|
||||
if (user && user.status === 'offline') {
|
||||
hiddenCount ++;
|
||||
hiddenCount += 1;
|
||||
}
|
||||
return user && user.status !== 'offline';
|
||||
});
|
||||
@@ -146,22 +146,22 @@ usersController.renderUsersPage = function (set, req, res, next) {
|
||||
|
||||
usersController.getUsers = function (set, uid, query, callback) {
|
||||
var setToData = {
|
||||
'users:postcount': {title: '[[pages:users/sort-posts]]', crumb: '[[users:top_posters]]'},
|
||||
'users:reputation': {title: '[[pages:users/sort-reputation]]', crumb: '[[users:most_reputation]]'},
|
||||
'users:joindate': {title: '[[pages:users/latest]]', crumb: '[[global:users]]'},
|
||||
'users:online': {title: '[[pages:users/online]]', crumb: '[[global:online]]'},
|
||||
'users:banned': {title: '[[pages:users/banned]]', crumb: '[[user:banned]]'},
|
||||
'users:flags': {title: '[[pages:users/most-flags]]', crumb: '[[users:most_flags]]'},
|
||||
'users:postcount': { title: '[[pages:users/sort-posts]]', crumb: '[[users:top_posters]]' },
|
||||
'users:reputation': { title: '[[pages:users/sort-reputation]]', crumb: '[[users:most_reputation]]' },
|
||||
'users:joindate': { title: '[[pages:users/latest]]', crumb: '[[global:users]]' },
|
||||
'users:online': { title: '[[pages:users/online]]', crumb: '[[global:online]]' },
|
||||
'users:banned': { title: '[[pages:users/banned]]', crumb: '[[user:banned]]' },
|
||||
'users:flags': { title: '[[pages:users/most-flags]]', crumb: '[[users:most_flags]]' },
|
||||
};
|
||||
|
||||
if (!setToData[set]) {
|
||||
setToData[set] = {title: '', crumb: ''};
|
||||
setToData[set] = { title: '', crumb: '' };
|
||||
}
|
||||
|
||||
var breadcrumbs = [{text: setToData[set].crumb}];
|
||||
var breadcrumbs = [{ text: setToData[set].crumb }];
|
||||
|
||||
if (set !== 'users:joindate') {
|
||||
breadcrumbs.unshift({text: '[[global:users]]', url: '/users'});
|
||||
breadcrumbs.unshift({ text: '[[global:users]]', url: '/users' });
|
||||
}
|
||||
|
||||
var page = parseInt(query.page, 10) || 1;
|
||||
@@ -175,7 +175,7 @@ usersController.getUsers = function (set, uid, query, callback) {
|
||||
},
|
||||
usersData: function (next) {
|
||||
usersController.getUsersAndCount(set, uid, start, stop, next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -188,7 +188,7 @@ usersController.getUsers = function (set, uid, query, callback) {
|
||||
userCount: results.usersData.count,
|
||||
title: setToData[set].title || '[[pages:users/latest]]',
|
||||
breadcrumbs: helpers.buildBreadcrumbs(breadcrumbs),
|
||||
isAdminOrGlobalMod: results.isAdminOrGlobalMod
|
||||
isAdminOrGlobalMod: results.isAdminOrGlobalMod,
|
||||
};
|
||||
userData['section_' + (query.section || 'joindate')] = true;
|
||||
callback(null, userData);
|
||||
@@ -211,7 +211,7 @@ usersController.getUsersAndCount = function (set, uid, start, stop, callback) {
|
||||
} else {
|
||||
db.getObjectField('global', 'userCount', next);
|
||||
}
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var coverPhoto = {};
|
||||
var meta = require('./meta');
|
||||
@@ -14,13 +14,13 @@ coverPhoto.getDefaultProfileCover = function (uid) {
|
||||
};
|
||||
|
||||
function getCover(type, id) {
|
||||
if (meta.config[type + ':defaultCovers']) {
|
||||
if (meta.config[type + ':defaultCovers']) {
|
||||
var covers = meta.config[type + ':defaultCovers'].trim().split(/[\s,]+/g);
|
||||
|
||||
|
||||
if (typeof id === 'string') {
|
||||
id = (id.charCodeAt(0) + id.charCodeAt(1)) % covers.length;
|
||||
} else {
|
||||
id = id % covers.length;
|
||||
id %= covers.length;
|
||||
}
|
||||
|
||||
return covers[id];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var nconf = require('nconf');
|
||||
var databaseName = nconf.get('database');
|
||||
@@ -11,4 +11,4 @@ if (!databaseName) {
|
||||
|
||||
var primaryDB = require('./database/' + databaseName);
|
||||
|
||||
module.exports = primaryDB;
|
||||
module.exports = primaryDB;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
'use strict';
|
||||
|
||||
(function (module) {
|
||||
|
||||
var winston = require('winston');
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
@@ -17,30 +16,30 @@
|
||||
{
|
||||
name: 'mongo:host',
|
||||
description: 'Host IP or address of your MongoDB instance',
|
||||
'default': nconf.get('mongo:host') || '127.0.0.1'
|
||||
default: nconf.get('mongo:host') || '127.0.0.1',
|
||||
},
|
||||
{
|
||||
name: 'mongo:port',
|
||||
description: 'Host port of your MongoDB instance',
|
||||
'default': nconf.get('mongo:port') || 27017
|
||||
default: nconf.get('mongo:port') || 27017,
|
||||
},
|
||||
{
|
||||
name: 'mongo:username',
|
||||
description: 'MongoDB username',
|
||||
'default': nconf.get('mongo:username') || ''
|
||||
default: nconf.get('mongo:username') || '',
|
||||
},
|
||||
{
|
||||
name: 'mongo:password',
|
||||
description: 'Password of your MongoDB database',
|
||||
hidden: true,
|
||||
default: nconf.get('mongo:password') || '',
|
||||
before: function (value) { value = value || nconf.get('mongo:password') || ''; return value; }
|
||||
before: function (value) { value = value || nconf.get('mongo:password') || ''; return value; },
|
||||
},
|
||||
{
|
||||
name: "mongo:database",
|
||||
description: "MongoDB database name",
|
||||
'default': nconf.get('mongo:database') || 'nodebb'
|
||||
}
|
||||
name: 'mongo:database',
|
||||
description: 'MongoDB database name',
|
||||
default: nconf.get('mongo:database') || 'nodebb',
|
||||
},
|
||||
];
|
||||
|
||||
module.helpers = module.helpers || {};
|
||||
@@ -76,7 +75,7 @@
|
||||
var ports = nconf.get('mongo:port').toString().split(',');
|
||||
var servers = [];
|
||||
|
||||
for (var i = 0; i < hosts.length; i++) {
|
||||
for (var i = 0; i < hosts.length; i += 1) {
|
||||
servers.push(hosts[i] + ':' + ports[i]);
|
||||
}
|
||||
|
||||
@@ -84,15 +83,15 @@
|
||||
|
||||
var connOptions = {
|
||||
server: {
|
||||
poolSize: parseInt(nconf.get('mongo:poolSize'), 10) || 10
|
||||
}
|
||||
poolSize: parseInt(nconf.get('mongo:poolSize'), 10) || 10,
|
||||
},
|
||||
};
|
||||
|
||||
connOptions = _.deepExtend((nconf.get('mongo:options') || {}), connOptions);
|
||||
|
||||
mongoClient.connect(connString, connOptions, function (err, _db) {
|
||||
if (err) {
|
||||
winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message);
|
||||
winston.error('NodeBB could not connect to your Mongo database. Mongo returned the following error: ' + err.message);
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -135,13 +134,13 @@
|
||||
|
||||
module.sessionStore = new sessionStore({
|
||||
client: rdb.client,
|
||||
ttl: ttl
|
||||
ttl: ttl,
|
||||
});
|
||||
} else if (nconf.get('mongo')) {
|
||||
sessionStore = require('connect-mongo')(session);
|
||||
module.sessionStore = new sessionStore({
|
||||
db: db,
|
||||
ttl: ttl
|
||||
ttl: ttl,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -162,7 +161,7 @@
|
||||
async.series([
|
||||
async.apply(createIndex, 'objects', { _key: 1, score: -1 }, { background: true }),
|
||||
async.apply(createIndex, 'objects', { _key: 1, value: -1 }, { background: true, unique: true, sparse: true }),
|
||||
async.apply(createIndex, 'objects', { expireAt: 1 }, { expireAfterSeconds: 0, background: true })
|
||||
async.apply(createIndex, 'objects', { expireAt: 1 }, { expireAfterSeconds: 0, background: true }),
|
||||
], function (err) {
|
||||
if (err) {
|
||||
winston.error('Error creating index ' + err.message);
|
||||
@@ -189,10 +188,10 @@
|
||||
}
|
||||
async.parallel({
|
||||
serverStatus: function (next) {
|
||||
db.command({ 'serverStatus': 1 }, next);
|
||||
db.command({ serverStatus: 1 }, next);
|
||||
},
|
||||
stats: function (next) {
|
||||
db.command({ 'dbStats': 1 }, next);
|
||||
db.command({ dbStats: 1 }, next);
|
||||
},
|
||||
listCollections: function (next) {
|
||||
db.listCollections().toArray(function (err, items) {
|
||||
@@ -203,7 +202,7 @@
|
||||
db.collection(collection.name).stats(next);
|
||||
}, next);
|
||||
});
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -219,7 +218,7 @@
|
||||
avgObjSize: collectionInfo.avgObjSize,
|
||||
storageSize: collectionInfo.storageSize,
|
||||
totalIndexSize: collectionInfo.totalIndexSize,
|
||||
indexSizes: collectionInfo.indexSizes
|
||||
indexSizes: collectionInfo.indexSizes,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -246,5 +245,4 @@
|
||||
module.close = function () {
|
||||
db.close();
|
||||
};
|
||||
|
||||
} (exports));
|
||||
}(exports));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
module.exports = function (db, module) {
|
||||
var helpers = module.helpers.mongo;
|
||||
@@ -9,7 +9,7 @@ module.exports = function (db, module) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
db.collection('objects').update({_key: key}, {$set: data}, {upsert: true, w: 1}, function (err) {
|
||||
db.collection('objects').update({ _key: key }, { $set: data }, { upsert: true, w: 1 }, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -29,14 +29,14 @@ module.exports = function (db, module) {
|
||||
if (!key) {
|
||||
return callback();
|
||||
}
|
||||
db.collection('objects').findOne({_key: key}, {_id: 0, _key: 0}, callback);
|
||||
db.collection('objects').findOne({ _key: key }, { _id: 0, _key: 0 }, callback);
|
||||
};
|
||||
|
||||
module.getObjects = function (keys, callback) {
|
||||
if (!Array.isArray(keys) || !keys.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
db.collection('objects').find({_key: {$in: keys}}, {_id: 0}).toArray(function (err, data) {
|
||||
db.collection('objects').find({ _key: { $in: keys } }, { _id: 0 }).toArray(function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -44,7 +44,7 @@ module.exports = function (db, module) {
|
||||
var map = helpers.toMap(data);
|
||||
var returnData = [];
|
||||
|
||||
for (var i = 0; i < keys.length; ++i) {
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
returnData.push(map[keys[i]]);
|
||||
}
|
||||
|
||||
@@ -58,10 +58,10 @@ module.exports = function (db, module) {
|
||||
}
|
||||
field = helpers.fieldToString(field);
|
||||
var _fields = {
|
||||
_id: 0
|
||||
_id: 0,
|
||||
};
|
||||
_fields[field] = 1;
|
||||
db.collection('objects').findOne({_key: key}, {fields: _fields}, function (err, item) {
|
||||
db.collection('objects').findOne({ _key: key }, { fields: _fields }, function (err, item) {
|
||||
if (err || !item) {
|
||||
return callback(err, null);
|
||||
}
|
||||
@@ -75,20 +75,21 @@ module.exports = function (db, module) {
|
||||
return callback();
|
||||
}
|
||||
var _fields = {
|
||||
_id: 0
|
||||
_id: 0,
|
||||
};
|
||||
var i;
|
||||
|
||||
for(var i = 0; i < fields.length; ++i) {
|
||||
for (i = 0; i < fields.length; i += 1) {
|
||||
fields[i] = helpers.fieldToString(fields[i]);
|
||||
_fields[fields[i]] = 1;
|
||||
}
|
||||
db.collection('objects').findOne({_key: key}, {fields: _fields}, function (err, item) {
|
||||
db.collection('objects').findOne({ _key: key }, { fields: _fields }, function (err, item) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
item = item || {};
|
||||
var result = {};
|
||||
for(i = 0; i < fields.length; ++i) {
|
||||
for (i = 0; i < fields.length; i += 1) {
|
||||
result[fields[i]] = item[fields[i]] !== undefined ? item[fields[i]] : null;
|
||||
}
|
||||
callback(null, result);
|
||||
@@ -101,15 +102,15 @@ module.exports = function (db, module) {
|
||||
}
|
||||
var _fields = {
|
||||
_id: 0,
|
||||
_key: 1
|
||||
_key: 1,
|
||||
};
|
||||
|
||||
for(var i = 0; i < fields.length; ++i) {
|
||||
for (var i = 0; i < fields.length; i += 1) {
|
||||
fields[i] = helpers.fieldToString(fields[i]);
|
||||
_fields[fields[i]] = 1;
|
||||
}
|
||||
|
||||
db.collection('objects').find({_key: {$in: keys}}, {fields: _fields}).toArray(function (err, items) {
|
||||
db.collection('objects').find({ _key: { $in: keys } }, { fields: _fields }).toArray(function (err, items) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -122,10 +123,10 @@ module.exports = function (db, module) {
|
||||
var returnData = [];
|
||||
var item;
|
||||
|
||||
for (var i = 0; i < keys.length; ++i) {
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
item = map[keys[i]] || {};
|
||||
|
||||
for (var k = 0; k < fields.length; ++k) {
|
||||
for (var k = 0; k < fields.length; k += 1) {
|
||||
if (item[fields[k]] === undefined) {
|
||||
item[fields[k]] = null;
|
||||
}
|
||||
@@ -145,12 +146,12 @@ module.exports = function (db, module) {
|
||||
|
||||
module.getObjectValues = function (key, callback) {
|
||||
module.getObject(key, function (err, data) {
|
||||
if(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var values = [];
|
||||
for(var key in data) {
|
||||
for (var key in data) {
|
||||
if (data && data.hasOwnProperty(key)) {
|
||||
values.push(data[key]);
|
||||
}
|
||||
@@ -166,7 +167,7 @@ module.exports = function (db, module) {
|
||||
var data = {};
|
||||
field = helpers.fieldToString(field);
|
||||
data[field] = '';
|
||||
db.collection('objects').findOne({_key: key}, {fields: data}, function (err, item) {
|
||||
db.collection('objects').findOne({ _key: key }, { fields: data }, function (err, item) {
|
||||
callback(err, !!item && item[field] !== undefined && item[field] !== null);
|
||||
});
|
||||
};
|
||||
@@ -182,7 +183,7 @@ module.exports = function (db, module) {
|
||||
data[field] = '';
|
||||
});
|
||||
|
||||
db.collection('objects').findOne({_key: key}, {fields: data}, function (err, item) {
|
||||
db.collection('objects').findOne({ _key: key }, { fields: data }, function (err, item) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -216,7 +217,7 @@ module.exports = function (db, module) {
|
||||
data[field] = '';
|
||||
});
|
||||
|
||||
db.collection('objects').update({_key: key}, {$unset : data}, function (err) {
|
||||
db.collection('objects').update({ _key: key }, { $unset: data }, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -240,8 +241,8 @@ module.exports = function (db, module) {
|
||||
field = helpers.fieldToString(field);
|
||||
data[field] = value;
|
||||
|
||||
db.collection('objects').findAndModify({_key: key}, {}, {$inc: data}, {new: true, upsert: true}, function (err, result) {
|
||||
db.collection('objects').findAndModify({ _key: key }, {}, { $inc: data }, { new: true, upsert: true }, function (err, result) {
|
||||
callback(err, result && result.value ? result.value[field] : null);
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var helpers = {};
|
||||
|
||||
helpers.toMap = function (data) {
|
||||
var map = {};
|
||||
for (var i = 0; i < data.length; ++i) {
|
||||
for (var i = 0; i < data.length; i += 1) {
|
||||
map[data[i]._key] = data[i];
|
||||
data[i]._key = undefined;
|
||||
}
|
||||
@@ -12,11 +12,11 @@ helpers.toMap = function (data) {
|
||||
};
|
||||
|
||||
helpers.fieldToString = function (field) {
|
||||
if(field === null || field === undefined) {
|
||||
if (field === null || field === undefined) {
|
||||
return field;
|
||||
}
|
||||
|
||||
if(typeof field !== 'string') {
|
||||
if (typeof field !== 'string') {
|
||||
field = field.toString();
|
||||
}
|
||||
// if there is a '.' in the field name it inserts subdocument in mongo, replace '.'s with \uff0E
|
||||
@@ -25,7 +25,7 @@ helpers.fieldToString = function (field) {
|
||||
};
|
||||
|
||||
helpers.valueToString = function (value) {
|
||||
if(value === null || value === undefined) {
|
||||
if (value === null || value === undefined) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -34,4 +34,4 @@ helpers.valueToString = function (value) {
|
||||
|
||||
helpers.noop = function () {};
|
||||
|
||||
module.exports = helpers;
|
||||
module.exports = helpers;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
module.exports = function (db, module) {
|
||||
var helpers = module.helpers.mongo;
|
||||
@@ -18,7 +18,7 @@ module.exports = function (db, module) {
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
db.collection('objects').update({_key:key}, {$push: {array: {$each: [value], $position: 0}}}, {upsert:true, w:1 }, function (err, res) {
|
||||
db.collection('objects').update({ _key: key }, { $push: { array: { $each: [value], $position: 0 } } }, { upsert: true, w: 1 }, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
} else {
|
||||
@@ -33,7 +33,7 @@ module.exports = function (db, module) {
|
||||
return callback();
|
||||
}
|
||||
value = helpers.valueToString(value);
|
||||
db.collection('objects').update({ _key: key }, { $push: { array: value } }, {upsert:true, w:1}, function (err, res) {
|
||||
db.collection('objects').update({ _key: key }, { $push: { array: value } }, { upsert: true, w: 1 }, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -48,20 +48,20 @@ module.exports = function (db, module) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db.collection('objects').update({_key: key }, { $pop: { array: 1 } }, function (err, result) {
|
||||
db.collection('objects').update({ _key: key }, { $pop: { array: 1 } }, function (err) {
|
||||
callback(err, (value && value.length) ? value[0] : null);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.listRemoveAll = function (key, value, callback) {
|
||||
callback = callback || helpers.noop;
|
||||
callback = callback || helpers.noop;
|
||||
if (!key) {
|
||||
return callback();
|
||||
}
|
||||
value = helpers.valueToString(value);
|
||||
|
||||
db.collection('objects').update({_key: key }, { $pull: { array: value } }, function (err, res) {
|
||||
db.collection('objects').update({ _key: key }, { $pull: { array: value } }, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -76,7 +76,7 @@ module.exports = function (db, module) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db.collection('objects').update({_key: key}, {$set: {array: value}}, function (err, res) {
|
||||
db.collection('objects').update({ _key: key }, { $set: { array: value } }, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
});
|
||||
@@ -87,8 +87,8 @@ module.exports = function (db, module) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
db.collection('objects').findOne({_key:key}, { array: 1}, function (err, data) {
|
||||
if(err || !(data && data.array)) {
|
||||
db.collection('objects').findOne({ _key: key }, { array: 1 }, function (err, data) {
|
||||
if (err || !(data && data.array)) {
|
||||
return callback(err, []);
|
||||
}
|
||||
|
||||
@@ -100,4 +100,4 @@ module.exports = function (db, module) {
|
||||
callback(null, data.array);
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
var winston = require('winston');
|
||||
'use strict';
|
||||
|
||||
module.exports = function (db, module) {
|
||||
var helpers = module.helpers.mongo;
|
||||
@@ -23,7 +21,7 @@ module.exports = function (db, module) {
|
||||
if (!key) {
|
||||
return callback();
|
||||
}
|
||||
db.collection('objects').findOne({_key: key}, function (err, item) {
|
||||
db.collection('objects').findOne({ _key: key }, function (err, item) {
|
||||
callback(err, item !== undefined && item !== null);
|
||||
});
|
||||
};
|
||||
@@ -33,7 +31,7 @@ module.exports = function (db, module) {
|
||||
if (!key) {
|
||||
return callback();
|
||||
}
|
||||
db.collection('objects').remove({_key: key}, function (err, res) {
|
||||
db.collection('objects').remove({ _key: key }, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -43,7 +41,7 @@ module.exports = function (db, module) {
|
||||
if (!Array.isArray(keys) || !keys.length) {
|
||||
return callback();
|
||||
}
|
||||
db.collection('objects').remove({_key: {$in: keys}}, function (err, res) {
|
||||
db.collection('objects').remove({ _key: { $in: keys } }, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -60,7 +58,7 @@ module.exports = function (db, module) {
|
||||
if (!key) {
|
||||
return callback();
|
||||
}
|
||||
var data = {value: value};
|
||||
var data = { value: value };
|
||||
module.setObject(key, data, callback);
|
||||
};
|
||||
|
||||
@@ -69,14 +67,14 @@ module.exports = function (db, module) {
|
||||
if (!key) {
|
||||
return callback();
|
||||
}
|
||||
db.collection('objects').findAndModify({_key: key}, {}, {$inc: {value: 1}}, {new: true, upsert: true}, function (err, result) {
|
||||
db.collection('objects').findAndModify({ _key: key }, {}, { $inc: { value: 1 } }, { new: true, upsert: true }, function (err, result) {
|
||||
callback(err, result && result.value ? result.value.value : null);
|
||||
});
|
||||
};
|
||||
|
||||
module.rename = function (oldKey, newKey, callback) {
|
||||
callback = callback || helpers.noop;
|
||||
db.collection('objects').update({_key: oldKey}, {$set:{_key: newKey}}, {multi: true}, function (err, res) {
|
||||
db.collection('objects').update({ _key: oldKey }, { $set: { _key: newKey } }, { multi: true }, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -96,4 +94,4 @@ module.exports = function (db, module) {
|
||||
module.pexpireAt = function (key, timestamp, callback) {
|
||||
module.setObjectField(key, 'expireAt', new Date(timestamp), callback);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
module.exports = function (db, module) {
|
||||
var helpers = module.helpers.mongo;
|
||||
|
||||
module.setAdd = function (key, value, callback) {
|
||||
callback = callback || helpers.noop;
|
||||
if(!Array.isArray(value)) {
|
||||
if (!Array.isArray(value)) {
|
||||
value = [value];
|
||||
}
|
||||
|
||||
@@ -14,17 +14,17 @@ module.exports = function (db, module) {
|
||||
});
|
||||
|
||||
db.collection('objects').update({
|
||||
_key: key
|
||||
_key: key,
|
||||
}, {
|
||||
$addToSet: {
|
||||
members: {
|
||||
$each: value
|
||||
}
|
||||
}
|
||||
$each: value,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
upsert: true,
|
||||
w: 1
|
||||
}, function (err, res) {
|
||||
w: 1,
|
||||
}, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -36,7 +36,7 @@ module.exports = function (db, module) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
if(!Array.isArray(value)) {
|
||||
if (!Array.isArray(value)) {
|
||||
value = [value];
|
||||
}
|
||||
|
||||
@@ -46,22 +46,22 @@ module.exports = function (db, module) {
|
||||
|
||||
var bulk = db.collection('objects').initializeUnorderedBulkOp();
|
||||
|
||||
for(var i = 0; i < keys.length; ++i) {
|
||||
bulk.find({_key: keys[i]}).upsert().updateOne({ $addToSet: {
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
bulk.find({ _key: keys[i] }).upsert().updateOne({ $addToSet: {
|
||||
members: {
|
||||
$each: value
|
||||
}
|
||||
}});
|
||||
$each: value,
|
||||
},
|
||||
} });
|
||||
}
|
||||
|
||||
bulk.execute(function (err, res) {
|
||||
bulk.execute(function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
module.setRemove = function (key, value, callback) {
|
||||
callback = callback || helpers.noop;
|
||||
if(!Array.isArray(value)) {
|
||||
if (!Array.isArray(value)) {
|
||||
value = [value];
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ module.exports = function (db, module) {
|
||||
array[index] = helpers.valueToString(element);
|
||||
});
|
||||
|
||||
db.collection('objects').update({_key: key}, {$pullAll: {members: value}}, function (err, res) {
|
||||
db.collection('objects').update({ _key: key }, { $pullAll: { members: value } }, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -83,13 +83,13 @@ module.exports = function (db, module) {
|
||||
|
||||
var bulk = db.collection('objects').initializeUnorderedBulkOp();
|
||||
|
||||
for(var i = 0; i < keys.length; ++i) {
|
||||
bulk.find({_key: keys[i]}).updateOne({$pull: {
|
||||
members: value
|
||||
}});
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
bulk.find({ _key: keys[i] }).updateOne({ $pull: {
|
||||
members: value,
|
||||
} });
|
||||
}
|
||||
|
||||
bulk.execute(function (err, res) {
|
||||
bulk.execute(function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -100,7 +100,7 @@ module.exports = function (db, module) {
|
||||
}
|
||||
value = helpers.valueToString(value);
|
||||
|
||||
db.collection('objects').findOne({_key: key, members: value}, {_id: 0, members: 0},function (err, item) {
|
||||
db.collection('objects').findOne({ _key: key, members: value }, { _id: 0, members: 0 }, function (err, item) {
|
||||
callback(err, item !== null && item !== undefined);
|
||||
});
|
||||
};
|
||||
@@ -110,11 +110,11 @@ module.exports = function (db, module) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
for (var i = 0; i < values.length; ++i) {
|
||||
for (var i = 0; i < values.length; i += 1) {
|
||||
values[i] = helpers.valueToString(values[i]);
|
||||
}
|
||||
|
||||
db.collection('objects').findOne({_key: key}, {_id: 0, _key: 0}, function (err, items) {
|
||||
db.collection('objects').findOne({ _key: key }, { _id: 0, _key: 0 }, function (err, items) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -133,7 +133,7 @@ module.exports = function (db, module) {
|
||||
}
|
||||
value = helpers.valueToString(value);
|
||||
|
||||
db.collection('objects').find({_key: {$in : sets}, members: value}, {_id:0, members: 0}).toArray(function (err, result) {
|
||||
db.collection('objects').find({ _key: { $in: sets }, members: value }, { _id: 0, members: 0 }).toArray(function (err, result) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -154,7 +154,7 @@ module.exports = function (db, module) {
|
||||
if (!key) {
|
||||
return callback(null, []);
|
||||
}
|
||||
db.collection('objects').findOne({_key: key}, {members: 1}, {_id: 0, _key: 0}, function (err, data) {
|
||||
db.collection('objects').findOne({ _key: key }, { members: 1 }, { _id: 0, _key: 0 }, function (err, data) {
|
||||
callback(err, data ? data.members : []);
|
||||
});
|
||||
};
|
||||
@@ -163,7 +163,7 @@ module.exports = function (db, module) {
|
||||
if (!Array.isArray(keys) || !keys.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
db.collection('objects').find({_key: {$in: keys}}, {_id: 0, _key: 1, members: 1}).toArray(function (err, data) {
|
||||
db.collection('objects').find({ _key: { $in: keys } }, { _id: 0, _key: 1, members: 1 }).toArray(function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -174,7 +174,7 @@ module.exports = function (db, module) {
|
||||
});
|
||||
|
||||
var returnData = new Array(keys.length);
|
||||
for(var i = 0; i < keys.length; ++i) {
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
returnData[i] = sets[keys[i]] || [];
|
||||
}
|
||||
callback(null, returnData);
|
||||
@@ -185,7 +185,7 @@ module.exports = function (db, module) {
|
||||
if (!key) {
|
||||
return callback(null, 0);
|
||||
}
|
||||
db.collection('objects').findOne({_key: key}, {_id: 0}, function (err, data) {
|
||||
db.collection('objects').findOne({ _key: key }, { _id: 0 }, function (err, data) {
|
||||
callback(err, data ? data.members.length : 0);
|
||||
});
|
||||
};
|
||||
@@ -205,8 +205,8 @@ module.exports = function (db, module) {
|
||||
|
||||
module.setRemoveRandom = function (key, callback) {
|
||||
callback = callback || function () {};
|
||||
db.collection('objects').findOne({_key:key}, function (err, data) {
|
||||
if(err || !data) {
|
||||
db.collection('objects').findOne({ _key: key }, function (err, data) {
|
||||
if (err || !data) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -217,4 +217,4 @@ module.exports = function (db, module) {
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var utils = require('../../../public/src/utils');
|
||||
@@ -32,13 +32,13 @@ module.exports = function (db, module) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
var fields = {_id: 0, value: 1};
|
||||
var fields = { _id: 0, value: 1 };
|
||||
if (withScores) {
|
||||
fields.score = 1;
|
||||
}
|
||||
|
||||
if (Array.isArray(key)) {
|
||||
key = {$in: key};
|
||||
key = { $in: key };
|
||||
}
|
||||
|
||||
var limit = stop - start + 1;
|
||||
@@ -46,10 +46,10 @@ module.exports = function (db, module) {
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
db.collection('objects').find({_key: key}, {fields: fields})
|
||||
db.collection('objects').find({ _key: key }, { fields: fields })
|
||||
.limit(limit)
|
||||
.skip(start)
|
||||
.sort({score: sort})
|
||||
.sort({ score: sort })
|
||||
.toArray(function (err, data) {
|
||||
if (err || !data) {
|
||||
return callback(err);
|
||||
@@ -89,25 +89,25 @@ module.exports = function (db, module) {
|
||||
count = 0;
|
||||
}
|
||||
|
||||
var query = {_key: key};
|
||||
var query = { _key: key };
|
||||
|
||||
if (min !== '-inf') {
|
||||
query.score = {$gte: min};
|
||||
query.score = { $gte: min };
|
||||
}
|
||||
if (max !== '+inf') {
|
||||
query.score = query.score || {};
|
||||
query.score.$lte = max;
|
||||
}
|
||||
|
||||
var fields = {_id: 0, value: 1};
|
||||
var fields = { _id: 0, value: 1 };
|
||||
if (withScores) {
|
||||
fields.score = 1;
|
||||
}
|
||||
|
||||
db.collection('objects').find(query, {fields: fields})
|
||||
db.collection('objects').find(query, { fields: fields })
|
||||
.limit(count)
|
||||
.skip(start)
|
||||
.sort({score: sort})
|
||||
.sort({ score: sort })
|
||||
.toArray(function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -128,9 +128,9 @@ module.exports = function (db, module) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
var query = {_key: key};
|
||||
var query = { _key: key };
|
||||
if (min !== '-inf') {
|
||||
query.score = {$gte: min};
|
||||
query.score = { $gte: min };
|
||||
}
|
||||
if (max !== '+inf') {
|
||||
query.score = query.score || {};
|
||||
@@ -138,7 +138,7 @@ module.exports = function (db, module) {
|
||||
}
|
||||
|
||||
db.collection('objects').count(query, function (err, count) {
|
||||
callback(err, count ? count : 0);
|
||||
callback(err, count || 0);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -146,9 +146,9 @@ module.exports = function (db, module) {
|
||||
if (!key) {
|
||||
return callback(null, 0);
|
||||
}
|
||||
db.collection('objects').count({_key: key}, function (err, count) {
|
||||
db.collection('objects').count({ _key: key }, function (err, count) {
|
||||
count = parseInt(count, 10);
|
||||
callback(err, count ? count : 0);
|
||||
callback(err, count || 0);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -157,9 +157,9 @@ module.exports = function (db, module) {
|
||||
return callback();
|
||||
}
|
||||
var pipeline = [
|
||||
{ $match : { _key : { $in: keys } } } ,
|
||||
{ $group: { _id: {_key: '$_key'}, count: { $sum: 1 } } },
|
||||
{ $project: { _id: 1, count: '$count' } }
|
||||
{ $match: { _key: { $in: keys } } },
|
||||
{ $group: { _id: { _key: '$_key' }, count: { $sum: 1 } } },
|
||||
{ $project: { _id: 1, count: '$count' } },
|
||||
];
|
||||
db.collection('objects').aggregate(pipeline, function (err, results) {
|
||||
if (err) {
|
||||
@@ -198,7 +198,7 @@ module.exports = function (db, module) {
|
||||
}
|
||||
value = helpers.valueToString(value);
|
||||
method(key, 0, -1, function (err, result) {
|
||||
if(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -212,8 +212,8 @@ module.exports = function (db, module) {
|
||||
return callback(null, []);
|
||||
}
|
||||
var data = new Array(values.length);
|
||||
for (var i = 0; i < values.length; ++i) {
|
||||
data[i] = {key: keys[i], value: values[i]};
|
||||
for (var i = 0; i < values.length; i += 1) {
|
||||
data[i] = { key: keys[i], value: values[i] };
|
||||
}
|
||||
|
||||
async.map(data, function (item, next) {
|
||||
@@ -244,7 +244,7 @@ module.exports = function (db, module) {
|
||||
return callback();
|
||||
}
|
||||
value = helpers.valueToString(value);
|
||||
db.collection('objects').findOne({_key: key, value: value}, {fields:{_id: 0, score: 1}}, function (err, result) {
|
||||
db.collection('objects').findOne({ _key: key, value: value }, { fields: { _id: 0, score: 1 } }, function (err, result) {
|
||||
callback(err, result ? result.score : null);
|
||||
});
|
||||
};
|
||||
@@ -254,16 +254,16 @@ module.exports = function (db, module) {
|
||||
return callback();
|
||||
}
|
||||
value = helpers.valueToString(value);
|
||||
db.collection('objects').find({_key:{$in:keys}, value: value}, {_id:0, _key:1, score: 1}).toArray(function (err, result) {
|
||||
db.collection('objects').find({ _key: { $in: keys }, value: value }, { _id: 0, _key: 1, score: 1 }).toArray(function (err, result) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var map = helpers.toMap(result),
|
||||
returnData = [],
|
||||
item;
|
||||
var map = helpers.toMap(result);
|
||||
var returnData = [];
|
||||
var item;
|
||||
|
||||
for(var i = 0; i < keys.length; ++i) {
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
item = map[keys[i]];
|
||||
returnData.push(item ? item.score : null);
|
||||
}
|
||||
@@ -277,7 +277,7 @@ module.exports = function (db, module) {
|
||||
return callback();
|
||||
}
|
||||
values = values.map(helpers.valueToString);
|
||||
db.collection('objects').find({_key: key, value: {$in: values}}, {_id: 0, value: 1, score: 1}).toArray(function (err, result) {
|
||||
db.collection('objects').find({ _key: key, value: { $in: values } }, { _id: 0, value: 1, score: 1 }).toArray(function (err, result) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -290,7 +290,7 @@ module.exports = function (db, module) {
|
||||
var returnData = new Array(values.length);
|
||||
var score;
|
||||
|
||||
for(var i = 0; i < values.length; ++i) {
|
||||
for (var i = 0; i < values.length; i += 1) {
|
||||
score = map[values[i]];
|
||||
returnData[i] = utils.isNumber(score) ? score : null;
|
||||
}
|
||||
@@ -304,7 +304,7 @@ module.exports = function (db, module) {
|
||||
return callback();
|
||||
}
|
||||
value = helpers.valueToString(value);
|
||||
db.collection('objects').findOne({_key: key, value: value}, {_id: 0, value: 1}, function (err, result) {
|
||||
db.collection('objects').findOne({ _key: key, value: value }, { _id: 0, value: 1 }, function (err, result) {
|
||||
callback(err, !!result);
|
||||
});
|
||||
};
|
||||
@@ -314,7 +314,7 @@ module.exports = function (db, module) {
|
||||
return callback();
|
||||
}
|
||||
values = values.map(helpers.valueToString);
|
||||
db.collection('objects').find({_key: key, value: {$in: values}}, {fields: {_id: 0, value: 1}}).toArray(function (err, results) {
|
||||
db.collection('objects').find({ _key: key, value: { $in: values } }, { fields: { _id: 0, value: 1 } }).toArray(function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -335,7 +335,7 @@ module.exports = function (db, module) {
|
||||
return callback();
|
||||
}
|
||||
value = helpers.valueToString(value);
|
||||
db.collection('objects').find({_key: {$in: keys}, value: value}, {fields: {_id: 0, _key: 1, value: 1}}).toArray(function (err, results) {
|
||||
db.collection('objects').find({ _key: { $in: keys }, value: value }, { fields: { _id: 0, _key: 1, value: 1 } }).toArray(function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -355,20 +355,20 @@ module.exports = function (db, module) {
|
||||
if (!Array.isArray(keys) || !keys.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
db.collection('objects').find({_key: {$in: keys}}, {_id: 0, _key: 1, value: 1}).toArray(function (err, data) {
|
||||
db.collection('objects').find({ _key: { $in: keys } }, { _id: 0, _key: 1, value: 1 }).toArray(function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var sets = {};
|
||||
data.forEach(function (set) {
|
||||
sets[set._key] = sets[set._key] || [];
|
||||
sets[set._key].push(set.value);
|
||||
sets[set._key] = sets[set._key] || [];
|
||||
sets[set._key].push(set.value);
|
||||
});
|
||||
|
||||
var returnData = new Array(keys.length);
|
||||
for(var i = 0; i < keys.length; ++i) {
|
||||
returnData[i] = sets[keys[i]] || [];
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
returnData[i] = sets[keys[i]] || [];
|
||||
}
|
||||
callback(null, returnData);
|
||||
});
|
||||
@@ -383,7 +383,7 @@ module.exports = function (db, module) {
|
||||
value = helpers.valueToString(value);
|
||||
data.score = parseFloat(increment);
|
||||
|
||||
db.collection('objects').findAndModify({_key: key, value: value}, {}, {$inc: data}, {new: true, upsert: true}, function (err, result) {
|
||||
db.collection('objects').findAndModify({ _key: key, value: value }, {}, { $inc: data }, { new: true, upsert: true }, function (err, result) {
|
||||
// if there is duplicate key error retry the upsert
|
||||
// https://github.com/NodeBB/NodeBB/issues/4467
|
||||
// https://jira.mongodb.org/browse/SERVER-14322
|
||||
@@ -416,11 +416,11 @@ module.exports = function (db, module) {
|
||||
count = 0;
|
||||
}
|
||||
|
||||
var query = {_key: key};
|
||||
var query = { _key: key };
|
||||
buildLexQuery(query, min, max);
|
||||
|
||||
db.collection('objects').find(query, {_id: 0, value: 1})
|
||||
.sort({value: sort})
|
||||
db.collection('objects').find(query, { _id: 0, value: 1 })
|
||||
.sort({ value: sort })
|
||||
.skip(start)
|
||||
.limit(count === -1 ? 0 : count)
|
||||
.toArray(function (err, data) {
|
||||
@@ -431,13 +431,13 @@ module.exports = function (db, module) {
|
||||
return item && item.value;
|
||||
});
|
||||
callback(err, data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.sortedSetRemoveRangeByLex = function (key, min, max, callback) {
|
||||
callback = callback || helpers.noop;
|
||||
|
||||
var query = {_key: key};
|
||||
var query = { _key: key };
|
||||
buildLexQuery(query, min, max);
|
||||
|
||||
db.collection('objects').remove(query, function (err) {
|
||||
@@ -448,11 +448,11 @@ module.exports = function (db, module) {
|
||||
function buildLexQuery(query, min, max) {
|
||||
if (min !== '-') {
|
||||
if (min.match(/^\(/)) {
|
||||
query.value = {$gt: min.slice(1)};
|
||||
query.value = { $gt: min.slice(1) };
|
||||
} else if (min.match(/^\[/)) {
|
||||
query.value = {$gte: min.slice(1)};
|
||||
query.value = { $gte: min.slice(1) };
|
||||
} else {
|
||||
query.value = {$gte: min};
|
||||
query.value = { $gte: min };
|
||||
}
|
||||
}
|
||||
if (max !== '+') {
|
||||
@@ -470,9 +470,9 @@ module.exports = function (db, module) {
|
||||
module.processSortedSet = function (setKey, process, batch, callback) {
|
||||
var done = false;
|
||||
var ids = [];
|
||||
var cursor = db.collection('objects').find({_key: setKey})
|
||||
.sort({score: 1})
|
||||
.project({_id: 0, value: 1})
|
||||
var cursor = db.collection('objects').find({ _key: setKey })
|
||||
.sort({ score: 1 })
|
||||
.project({ _id: 0, value: 1 })
|
||||
.batchSize(batch);
|
||||
|
||||
async.whilst(
|
||||
@@ -503,5 +503,4 @@ module.exports = function (db, module) {
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (db, module) {
|
||||
|
||||
var helpers = module.helpers.mongo;
|
||||
|
||||
module.sortedSetAdd = function (key, score, value, callback) {
|
||||
@@ -15,7 +14,7 @@ module.exports = function (db, module) {
|
||||
|
||||
value = helpers.valueToString(value);
|
||||
|
||||
db.collection('objects').update({_key: key, value: value}, {$set: {score: parseFloat(score)}}, {upsert:true, w: 1}, function (err) {
|
||||
db.collection('objects').update({ _key: key, value: value }, { $set: { score: parseFloat(score) } }, { upsert: true, w: 1 }, function (err) {
|
||||
if (err && err.message.startsWith('E11000 duplicate key error')) {
|
||||
return process.nextTick(module.sortedSetAdd, key, score, value, callback);
|
||||
}
|
||||
@@ -35,8 +34,8 @@ module.exports = function (db, module) {
|
||||
|
||||
var bulk = db.collection('objects').initializeUnorderedBulkOp();
|
||||
|
||||
for(var i = 0; i < scores.length; ++i) {
|
||||
bulk.find({_key: key, value: values[i]}).upsert().updateOne({$set: {score: parseFloat(scores[i])}});
|
||||
for (var i = 0; i < scores.length; i += 1) {
|
||||
bulk.find({ _key: key, value: values[i] }).upsert().updateOne({ $set: { score: parseFloat(scores[i]) } });
|
||||
}
|
||||
|
||||
bulk.execute(function (err) {
|
||||
@@ -53,13 +52,12 @@ module.exports = function (db, module) {
|
||||
|
||||
var bulk = db.collection('objects').initializeUnorderedBulkOp();
|
||||
|
||||
for(var i = 0; i < keys.length; ++i) {
|
||||
bulk.find({_key: keys[i], value: value}).upsert().updateOne({$set: {score: parseFloat(score)}});
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
bulk.find({ _key: keys[i], value: value }).upsert().updateOne({ $set: { score: parseFloat(score) } });
|
||||
}
|
||||
|
||||
bulk.execute(function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (db, module) {
|
||||
|
||||
module.sortedSetIntersectCard = function (keys, callback) {
|
||||
if (!Array.isArray(keys) || !keys.length) {
|
||||
return callback(null, 0);
|
||||
}
|
||||
|
||||
var pipeline = [
|
||||
{ $match: { _key: {$in: keys}} },
|
||||
{ $group: { _id: {value: '$value'}, count: {$sum: 1}} },
|
||||
{ $match: { count: keys.length} },
|
||||
{ $group: { _id: null, count: { $sum: 1 } } }
|
||||
{ $match: { _key: { $in: keys } } },
|
||||
{ $group: { _id: { value: '$value' }, count: { $sum: 1 } } },
|
||||
{ $match: { count: keys.length } },
|
||||
{ $group: { _id: null, count: { $sum: 1 } } },
|
||||
];
|
||||
|
||||
db.collection('objects').aggregate(pipeline, function (err, data) {
|
||||
@@ -48,7 +47,7 @@ module.exports = function (db, module) {
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
var pipeline = [{ $match: { _key: {$in: sets}} }];
|
||||
var pipeline = [{ $match: { _key: { $in: sets } } }];
|
||||
|
||||
weights.forEach(function (weight, index) {
|
||||
if (weight !== 1) {
|
||||
@@ -56,16 +55,24 @@ module.exports = function (db, module) {
|
||||
$project: {
|
||||
value: 1,
|
||||
score: {
|
||||
$cond: { if: { $eq: [ "$_key", sets[index] ] }, then: { $multiply: [ '$score', weight ] }, else: '$score' }
|
||||
}
|
||||
}
|
||||
$cond: {
|
||||
if: {
|
||||
$eq: ['$_key', sets[index]],
|
||||
},
|
||||
then: {
|
||||
$multiply: ['$score', weight],
|
||||
},
|
||||
else: '$score',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
pipeline.push({ $group: { _id: {value: '$value'}, totalScore: aggregate, count: {$sum: 1}} });
|
||||
pipeline.push({ $match: { count: sets.length} });
|
||||
pipeline.push({ $sort: { totalScore: params.sort} });
|
||||
pipeline.push({ $group: { _id: { value: '$value' }, totalScore: aggregate, count: { $sum: 1 } } });
|
||||
pipeline.push({ $match: { count: sets.length } });
|
||||
pipeline.push({ $sort: { totalScore: params.sort } });
|
||||
|
||||
if (start) {
|
||||
pipeline.push({ $skip: start });
|
||||
@@ -75,7 +82,7 @@ module.exports = function (db, module) {
|
||||
pipeline.push({ $limit: limit });
|
||||
}
|
||||
|
||||
var project = { _id: 0, value: '$_id.value'};
|
||||
var project = { _id: 0, value: '$_id.value' };
|
||||
if (params.withScores) {
|
||||
project.score = '$totalScore';
|
||||
}
|
||||
@@ -95,5 +102,4 @@ module.exports = function (db, module) {
|
||||
callback(null, data);
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (db, module) {
|
||||
|
||||
var helpers = module.helpers.mongo;
|
||||
|
||||
module.sortedSetRemove = function (key, value, callback) {
|
||||
@@ -15,10 +14,10 @@ module.exports = function (db, module) {
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
value = value.map(helpers.valueToString);
|
||||
db.collection('objects').remove({_key: key, value: {$in: value}}, done);
|
||||
db.collection('objects').remove({ _key: key, value: { $in: value } }, done);
|
||||
} else {
|
||||
value = helpers.valueToString(value);
|
||||
db.collection('objects').remove({_key: key, value: value}, done);
|
||||
db.collection('objects').remove({ _key: key, value: value }, done);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -29,7 +28,7 @@ module.exports = function (db, module) {
|
||||
}
|
||||
value = helpers.valueToString(value);
|
||||
|
||||
db.collection('objects').remove({_key: {$in: keys}, value: value}, function (err) {
|
||||
db.collection('objects').remove({ _key: { $in: keys }, value: value }, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -39,10 +38,10 @@ module.exports = function (db, module) {
|
||||
if (!Array.isArray(keys) || !keys.length) {
|
||||
return callback();
|
||||
}
|
||||
var query = {_key: {$in: keys}};
|
||||
var query = { _key: { $in: keys } };
|
||||
|
||||
if (min !== '-inf') {
|
||||
query.score = {$gte: min};
|
||||
query.score = { $gte: min };
|
||||
}
|
||||
if (max !== '+inf') {
|
||||
query.score = query.score || {};
|
||||
@@ -53,5 +52,4 @@ module.exports = function (db, module) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (db, module) {
|
||||
|
||||
module.sortedSetUnionCard = function (keys, callback) {
|
||||
if (!Array.isArray(keys) || !keys.length) {
|
||||
return callback(null, 0);
|
||||
}
|
||||
|
||||
var pipeline = [
|
||||
{ $match: { _key: {$in: keys} } },
|
||||
{ $group: { _id: {value: '$value' } } },
|
||||
{ $group: { _id: null, count: { $sum: 1 } } }
|
||||
{ $match: { _key: { $in: keys } } },
|
||||
{ $group: { _id: { value: '$value' } } },
|
||||
{ $group: { _id: null, count: { $sum: 1 } } },
|
||||
];
|
||||
|
||||
var project = { _id: 0, count: '$count' };
|
||||
@@ -48,9 +47,9 @@ module.exports = function (db, module) {
|
||||
}
|
||||
|
||||
var pipeline = [
|
||||
{ $match: { _key: {$in: params.sets}} },
|
||||
{ $group: { _id: {value: '$value'}, totalScore: aggregate} },
|
||||
{ $sort: { totalScore: params.sort} }
|
||||
{ $match: { _key: { $in: params.sets } } },
|
||||
{ $group: { _id: { value: '$value' }, totalScore: aggregate } },
|
||||
{ $sort: { totalScore: params.sort } },
|
||||
];
|
||||
|
||||
if (params.start) {
|
||||
@@ -81,5 +80,4 @@ module.exports = function (db, module) {
|
||||
callback(null, data);
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,38 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
(function (module) {
|
||||
|
||||
var winston = require('winston');
|
||||
var nconf = require('nconf');
|
||||
var semver = require('semver');
|
||||
var session = require('express-session');
|
||||
var redis;
|
||||
var connectRedis;
|
||||
var redisClient;
|
||||
|
||||
module.questions = [
|
||||
{
|
||||
name: 'redis:host',
|
||||
description: 'Host IP or address of your Redis instance',
|
||||
'default': nconf.get('redis:host') || '127.0.0.1'
|
||||
default: nconf.get('redis:host') || '127.0.0.1',
|
||||
},
|
||||
{
|
||||
name: 'redis:port',
|
||||
description: 'Host port of your Redis instance',
|
||||
'default': nconf.get('redis:port') || 6379
|
||||
default: nconf.get('redis:port') || 6379,
|
||||
},
|
||||
{
|
||||
name: 'redis:password',
|
||||
description: 'Password of your Redis database',
|
||||
hidden: true,
|
||||
default: nconf.get('redis:password') || '',
|
||||
before: function (value) { value = value || nconf.get('redis:password') || ''; return value; }
|
||||
before: function (value) { value = value || nconf.get('redis:password') || ''; return value; },
|
||||
},
|
||||
{
|
||||
name: "redis:database",
|
||||
description: "Which database to use (0..n)",
|
||||
'default': nconf.get('redis:database') || 0
|
||||
}
|
||||
name: 'redis:database',
|
||||
description: 'Which database to use (0..n)',
|
||||
default: nconf.get('redis:database') || 0,
|
||||
},
|
||||
];
|
||||
|
||||
module.init = function (callback) {
|
||||
@@ -68,7 +66,7 @@
|
||||
|
||||
module.sessionStore = new sessionStore({
|
||||
client: module.client,
|
||||
ttl: ttl
|
||||
ttl: ttl,
|
||||
});
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
@@ -110,7 +108,7 @@
|
||||
if (dbIdx) {
|
||||
cxn.select(dbIdx, function (error) {
|
||||
if (error) {
|
||||
winston.error("NodeBB could not connect to your Redis database. Redis returned the following error: " + error.message);
|
||||
winston.error('NodeBB could not connect to your Redis database. Redis returned the following error: ' + error.message);
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
@@ -150,7 +148,7 @@
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var lines = data.toString().split("\r\n").sort();
|
||||
var lines = data.toString().split('\r\n').sort();
|
||||
var redisData = {};
|
||||
lines.forEach(function (line) {
|
||||
var parts = line.split(':');
|
||||
@@ -168,5 +166,5 @@
|
||||
|
||||
module.helpers = module.helpers || {};
|
||||
module.helpers.redis = require('./redis/helpers');
|
||||
} (exports));
|
||||
}(exports));
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
module.exports = function (redisClient, module) {
|
||||
|
||||
var helpers = module.helpers.redis;
|
||||
|
||||
module.setObject = function (key, data, callback) {
|
||||
@@ -52,14 +51,14 @@ module.exports = function (redisClient, module) {
|
||||
}
|
||||
var multi = redisClient.multi();
|
||||
|
||||
for(var x = 0; x < keys.length; ++x) {
|
||||
for (var x = 0; x < keys.length; x += 1) {
|
||||
multi.hmget.apply(multi, [keys[x]].concat(fields));
|
||||
}
|
||||
|
||||
function makeObject(array) {
|
||||
var obj = {};
|
||||
|
||||
for (var i = 0, ii = fields.length; i < ii; ++i) {
|
||||
for (var i = 0, ii = fields.length; i < ii; i += 1) {
|
||||
obj[fields[i]] = array[i];
|
||||
}
|
||||
return obj;
|
||||
@@ -97,13 +96,13 @@ module.exports = function (redisClient, module) {
|
||||
|
||||
module.deleteObjectField = function (key, field, callback) {
|
||||
callback = callback || function () {};
|
||||
redisClient.hdel(key, field, function (err, res) {
|
||||
redisClient.hdel(key, field, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
module.deleteObjectFields = function (key, fields, callback) {
|
||||
helpers.multiKeyValues(redisClient, 'hdel', key, fields, function (err, results) {
|
||||
helpers.multiKeyValues(redisClient, 'hdel', key, fields, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -119,4 +118,4 @@ module.exports = function (redisClient, module) {
|
||||
module.incrObjectFieldBy = function (key, field, value, callback) {
|
||||
redisClient.hincrby(key, field, value, callback);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var helpers = {};
|
||||
|
||||
helpers.multiKeys = function (redisClient, command, keys, callback) {
|
||||
callback = callback || function () {};
|
||||
var multi = redisClient.multi();
|
||||
for (var i = 0; i < keys.length; ++i) {
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
multi[command](keys[i]);
|
||||
}
|
||||
multi.exec(callback);
|
||||
@@ -14,7 +14,7 @@ helpers.multiKeys = function (redisClient, command, keys, callback) {
|
||||
helpers.multiKeysValue = function (redisClient, command, keys, value, callback) {
|
||||
callback = callback || function () {};
|
||||
var multi = redisClient.multi();
|
||||
for (var i = 0; i < keys.length; ++i) {
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
multi[command](keys[i], value);
|
||||
}
|
||||
multi.exec(callback);
|
||||
@@ -23,17 +23,17 @@ helpers.multiKeysValue = function (redisClient, command, keys, value, callback)
|
||||
helpers.multiKeyValues = function (redisClient, command, key, values, callback) {
|
||||
callback = callback || function () {};
|
||||
var multi = redisClient.multi();
|
||||
for (var i = 0; i < values.length; ++i) {
|
||||
for (var i = 0; i < values.length; i += 1) {
|
||||
multi[command](key, values[i]);
|
||||
}
|
||||
multi.exec(callback);
|
||||
};
|
||||
|
||||
helpers.resultsToBool = function (results) {
|
||||
for (var i = 0; i < results.length; ++i) {
|
||||
for (var i = 0; i < results.length; i += 1) {
|
||||
results[i] = results[i] === 1;
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
module.exports = helpers;
|
||||
module.exports = helpers;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
module.exports = function (redisClient, module) {
|
||||
module.listPrepend = function (key, value, callback) {
|
||||
callback = callback || function () {};
|
||||
redisClient.lpush(key, value, function (err, res) {
|
||||
redisClient.lpush(key, value, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
module.listAppend = function (key, value, callback) {
|
||||
callback = callback || function () {};
|
||||
redisClient.rpush(key, value, function (err, res) {
|
||||
redisClient.rpush(key, value, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -22,14 +22,14 @@ module.exports = function (redisClient, module) {
|
||||
|
||||
module.listRemoveAll = function (key, value, callback) {
|
||||
callback = callback || function () {};
|
||||
redisClient.lrem(key, 0, value, function (err, res) {
|
||||
redisClient.lrem(key, 0, value, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
module.listTrim = function (key, start, stop, callback) {
|
||||
callback = callback || function () {};
|
||||
redisClient.ltrim(key, start, stop, function (err, res) {
|
||||
redisClient.ltrim(key, start, stop, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -38,4 +38,4 @@ module.exports = function (redisClient, module) {
|
||||
callback = callback || function () {};
|
||||
redisClient.lrange(key, start, stop, callback);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
module.exports = function (redisClient, module) {
|
||||
|
||||
module.flushdb = function (callback) {
|
||||
redisClient.send_command('flushdb', [], function (err) {
|
||||
if (typeof callback === 'function') {
|
||||
@@ -22,7 +21,7 @@ module.exports = function (redisClient, module) {
|
||||
|
||||
module.delete = function (key, callback) {
|
||||
callback = callback || function () {};
|
||||
redisClient.del(key, function (err, res) {
|
||||
redisClient.del(key, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -30,10 +29,10 @@ module.exports = function (redisClient, module) {
|
||||
module.deleteAll = function (keys, callback) {
|
||||
callback = callback || function () {};
|
||||
var multi = redisClient.multi();
|
||||
for(var i = 0; i < keys.length; ++i) {
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
multi.del(keys[i]);
|
||||
}
|
||||
multi.exec(function (err, res) {
|
||||
multi.exec(function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -56,7 +55,7 @@ module.exports = function (redisClient, module) {
|
||||
|
||||
module.rename = function (oldKey, newKey, callback) {
|
||||
callback = callback || function () {};
|
||||
redisClient.rename(oldKey, newKey, function (err, res) {
|
||||
redisClient.rename(oldKey, newKey, function (err) {
|
||||
callback(err && err.message !== 'ERR no such key' ? err : null);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
module.exports = function (redisClient, module) {
|
||||
var helpers = module.helpers.redis;
|
||||
@@ -11,28 +11,28 @@ module.exports = function (redisClient, module) {
|
||||
if (!value.length) {
|
||||
return callback();
|
||||
}
|
||||
redisClient.sadd(key, value, function (err, res) {
|
||||
redisClient.sadd(key, value, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
module.setsAdd = function (keys, value, callback) {
|
||||
callback = callback || function () {};
|
||||
helpers.multiKeysValue(redisClient, 'sadd', keys, value, function (err, res) {
|
||||
helpers.multiKeysValue(redisClient, 'sadd', keys, value, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
module.setRemove = function (key, value, callback) {
|
||||
callback = callback || function () {};
|
||||
redisClient.srem(key, value, function (err, res) {
|
||||
redisClient.srem(key, value, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
module.setsRemove = function (keys, value, callback) {
|
||||
callback = callback || function () {};
|
||||
helpers.multiKeysValue(redisClient, 'srem', keys, value, function (err, res) {
|
||||
helpers.multiKeysValue(redisClient, 'srem', keys, value, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -77,4 +77,4 @@ module.exports = function (redisClient, module) {
|
||||
};
|
||||
|
||||
return module;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
module.exports = function (redisClient, module) {
|
||||
|
||||
var utils = require('../../../public/src/utils');
|
||||
|
||||
var helpers = module.helpers.redis;
|
||||
@@ -29,7 +28,7 @@ module.exports = function (redisClient, module) {
|
||||
|
||||
function sortedSetRange(method, key, start, stop, withScores, callback) {
|
||||
if (Array.isArray(key)) {
|
||||
return module.sortedSetUnion({method: method, sets: key, start: start, stop: stop, withScores: withScores}, callback);
|
||||
return module.sortedSetUnion({ method: method, sets: key, start: start, stop: stop, withScores: withScores }, callback);
|
||||
}
|
||||
|
||||
var params = [key, start, stop];
|
||||
@@ -45,8 +44,8 @@ module.exports = function (redisClient, module) {
|
||||
return callback(null, data);
|
||||
}
|
||||
var objects = [];
|
||||
for(var i = 0; i < data.length; i += 2) {
|
||||
objects.push({value: data[i], score: parseFloat(data[i + 1])});
|
||||
for (var i = 0; i < data.length; i += 2) {
|
||||
objects.push({ value: data[i], score: parseFloat(data[i + 1]) });
|
||||
}
|
||||
callback(null, objects);
|
||||
});
|
||||
@@ -74,8 +73,8 @@ module.exports = function (redisClient, module) {
|
||||
return callback(err);
|
||||
}
|
||||
var objects = [];
|
||||
for(var i = 0; i < data.length; i += 2) {
|
||||
objects.push({value: data[i], score: parseFloat(data[i + 1])});
|
||||
for (var i = 0; i < data.length; i += 2) {
|
||||
objects.push({ value: data[i], score: parseFloat(data[i + 1]) });
|
||||
}
|
||||
callback(null, objects);
|
||||
});
|
||||
@@ -94,7 +93,7 @@ module.exports = function (redisClient, module) {
|
||||
return callback(null, []);
|
||||
}
|
||||
var multi = redisClient.multi();
|
||||
for(var i = 0; i < keys.length; ++i) {
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
multi.zcard(keys[i]);
|
||||
}
|
||||
multi.exec(callback);
|
||||
@@ -106,7 +105,7 @@ module.exports = function (redisClient, module) {
|
||||
|
||||
module.sortedSetsRanks = function (keys, values, callback) {
|
||||
var multi = redisClient.multi();
|
||||
for(var i = 0; i < values.length; ++i) {
|
||||
for (var i = 0; i < values.length; i += 1) {
|
||||
multi.zrank(keys[i], values[i]);
|
||||
}
|
||||
multi.exec(callback);
|
||||
@@ -114,7 +113,7 @@ module.exports = function (redisClient, module) {
|
||||
|
||||
module.sortedSetRanks = function (key, values, callback) {
|
||||
var multi = redisClient.multi();
|
||||
for(var i = 0; i < values.length; ++i) {
|
||||
for (var i = 0; i < values.length; i += 1) {
|
||||
multi.zrank(key, values[i]);
|
||||
}
|
||||
multi.exec(callback);
|
||||
@@ -164,7 +163,7 @@ module.exports = function (redisClient, module) {
|
||||
|
||||
module.getSortedSetsMembers = function (keys, callback) {
|
||||
var multi = redisClient.multi();
|
||||
for (var i = 0; i < keys.length; ++i) {
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
multi.zrange(keys[i], 0, -1);
|
||||
}
|
||||
multi.exec(callback);
|
||||
@@ -198,7 +197,8 @@ module.exports = function (redisClient, module) {
|
||||
function sortedSetLex(method, reverse, key, min, max, start, count, callback) {
|
||||
callback = callback || start;
|
||||
|
||||
var minmin, maxmax;
|
||||
var minmin;
|
||||
var maxmax;
|
||||
if (reverse) {
|
||||
minmin = '+';
|
||||
maxmax = '-';
|
||||
@@ -207,10 +207,10 @@ module.exports = function (redisClient, module) {
|
||||
maxmax = '+';
|
||||
}
|
||||
|
||||
if (min !== minmin && !min.match(/^[\[\(]/)) {
|
||||
if (min !== minmin && !min.match(/^[[(]/)) {
|
||||
min = '[' + min;
|
||||
}
|
||||
if (max !== maxmax && !max.match(/^[\[\(]/)) {
|
||||
if (max !== maxmax && !max.match(/^[[(]/)) {
|
||||
max = '[' + max;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (redisClient, module) {
|
||||
|
||||
module.sortedSetAdd = function (key, score, value, callback) {
|
||||
callback = callback || function () {};
|
||||
if (Array.isArray(score) && Array.isArray(value)) {
|
||||
@@ -23,7 +22,7 @@ module.exports = function (redisClient, module) {
|
||||
|
||||
var args = [key];
|
||||
|
||||
for(var i = 0; i < scores.length; ++i) {
|
||||
for (var i = 0; i < scores.length; i += 1) {
|
||||
args.push(scores[i], values[i]);
|
||||
}
|
||||
|
||||
@@ -36,7 +35,7 @@ module.exports = function (redisClient, module) {
|
||||
callback = callback || function () {};
|
||||
var multi = redisClient.multi();
|
||||
|
||||
for(var i = 0; i < keys.length; ++i) {
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
multi.zadd(keys[i], score, value);
|
||||
}
|
||||
|
||||
@@ -44,6 +43,4 @@ module.exports = function (redisClient, module) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (redisClient, module) {
|
||||
|
||||
module.sortedSetIntersectCard = function (keys, callback) {
|
||||
if (!Array.isArray(keys) || !keys.length) {
|
||||
return callback(null, 0);
|
||||
@@ -70,10 +69,10 @@ module.exports = function (redisClient, module) {
|
||||
}
|
||||
results = results[1] || [];
|
||||
var objects = [];
|
||||
for(var i = 0; i < results.length; i += 2) {
|
||||
objects.push({value: results[i], score: parseFloat(results[i + 1])});
|
||||
for (var i = 0; i < results.length; i += 2) {
|
||||
objects.push({ value: results[i], score: parseFloat(results[i + 1]) });
|
||||
}
|
||||
callback(null, objects);
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (redisClient, module) {
|
||||
|
||||
var helpers = module.helpers.redis;
|
||||
|
||||
module.sortedSetRemove = function (key, value, callback) {
|
||||
@@ -28,11 +27,11 @@ module.exports = function (redisClient, module) {
|
||||
module.sortedSetsRemoveRangeByScore = function (keys, min, max, callback) {
|
||||
callback = callback || function () {};
|
||||
var multi = redisClient.multi();
|
||||
for(var i = 0; i < keys.length; ++i) {
|
||||
for (var i = 0; i < keys.length; i += 1) {
|
||||
multi.zremrangebyscore(keys[i], min, max);
|
||||
}
|
||||
multi.exec(function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (redisClient, module) {
|
||||
|
||||
module.sortedSetUnionCard = function (keys, callback) {
|
||||
var tempSetName = 'temp_' + Date.now();
|
||||
|
||||
@@ -30,7 +29,6 @@ module.exports = function (redisClient, module) {
|
||||
};
|
||||
|
||||
module.sortedSetUnion = function (params, callback) {
|
||||
|
||||
var tempSetName = 'temp_' + Date.now();
|
||||
|
||||
var rangeParams = [tempSetName, params.start, params.stop];
|
||||
@@ -51,10 +49,10 @@ module.exports = function (redisClient, module) {
|
||||
}
|
||||
results = results[1] || [];
|
||||
var objects = [];
|
||||
for(var i = 0; i < results.length; i += 2) {
|
||||
objects.push({value: results[i], score: parseFloat(results[i + 1])});
|
||||
for (var i = 0; i < results.length; i += 2) {
|
||||
objects.push({ value: results[i], score: parseFloat(results[i + 1]) });
|
||||
}
|
||||
callback(null, objects);
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var winston = require('winston');
|
||||
@@ -17,7 +17,7 @@ var translator = require('../public/src/modules/translator');
|
||||
|
||||
var transports = {
|
||||
sendmail: nodemailer.createTransport(sendmailTransport()),
|
||||
gmail: undefined
|
||||
gmail: undefined,
|
||||
};
|
||||
|
||||
var app;
|
||||
@@ -29,15 +29,16 @@ var fallbackTransport;
|
||||
|
||||
// Enable Gmail transport if enabled in ACP
|
||||
if (parseInt(meta.config['email:GmailTransport:enabled'], 10) === 1) {
|
||||
fallbackTransport = transports.gmail = nodemailer.createTransport(smtpTransport({
|
||||
transports.gmail = nodemailer.createTransport(smtpTransport({
|
||||
host: 'smtp.gmail.com',
|
||||
port: 465,
|
||||
secure: true,
|
||||
auth: {
|
||||
user: meta.config['email:GmailTransport:user'],
|
||||
pass: meta.config['email:GmailTransport:pass']
|
||||
}
|
||||
pass: meta.config['email:GmailTransport:pass'],
|
||||
},
|
||||
}));
|
||||
fallbackTransport = transports.gmail;
|
||||
} else {
|
||||
fallbackTransport = transports.sendmail;
|
||||
}
|
||||
@@ -56,7 +57,7 @@ var fallbackTransport;
|
||||
function (next) {
|
||||
async.parallel({
|
||||
email: async.apply(User.getUserField, uid, 'email'),
|
||||
settings: async.apply(User.getSettings, uid)
|
||||
settings: async.apply(User.getSettings, uid),
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -66,7 +67,7 @@ var fallbackTransport;
|
||||
}
|
||||
params.uid = uid;
|
||||
Emailer.sendToEmail(template, results.email, results.settings.userLang, params, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -85,7 +86,7 @@ var fallbackTransport;
|
||||
translator.translate(params.subject, lang, function (translated) {
|
||||
next(null, translated);
|
||||
});
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -97,12 +98,12 @@ var fallbackTransport;
|
||||
subject: results.subject,
|
||||
html: results.html,
|
||||
plaintext: htmlToText.fromString(results.html, {
|
||||
ignoreImage: true
|
||||
ignoreImage: true,
|
||||
}),
|
||||
template: template,
|
||||
uid: params.uid,
|
||||
pid: params.pid,
|
||||
fromUid: params.fromUid
|
||||
fromUid: params.fromUid,
|
||||
};
|
||||
Plugins.fireHook('filter:email.modify', data, next);
|
||||
},
|
||||
@@ -112,7 +113,7 @@ var fallbackTransport;
|
||||
} else {
|
||||
Emailer.sendViaFallback(data, next);
|
||||
}
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
if (err && err.code === 'ENOENT') {
|
||||
callback(new Error('[[error:sendmail-not-found]]'));
|
||||
@@ -163,6 +164,5 @@ var fallbackTransport;
|
||||
|
||||
return parsed.hostname;
|
||||
}
|
||||
|
||||
}(module.exports));
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var eventEmitter = new (require('events')).EventEmitter();
|
||||
|
||||
@@ -32,4 +32,4 @@ eventEmitter.any = function (events, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = eventEmitter;
|
||||
module.exports = eventEmitter;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
var async = require('async');
|
||||
var validator = require('validator');
|
||||
|
||||
var db = require('./database');
|
||||
var db = require('./database');
|
||||
var batch = require('./batch');
|
||||
var user = require('./user');
|
||||
var utils = require('../public/src/utils');
|
||||
@@ -27,10 +27,10 @@ var utils = require('../public/src/utils');
|
||||
},
|
||||
function (next) {
|
||||
db.setObject('event:' + eid, data, next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
}
|
||||
], function (err, result) {
|
||||
},
|
||||
], function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
@@ -61,12 +61,16 @@ var utils = require('../public/src/utils');
|
||||
}
|
||||
});
|
||||
var e = utils.merge(event);
|
||||
e.eid = e.uid = e.type = e.ip = e.user = undefined;
|
||||
e.eid = undefined;
|
||||
e.uid = undefined;
|
||||
e.type = undefined;
|
||||
e.ip = undefined;
|
||||
e.user = undefined;
|
||||
event.jsonString = JSON.stringify(e, null, 4);
|
||||
event.timestampISO = new Date(parseInt(event.timestamp, 10)).toUTCString();
|
||||
});
|
||||
next(null, eventsData);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -87,7 +91,7 @@ var utils = require('../public/src/utils');
|
||||
},
|
||||
userData: function (next) {
|
||||
user.getUsersFields(uids, ['username', 'userslug', 'picture'], next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -121,7 +125,7 @@ var utils = require('../public/src/utils');
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetRemove('events:time', eids, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -130,8 +134,6 @@ var utils = require('../public/src/utils');
|
||||
|
||||
batch.processSortedSet('events:time', function (eids, next) {
|
||||
events.deleteEvents(eids, next);
|
||||
}, {alwaysStartAt: 0}, callback);
|
||||
}, { alwaysStartAt: 0 }, callback);
|
||||
};
|
||||
|
||||
|
||||
}(module.exports));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var nconf = require('nconf');
|
||||
@@ -35,7 +35,7 @@ file.saveFileToLocal = function (filename, folder, tempPath, callback) {
|
||||
is.on('end', function () {
|
||||
callback(null, {
|
||||
url: '/assets/uploads/' + folder + '/' + filename,
|
||||
path: uploadPath
|
||||
path: uploadPath,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -49,7 +49,7 @@ file.base64ToLocal = function (imageData, uploadPath, callback) {
|
||||
uploadPath = path.join(nconf.get('upload_path'), uploadPath);
|
||||
|
||||
fs.writeFile(uploadPath, buffer, {
|
||||
encoding: 'base64'
|
||||
encoding: 'base64',
|
||||
}, function (err) {
|
||||
callback(err, uploadPath);
|
||||
});
|
||||
@@ -119,8 +119,7 @@ file.existsSync = function (path) {
|
||||
file.link = function link(filePath, destPath, cb) {
|
||||
if (process.platform === 'win32') {
|
||||
fs.link(filePath, destPath, cb);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fs.symlink(filePath, destPath, 'file', cb);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,7 +11,6 @@ var privileges = require('./privileges');
|
||||
var utils = require('../public/src/utils');
|
||||
|
||||
(function (Groups) {
|
||||
|
||||
require('./groups/create')(Groups);
|
||||
require('./groups/delete')(Groups);
|
||||
require('./groups/update')(Groups);
|
||||
@@ -20,30 +19,29 @@ var utils = require('../public/src/utils');
|
||||
require('./groups/search')(Groups);
|
||||
require('./groups/cover')(Groups);
|
||||
|
||||
var ephemeralGroups = ['guests'],
|
||||
var ephemeralGroups = ['guests'];
|
||||
|
||||
internals = {
|
||||
getEphemeralGroup: function (groupName) {
|
||||
return {
|
||||
name: groupName,
|
||||
slug: utils.slugify(groupName),
|
||||
description: '',
|
||||
deleted: '0',
|
||||
hidden: '0',
|
||||
system: '1'
|
||||
};
|
||||
},
|
||||
removeEphemeralGroups: function (groups) {
|
||||
var x = groups.length;
|
||||
while(x--) {
|
||||
if (ephemeralGroups.indexOf(groups[x]) !== -1) {
|
||||
groups.splice(x, 1);
|
||||
}
|
||||
var internals = {
|
||||
getEphemeralGroup: function (groupName) {
|
||||
return {
|
||||
name: groupName,
|
||||
slug: utils.slugify(groupName),
|
||||
description: '',
|
||||
deleted: '0',
|
||||
hidden: '0',
|
||||
system: '1',
|
||||
};
|
||||
},
|
||||
removeEphemeralGroups: function (groups) {
|
||||
for (var x = groups.length; x >= 0; x -= 1) {
|
||||
if (ephemeralGroups.indexOf(groups[x]) !== -1) {
|
||||
groups.splice(x, 1);
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
};
|
||||
|
||||
return groups;
|
||||
},
|
||||
};
|
||||
|
||||
Groups.internals = internals;
|
||||
|
||||
@@ -73,7 +71,7 @@ var utils = require('../public/src/utils');
|
||||
}
|
||||
|
||||
Groups.getGroupsAndMembers(groupNames, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -88,7 +86,7 @@ var utils = require('../public/src/utils');
|
||||
},
|
||||
members: function (next) {
|
||||
Groups.getMemberUsers(groupNames, 0, 3, next);
|
||||
}
|
||||
},
|
||||
}, function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -132,7 +130,7 @@ var utils = require('../public/src/utils');
|
||||
},
|
||||
function (uids, next) {
|
||||
user.getUsersData(uids, next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
},
|
||||
invited: function (next) {
|
||||
@@ -142,13 +140,13 @@ var utils = require('../public/src/utils');
|
||||
},
|
||||
function (uids, next) {
|
||||
user.getUsersData(uids, next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
},
|
||||
isMember: async.apply(Groups.isMember, options.uid, groupName),
|
||||
isPending: async.apply(Groups.isPending, options.uid, groupName),
|
||||
isInvited: async.apply(Groups.isInvited, options.uid, groupName),
|
||||
isOwner: async.apply(Groups.ownership.isOwner, options.uid, groupName)
|
||||
isOwner: async.apply(Groups.ownership.isOwner, options.uid, groupName),
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -186,7 +184,7 @@ var utils = require('../public/src/utils');
|
||||
results.base.isInvited = results.isInvited;
|
||||
results.base.isOwner = results.isOwner;
|
||||
|
||||
plugins.fireHook('filter:group.get', {group: results.base}, function (err, data) {
|
||||
plugins.fireHook('filter:group.get', { group: results.base }, function (err, data) {
|
||||
callback(err, data ? data.group : null);
|
||||
});
|
||||
});
|
||||
@@ -206,12 +204,12 @@ var utils = require('../public/src/utils');
|
||||
},
|
||||
function (uids, next) {
|
||||
user.getUsers(uids, uid, next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
},
|
||||
members: function (next) {
|
||||
user.getUsersFromSet('group:' + groupName + ':members', uid, start, stop, next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -276,7 +274,7 @@ var utils = require('../public/src/utils');
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
plugins.fireHook('action:group.set', {field: field, value: value, type: 'set'});
|
||||
plugins.fireHook('action:group.set', { field: field, value: value, type: 'set' });
|
||||
callback();
|
||||
});
|
||||
};
|
||||
@@ -287,7 +285,7 @@ var utils = require('../public/src/utils');
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null, (parseInt(isPrivate, 10) === 0) ? false : true);
|
||||
callback(null, parseInt(isPrivate, 10) !== 0);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -304,15 +302,15 @@ var utils = require('../public/src/utils');
|
||||
Groups.exists = function (name, callback) {
|
||||
if (Array.isArray(name)) {
|
||||
var slugs = name.map(function (groupName) {
|
||||
return utils.slugify(groupName);
|
||||
});
|
||||
return utils.slugify(groupName);
|
||||
});
|
||||
async.parallel([
|
||||
function (next) {
|
||||
next(null, slugs.map(function (slug) {
|
||||
return ephemeralGroups.indexOf(slug) !== -1;
|
||||
}));
|
||||
},
|
||||
async.apply(db.isSortedSetMembers, 'groups:createtime', name)
|
||||
async.apply(db.isSortedSetMembers, 'groups:createtime', name),
|
||||
], function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -327,7 +325,7 @@ var utils = require('../public/src/utils');
|
||||
function (next) {
|
||||
next(null, ephemeralGroups.indexOf(slug) !== -1);
|
||||
},
|
||||
async.apply(db.isSortedSetMember, 'groups:createtime', name)
|
||||
async.apply(db.isSortedSetMember, 'groups:createtime', name),
|
||||
], function (err, results) {
|
||||
callback(err, !err ? (results[0] || results[1]) : null);
|
||||
});
|
||||
@@ -360,8 +358,8 @@ var utils = require('../public/src/utils');
|
||||
privileges.posts.filter('read', pids, uid, next);
|
||||
},
|
||||
function (pids, next) {
|
||||
posts.getPostSummaryByPids(pids, uid, {stripTags: false}, next);
|
||||
}
|
||||
posts.getPostSummaryByPids(pids, uid, { stripTags: false }, next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -408,7 +406,7 @@ var utils = require('../public/src/utils');
|
||||
group.hidden = parseInt(group.hidden, 10) === 1;
|
||||
group.system = parseInt(group.system, 10) === 1;
|
||||
group.private = (group.private === null || group.private === undefined) ? true : !!parseInt(group.private, 10);
|
||||
group.disableJoinRequests = parseInt(group.disableJoinRequests) === 1;
|
||||
group.disableJoinRequests = parseInt(group.disableJoinRequests, 10) === 1;
|
||||
|
||||
group['cover:url'] = group['cover:url'] || require('./coverPhoto').getDefaultGroupCover(group.name);
|
||||
group['cover:thumb:url'] = group['cover:thumb:url'] || group['cover:url'];
|
||||
@@ -416,7 +414,7 @@ var utils = require('../public/src/utils');
|
||||
}
|
||||
});
|
||||
|
||||
plugins.fireHook('filter:groups.get', {groups: groupData}, function (err, data) {
|
||||
plugins.fireHook('filter:groups.get', { groups: groupData }, function (err, data) {
|
||||
callback(err, data ? data.groups : null);
|
||||
});
|
||||
});
|
||||
@@ -448,8 +446,7 @@ var utils = require('../public/src/utils');
|
||||
Groups.getGroupsData(memberOf, next);
|
||||
});
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
}(module.exports));
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var crypto = require('crypto');
|
||||
var Jimp = require('jimp');
|
||||
var mime = require('mime');
|
||||
var winston = require('winston');
|
||||
@@ -14,7 +11,6 @@ var image = require('../image');
|
||||
var uploadsController = require('../controllers/uploads');
|
||||
|
||||
module.exports = function (Groups) {
|
||||
|
||||
Groups.updateCoverPosition = function (groupName, position, callback) {
|
||||
if (!groupName) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
@@ -23,7 +19,6 @@ module.exports = function (Groups) {
|
||||
};
|
||||
|
||||
Groups.updateCover = function (uid, data, callback) {
|
||||
|
||||
// Position only? That's fine
|
||||
if (!data.imageData && !data.file && data.position) {
|
||||
return Groups.updateCoverPosition(data.groupName, data.position, callback);
|
||||
@@ -45,7 +40,7 @@ module.exports = function (Groups) {
|
||||
uploadsController.uploadGroupCover(uid, {
|
||||
name: 'groupCover',
|
||||
path: tempPath,
|
||||
type: type
|
||||
type: type,
|
||||
}, next);
|
||||
},
|
||||
function (uploadData, next) {
|
||||
@@ -59,7 +54,7 @@ module.exports = function (Groups) {
|
||||
uploadsController.uploadGroupCover(uid, {
|
||||
name: 'groupCoverThumb',
|
||||
path: tempPath,
|
||||
type: type
|
||||
type: type,
|
||||
}, next);
|
||||
},
|
||||
function (uploadData, next) {
|
||||
@@ -71,13 +66,13 @@ module.exports = function (Groups) {
|
||||
} else {
|
||||
next(null);
|
||||
}
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
fs.unlink(tempPath, function (unlinkErr) {
|
||||
if (unlinkErr) {
|
||||
winston.error(unlinkErr);
|
||||
}
|
||||
callback(err, {url: url});
|
||||
callback(err, { url: url });
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -92,7 +87,7 @@ module.exports = function (Groups) {
|
||||
},
|
||||
function (image, next) {
|
||||
image.write(path, next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
callback(err);
|
||||
});
|
||||
@@ -101,5 +96,4 @@ module.exports = function (Groups) {
|
||||
Groups.removeCover = function (data, callback) {
|
||||
db.deleteObjectFields('group:' + data.groupName, ['cover:url', 'cover:thumb:url', 'cover:position'], callback);
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -7,7 +7,6 @@ var utils = require('../../public/src/utils');
|
||||
var db = require('../database');
|
||||
|
||||
module.exports = function (Groups) {
|
||||
|
||||
Groups.create = function (data, callback) {
|
||||
var system = isSystemGroup(data);
|
||||
var groupData;
|
||||
@@ -42,14 +41,14 @@ module.exports = function (Groups) {
|
||||
hidden: parseInt(data.hidden, 10) === 1 ? 1 : 0,
|
||||
system: system ? 1 : 0,
|
||||
private: isPrivate,
|
||||
disableJoinRequests: disableJoinRequests
|
||||
disableJoinRequests: disableJoinRequests,
|
||||
};
|
||||
plugins.fireHook('filter:group.create', {group: groupData, data: data}, next);
|
||||
plugins.fireHook('filter:group.create', { group: groupData, data: data }, next);
|
||||
},
|
||||
function (results, next) {
|
||||
var tasks = [
|
||||
async.apply(db.sortedSetAdd, 'groups:createtime', groupData.createtime, groupData.name),
|
||||
async.apply(db.setObject, 'group:' + groupData.name, groupData)
|
||||
async.apply(db.setObject, 'group:' + groupData.name, groupData),
|
||||
];
|
||||
|
||||
if (data.hasOwnProperty('ownerUid')) {
|
||||
@@ -72,9 +71,8 @@ module.exports = function (Groups) {
|
||||
function (results, next) {
|
||||
plugins.fireHook('action:group.create', {group: groupData});
|
||||
next(null, groupData);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
|
||||
};
|
||||
|
||||
function isSystemGroup(data) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user