mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-04 11:31:23 +01:00
Merge remote-tracking branch 'origin/master' into webserver.js-refactor
Conflicts: src/routes/user.js
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
"less-middleware": "0.1.12",
|
||||
"marked": "0.2.8",
|
||||
"async": "~0.2.8",
|
||||
"node-imagemagick": "0.1.8",
|
||||
"gm": "1.14.2",
|
||||
"gravatar": "1.0.6",
|
||||
"nconf": "~0.6.7",
|
||||
"sitemap": "~0.7.1",
|
||||
|
||||
36
src/image.js
36
src/image.js
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs'),
|
||||
imagemagick = require('node-imagemagick'),
|
||||
gm = require('gm').subClass({imageMagick: true}),
|
||||
meta = require('./meta');
|
||||
|
||||
var image = {};
|
||||
@@ -11,35 +12,26 @@ image.resizeImage = function(path, extension, width, height, callback) {
|
||||
}
|
||||
|
||||
if(extension === '.gif') {
|
||||
imagemagick.convert([
|
||||
path,
|
||||
'-coalesce',
|
||||
'-repage',
|
||||
'0x0',
|
||||
'-crop',
|
||||
width+'x'+height+'+0+0',
|
||||
'+repage',
|
||||
path
|
||||
], done);
|
||||
gm().in(path)
|
||||
.in('-coalesce')
|
||||
.in('-resize')
|
||||
.in(width+'x'+height)
|
||||
.write(path, done);
|
||||
} else {
|
||||
imagemagick.crop({
|
||||
srcPath: path,
|
||||
dstPath: path,
|
||||
width: width,
|
||||
height: height
|
||||
}, done);
|
||||
gm(path)
|
||||
.crop(width, height, 0, 0)
|
||||
.write(path, done);
|
||||
}
|
||||
};
|
||||
|
||||
image.convertImageToPng = function(path, extension, callback) {
|
||||
var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10);
|
||||
if(convertToPNG && extension !== '.png') {
|
||||
imagemagick.convert([path, 'png:-'], function(err, stdout) {
|
||||
if(err) {
|
||||
gm(path).toBuffer('png', function(err, buffer) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
fs.writeFile(path, stdout, 'binary', callback);
|
||||
fs.writeFile(path, buffer, 'binary', callback);
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
@@ -50,6 +42,6 @@ image.convertImageToBase64 = function(path, callback) {
|
||||
fs.readFile(path, function(err, data) {
|
||||
callback(err, data ? data.toString('base64') : null);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = image;
|
||||
659
src/routes/user.js
Normal file
659
src/routes/user.js
Normal file
@@ -0,0 +1,659 @@
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
winston = require('winston'),
|
||||
nconf = require('nconf'),
|
||||
async= require('async'),
|
||||
|
||||
user = require('./../user'),
|
||||
posts = require('./../posts'),
|
||||
postTools = require('../postTools'),
|
||||
utils = require('./../../public/src/utils'),
|
||||
templates = require('./../../public/src/templates'),
|
||||
meta = require('./../meta'),
|
||||
plugins = require('./../plugins'),
|
||||
image = require('./../image'),
|
||||
file = require('./../file'),
|
||||
db = require('./../database');
|
||||
|
||||
(function (User) {
|
||||
User.createRoutes = function (app) {
|
||||
|
||||
app.namespace('/users', function () {
|
||||
var routes = ['', '/latest', '/sort-posts', '/sort-reputation', '/online', '/search'];
|
||||
|
||||
function createRoute(routeName) {
|
||||
app.get(routeName, function (req, res) {
|
||||
|
||||
if(!req.user && !!parseInt(meta.config.privateUserInfo, 10)) {
|
||||
return res.redirect('/403');
|
||||
}
|
||||
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function (err, header) {
|
||||
res.send(header + app.create_route("users" + routeName, "users") + templates['footer']);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
for (var i=0; i<routes.length; ++i) {
|
||||
createRoute(routes[i]);
|
||||
}
|
||||
});
|
||||
|
||||
app.namespace('/user', function () {
|
||||
|
||||
function createRoute(routeName, path, templateName, access) {
|
||||
|
||||
function isAllowed(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
if (!callerUID && !!parseInt(meta.config.privateUserInfo, 10)) {
|
||||
return res.redirect('/403');
|
||||
}
|
||||
|
||||
user.getUidByUserslug(req.params.userslug, function (err, uid) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!uid) {
|
||||
return res.redirect('/404');
|
||||
}
|
||||
|
||||
if (parseInt(uid, 10) === callerUID) {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (req.path.indexOf('/edit') !== -1) {
|
||||
user.isAdministrator(callerUID, function(err, isAdmin) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(!isAdmin) {
|
||||
return res.redirect('/403');
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
} else if (req.path.indexOf('/settings') !== -1 || req.path.indexOf('/favourites') !== -1) {
|
||||
res.redirect('/403')
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
app.get(routeName, isAllowed, function(req, res, next) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function (err, header) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
res.send(header + app.create_route('user/' + req.params.userslug + path, templateName) + templates['footer']);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
createRoute('/:userslug', '', 'account');
|
||||
createRoute('/:userslug/following', '/following', 'following');
|
||||
createRoute('/:userslug/followers', '/followers', 'followers');
|
||||
createRoute('/:userslug/favourites', '/favourites', 'favourites');
|
||||
createRoute('/:userslug/posts', '/posts', 'accountposts');
|
||||
createRoute('/:userslug/edit', '/edit', 'accountedit');
|
||||
createRoute('/:userslug/settings', '/settings', 'accountsettings');
|
||||
|
||||
app.post('/uploadpicture', function (req, res) {
|
||||
if (!req.user) {
|
||||
return res.json(403, {
|
||||
error: 'Not allowed!'
|
||||
});
|
||||
}
|
||||
|
||||
var uploadSize = parseInt(meta.config.maximumProfileImageSize, 10) || 256;
|
||||
if (req.files.userPhoto.size > uploadSize * 1024) {
|
||||
fs.unlink(req.files.userPhoto.path);
|
||||
return res.send({
|
||||
error: 'Images must be smaller than ' + uploadSize + ' kb!'
|
||||
});
|
||||
}
|
||||
|
||||
var allowedTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'];
|
||||
if (allowedTypes.indexOf(req.files.userPhoto.type) === -1) {
|
||||
fs.unlink(req.files.userPhoto.path);
|
||||
return res.send({
|
||||
error: 'Allowed image types are png, jpg and gif!'
|
||||
});
|
||||
}
|
||||
|
||||
var extension = path.extname(req.files.userPhoto.name);
|
||||
if (!extension) {
|
||||
fs.unlink(req.files.userPhoto.path);
|
||||
return res.send({
|
||||
error: 'Error uploading file! Error : Invalid extension!'
|
||||
});
|
||||
}
|
||||
|
||||
var updateUid = req.user.uid;
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
image.resizeImage(req.files.userPhoto.path, extension, 128, 128, next);
|
||||
},
|
||||
function(next) {
|
||||
image.convertImageToPng(req.files.userPhoto.path, extension, next);
|
||||
},
|
||||
function(next) {
|
||||
try {
|
||||
var params = JSON.parse(req.body.params);
|
||||
if(parseInt(updateUid, 10) === parseInt(params.uid, 10)) {
|
||||
return next();
|
||||
}
|
||||
|
||||
user.isAdministrator(req.user.uid, function(err, isAdmin) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(!isAdmin) {
|
||||
return res.json(403, {
|
||||
error: 'Not allowed!'
|
||||
});
|
||||
}
|
||||
updateUid = params.uid;
|
||||
next();
|
||||
});
|
||||
} catch(err) {
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
], function(err, result) {
|
||||
|
||||
function done(err, image) {
|
||||
fs.unlink(req.files.userPhoto.path);
|
||||
if(err) {
|
||||
return res.send({error: err.message});
|
||||
}
|
||||
|
||||
user.setUserField(updateUid, 'uploadedpicture', image.url);
|
||||
user.setUserField(updateUid, 'picture', image.url);
|
||||
res.json({
|
||||
path: image.url
|
||||
});
|
||||
}
|
||||
|
||||
if(err) {
|
||||
fs.unlink(req.files.userPhoto.path);
|
||||
return res.send({error:err.message});
|
||||
}
|
||||
|
||||
if(plugins.hasListeners('filter:uploadImage')) {
|
||||
return plugins.fireHook('filter:uploadImage', req.files.userPhoto, done);
|
||||
}
|
||||
|
||||
var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10);
|
||||
var filename = updateUid + '-profileimg' + (convertToPNG ? '.png' : extension);
|
||||
|
||||
user.getUserField(updateUid, 'uploadedpicture', function (err, oldpicture) {
|
||||
if (!oldpicture) {
|
||||
file.saveFileToLocal(filename, req.files.userPhoto.path, done);
|
||||
return;
|
||||
}
|
||||
|
||||
var absolutePath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), path.basename(oldpicture));
|
||||
|
||||
fs.unlink(absolutePath, function (err) {
|
||||
if (err) {
|
||||
winston.err(err);
|
||||
}
|
||||
|
||||
file.saveFileToLocal(filename, req.files.userPhoto.path, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function isAllowed(req, res, next) {
|
||||
if(!req.user && !!parseInt(meta.config.privateUserInfo, 10)) {
|
||||
return res.json(403, 'not-allowed');
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
app.get('/api/user/:userslug/following', isAllowed, getUserFollowing);
|
||||
app.get('/api/user/:userslug/followers', isAllowed, getUserFollowers);
|
||||
app.get('/api/user/:userslug/edit', isAllowed, getUserEdit);
|
||||
app.get('/api/user/:userslug/settings', isAllowed, getUserSettings);
|
||||
app.get('/api/user/:userslug/favourites', isAllowed, getUserFavourites);
|
||||
app.get('/api/user/:userslug/posts', isAllowed, getUserPosts);
|
||||
app.get('/api/user/uid/:uid', isAllowed, getUserData);
|
||||
app.get('/api/user/:userslug', isAllowed, getUserProfile);
|
||||
|
||||
app.get('/api/users', isAllowed, getOnlineUsers);
|
||||
app.get('/api/users/sort-posts', isAllowed, getUsersSortedByPosts);
|
||||
app.get('/api/users/sort-reputation', isAllowed, getUsersSortedByReputation);
|
||||
app.get('/api/users/latest', isAllowed, getUsersSortedByJoinDate);
|
||||
app.get('/api/users/online', isAllowed, getOnlineUsers);
|
||||
app.get('/api/users/search', isAllowed, getUsersForSearch);
|
||||
|
||||
|
||||
function getUserProfile(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(!userData) {
|
||||
return res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
|
||||
user.isFollowing(callerUID, userData.theirid, function (isFollowing) {
|
||||
|
||||
posts.getPostsByUid(callerUID, userData.theirid, 0, 9, function (err, userPosts) {
|
||||
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
userData.posts = userPosts.posts.filter(function (p) {
|
||||
return p && parseInt(p.deleted, 10) !== 1;
|
||||
});
|
||||
|
||||
userData.isFollowing = isFollowing;
|
||||
|
||||
if (!userData.profileviews) {
|
||||
userData.profileviews = 1;
|
||||
}
|
||||
|
||||
if (callerUID !== parseInt(userData.uid, 10) && callerUID) {
|
||||
user.incrementUserFieldBy(userData.uid, 'profileviews', 1);
|
||||
}
|
||||
|
||||
postTools.parse(userData.signature, function (err, signature) {
|
||||
userData.signature = signature;
|
||||
res.json(userData);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getUserData(req, res, next) {
|
||||
var uid = req.params.uid ? req.params.uid : 0;
|
||||
|
||||
user.getUserData(uid, function(err, userData) {
|
||||
res.json(userData);
|
||||
});
|
||||
}
|
||||
|
||||
function getUserPosts(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
user.getUidByUserslug(req.params.userslug, function (err, uid) {
|
||||
if (!uid) {
|
||||
return res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
|
||||
user.getUserFields(uid, ['username', 'userslug'], function (err, userData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!userData) {
|
||||
return res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
|
||||
posts.getPostsByUid(callerUID, uid, 0, 19, function (err, userPosts) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
userData.uid = uid;
|
||||
userData.theirid = uid;
|
||||
userData.yourid = callerUID;
|
||||
userData.posts = userPosts.posts;
|
||||
userData.nextStart = userPosts.nextStart;
|
||||
|
||||
res.json(userData);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getUserFavourites(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
user.getUidByUserslug(req.params.userslug, function (err, uid) {
|
||||
if (!uid) {
|
||||
return res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
|
||||
if (parseInt(uid, 10) !== callerUID) {
|
||||
return res.json(403, {
|
||||
error: 'Not allowed!'
|
||||
});
|
||||
}
|
||||
|
||||
user.getUserFields(uid, ['username', 'userslug'], function (err, userData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!userData) {
|
||||
return res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
|
||||
posts.getFavourites(uid, 0, 9, function (err, favourites) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
userData.theirid = uid;
|
||||
userData.yourid = callerUID;
|
||||
userData.posts = favourites.posts;
|
||||
userData.nextStart = favourites.nextStart;
|
||||
|
||||
res.json(userData);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getUserSettings(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
user.getUidByUserslug(req.params.userslug, function(err, uid) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!uid) {
|
||||
return res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
|
||||
if (parseInt(uid, 10) !== callerUID) {
|
||||
return res.json(403, {
|
||||
error: 'Not allowed!'
|
||||
});
|
||||
}
|
||||
|
||||
plugins.fireHook('filter:user.settings', [], function(err, settings) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
user.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(!userData) {
|
||||
return res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
userData.yourid = req.user.uid;
|
||||
userData.theirid = uid;
|
||||
userData.settings = settings;
|
||||
res.json(userData);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function getUserEdit(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
res.json(userData);
|
||||
});
|
||||
}
|
||||
|
||||
function getUserFollowers(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (userData) {
|
||||
user.getFollowers(userData.uid, function (err, followersData) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
userData.followers = followersData;
|
||||
userData.followersCount = followersData.length;
|
||||
res.json(userData);
|
||||
});
|
||||
} else {
|
||||
res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getUserFollowing(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (userData) {
|
||||
user.getFollowing(userData.uid, function (err, followingData) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
userData.following = followingData;
|
||||
userData.followingCount = followingData.length;
|
||||
res.json(userData);
|
||||
});
|
||||
|
||||
} else {
|
||||
res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getUsersSortedByJoinDate(req, res) {
|
||||
user.getUsers('users:joindate', 0, 49, function (err, data) {
|
||||
res.json({
|
||||
search_display: 'none',
|
||||
loadmore_display: 'block',
|
||||
users: data,
|
||||
show_anon: 'hide'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getUsersSortedByPosts(req, res) {
|
||||
user.getUsers('users:postcount', 0, 49, function (err, data) {
|
||||
res.json({
|
||||
search_display: 'none',
|
||||
loadmore_display: 'block',
|
||||
users: data,
|
||||
show_anon: 'hide'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getUsersSortedByReputation(req, res) {
|
||||
user.getUsers('users:reputation', 0, 49, function (err, data) {
|
||||
res.json({
|
||||
search_display: 'none',
|
||||
loadmore_display: 'block',
|
||||
users: data,
|
||||
show_anon: 'hide'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getOnlineUsers(req, res, next) {
|
||||
var websockets = require('../socket.io');
|
||||
|
||||
user.getUsers('users:online', 0, 49, function (err, data) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
var onlineUsers = [];
|
||||
|
||||
uid = 0;
|
||||
if (req.user) {
|
||||
uid = req.user.uid;
|
||||
}
|
||||
|
||||
user.isAdministrator(uid, function (err, isAdministrator) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!isAdministrator) {
|
||||
data = data.filter(function(item) {
|
||||
return item.status !== 'offline';
|
||||
});
|
||||
}
|
||||
|
||||
function iterator(userData, next) {
|
||||
var online = websockets.isUserOnline(userData.uid);
|
||||
if(!online) {
|
||||
db.sortedSetRemove('users:online', userData.uid);
|
||||
return next(null);
|
||||
}
|
||||
|
||||
onlineUsers.push(userData);
|
||||
next(null);
|
||||
}
|
||||
|
||||
var anonymousUserCount = websockets.getOnlineAnonCount();
|
||||
|
||||
async.each(data, iterator, function(err) {
|
||||
res.json({
|
||||
search_display: 'none',
|
||||
loadmore_display: 'block',
|
||||
users: onlineUsers,
|
||||
anonymousUserCount: anonymousUserCount,
|
||||
show_anon: anonymousUserCount?'':'hide'
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getUsersForSearch(req, res) {
|
||||
res.json({
|
||||
search_display: 'block',
|
||||
loadmore_display: 'none',
|
||||
users: [],
|
||||
show_anon: 'hide'
|
||||
});
|
||||
}
|
||||
|
||||
function getUserDataByUserSlug(userslug, callerUID, callback) {
|
||||
|
||||
user.getUidByUserslug(userslug, function(err, uid) {
|
||||
if(err || !uid) {
|
||||
return callback(err || new Error('invalid-user'));
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
userData : function(next) {
|
||||
user.getUserData(uid, next);
|
||||
},
|
||||
userSettings : function(next) {
|
||||
user.getSettings(uid, next);
|
||||
},
|
||||
isAdmin : function(next) {
|
||||
user.isAdministrator(callerUID, next);
|
||||
},
|
||||
followStats: function(next) {
|
||||
user.getFollowStats(uid, next);
|
||||
},
|
||||
ips: function(next) {
|
||||
user.getIPs(uid, 4, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if(err || !results.userData) {
|
||||
return callback(err || new Error('invalid-user'));
|
||||
}
|
||||
|
||||
var userData = results.userData;
|
||||
var userSettings = results.userSettings;
|
||||
var isAdmin = results.isAdmin;
|
||||
var self = parseInt(callerUID, 10) === parseInt(userData.uid, 10);
|
||||
|
||||
userData.joindate = utils.toISOString(userData.joindate);
|
||||
if(userData.lastonline) {
|
||||
userData.lastonline = utils.toISOString(userData.lastonline);
|
||||
} else {
|
||||
userData.lastonline = userData.joindate;
|
||||
}
|
||||
|
||||
if (!userData.birthday) {
|
||||
userData.age = '';
|
||||
} else {
|
||||
userData.age = Math.floor((new Date().getTime() - new Date(userData.birthday).getTime()) / 31536000000);
|
||||
}
|
||||
|
||||
function canSeeEmail() {
|
||||
return ;
|
||||
}
|
||||
|
||||
if (!(isAdmin || self || (userData.email && userSettings.showemail))) {
|
||||
userData.email = "";
|
||||
}
|
||||
|
||||
if (self && !userSettings.showemail) {
|
||||
userData.emailClass = "";
|
||||
} else {
|
||||
userData.emailClass = "hide";
|
||||
}
|
||||
|
||||
if (isAdmin || self) {
|
||||
userData.ips = results.ips;
|
||||
}
|
||||
|
||||
userData.websiteName = userData.website.replace('http://', '').replace('https://', '');
|
||||
userData.banned = parseInt(userData.banned, 10) === 1;
|
||||
userData.uid = userData.uid;
|
||||
userData.yourid = callerUID;
|
||||
userData.theirid = userData.uid;
|
||||
|
||||
userData.disableSignatures = meta.config.disableSignatures !== undefined && parseInt(meta.config.disableSignatures, 10) === 1;
|
||||
|
||||
userData.followingCount = results.followStats.followingCount;
|
||||
userData.followerCount = results.followStats.followerCount;
|
||||
|
||||
callback(null, userData);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
}(exports));
|
||||
708
src/upgrade.js
708
src/upgrade.js
@@ -15,11 +15,11 @@ var db = require('./database'),
|
||||
|
||||
Upgrade = {},
|
||||
|
||||
minSchemaDate = new Date(2014, 0, 4).getTime(), // This value gets updated every new MINOR version
|
||||
minSchemaDate = Date.UTC(2014, 1, 14, 21, 50), // This value gets updated every new MINOR version
|
||||
schemaDate, thisSchemaDate,
|
||||
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||
latestSchema = new Date(2014, 1, 22).getTime();
|
||||
latestSchema = Date.UTC(2014, 1, 22);
|
||||
|
||||
Upgrade.check = function(callback) {
|
||||
db.get('schemaDate', function(err, value) {
|
||||
@@ -38,6 +38,10 @@ Upgrade.check = function(callback) {
|
||||
});
|
||||
};
|
||||
|
||||
Upgrade.update = function(schemaDate, callback) {
|
||||
db.set('schemaDate', schemaDate, callback);
|
||||
};
|
||||
|
||||
Upgrade.upgrade = function(callback) {
|
||||
var updatesMade = false;
|
||||
|
||||
@@ -64,649 +68,9 @@ Upgrade.upgrade = function(callback) {
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 0, 5).getTime();
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
db.getListRange('categories:cid', 0, -1, function(err, cids) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var timestamp = Date.now();
|
||||
|
||||
function upgradeCategory(cid, next) {
|
||||
db.getSetMembers('cid:' + cid + ':active_users', function(err, uids) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
db.delete('cid:' + cid + ':active_users', function(err) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
for(var i=0; i<uids.length; ++i) {
|
||||
db.sortedSetAdd('cid:' + cid + ':active_users', timestamp, uids[i]);
|
||||
}
|
||||
next();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async.each(cids, upgradeCategory, function(err) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
winston.info('[2014/1/5] Upgraded categories active users');
|
||||
next();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/1/5] categories active users skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 0, 5, 14, 6).getTime();
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
// Re-slugify all users
|
||||
db.delete('userslug:uid', function(err) {
|
||||
if (!err) {
|
||||
db.getObjectValues('username:uid', function(err, uids) {
|
||||
var newUserSlug;
|
||||
|
||||
async.each(uids, function(uid, next) {
|
||||
User.getUserField(uid, 'username', function(err, username) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
if(username) {
|
||||
newUserSlug = Utils.slugify(username);
|
||||
async.parallel([
|
||||
function(next) {
|
||||
User.setUserField(uid, 'userslug', newUserSlug, next);
|
||||
},
|
||||
function(next) {
|
||||
db.setObjectField('userslug:uid', newUserSlug, uid, next);
|
||||
}
|
||||
], next);
|
||||
} else {
|
||||
winston.warn('uid '+ uid + ' doesn\'t have a valid username (' + username + '), skipping');
|
||||
next(null);
|
||||
}
|
||||
});
|
||||
}, function(err) {
|
||||
winston.info('[2014/1/5] Re-slugify usernames (again)');
|
||||
next(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/1/5] Re-slugify usernames (again) skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
function upgradeUserPostsTopics(next) {
|
||||
|
||||
function upgradeUser(uid, next) {
|
||||
|
||||
function upgradeUserPosts(next) {
|
||||
|
||||
function addPostToUser(pid) {
|
||||
Posts.getPostField(pid, 'timestamp', function(err, timestamp) {
|
||||
db.sortedSetAdd('uid:' + uid + ':posts', timestamp, pid);
|
||||
});
|
||||
}
|
||||
|
||||
db.getListRange('uid:' + uid + ':posts', 0, -1, function(err, pids) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(!pids || !pids.length) {
|
||||
return next();
|
||||
}
|
||||
|
||||
db.delete('uid:' + uid + ':posts', function(err) {
|
||||
for(var i = 0; i< pids.length; ++i) {
|
||||
addPostToUser(pids[i]);
|
||||
}
|
||||
next();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function upgradeUserTopics(next) {
|
||||
|
||||
function addTopicToUser(tid) {
|
||||
Topics.getTopicField(tid, 'timestamp', function(err, timestamp) {
|
||||
db.sortedSetAdd('uid:' + uid + ':topics', timestamp, tid);
|
||||
});
|
||||
}
|
||||
|
||||
db.getListRange('uid:' + uid + ':topics', 0, -1, function(err, tids) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(!tids || !tids.length) {
|
||||
return next();
|
||||
}
|
||||
|
||||
db.delete('uid:' + uid + ':topics', function(err) {
|
||||
for(var i = 0; i< tids.length; ++i) {
|
||||
addTopicToUser(tids[i]);
|
||||
}
|
||||
next();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async.series([upgradeUserPosts, upgradeUserTopics], function(err, result) {
|
||||
next(err);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
db.getSortedSetRange('users:joindate', 0, -1, function(err, uids) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
async.each(uids, upgradeUser, function(err, result) {
|
||||
next(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function upgradeTopicPosts(next) {
|
||||
function upgradeTopic(tid, next) {
|
||||
function addPostToTopic(pid) {
|
||||
Posts.getPostField(pid, 'timestamp', function(err, timestamp) {
|
||||
db.sortedSetAdd('tid:' + tid + ':posts', timestamp, pid);
|
||||
});
|
||||
}
|
||||
|
||||
db.getListRange('tid:' + tid + ':posts', 0, -1, function(err, pids) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(!pids || !pids.length) {
|
||||
return next();
|
||||
}
|
||||
|
||||
db.delete('tid:' + tid + ':posts', function(err) {
|
||||
for(var i = 0; i< pids.length; ++i) {
|
||||
addPostToTopic(pids[i]);
|
||||
}
|
||||
next();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
db.getSetMembers('topics:tid', function(err, tids) {
|
||||
async.each(tids, upgradeTopic, function(err, results) {
|
||||
next(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
thisSchemaDate = new Date(2014, 0, 7).getTime();
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
async.series([upgradeUserPostsTopics, upgradeTopicPosts], function(err, results) {
|
||||
if(err) {
|
||||
winston.err('Error upgrading '+ err.message);
|
||||
return next(err);
|
||||
}
|
||||
|
||||
winston.info('[2014/1/7] Updated topic and user posts to sorted set');
|
||||
next();
|
||||
});
|
||||
|
||||
} else {
|
||||
winston.info('[2014/1/7] Update to topic and user posts to sorted set skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 0, 13, 12, 0).getTime();
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
db.getObjectValues('username:uid', function(err, uids) {
|
||||
async.eachSeries(uids, function(uid, next) {
|
||||
Groups.joinByGroupName('registered-users', uid, next);
|
||||
}, function(err) {
|
||||
if(err) {
|
||||
winston.err('Error upgrading '+ err.message);
|
||||
process.exit();
|
||||
} else {
|
||||
winston.info('[2014/1/13] Set up "Registered Users" user group');
|
||||
next();
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/1/13] Set up "Registered Users" user group - skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 0, 19, 22, 19).getTime();
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
db.getObjectValues('username:uid', function(err, uids) {
|
||||
async.each(uids, function(uid, next) {
|
||||
db.searchRemove('user', uid, next);
|
||||
}, function(err) {
|
||||
winston.info('[2014/1/19] Remove user search from Reds');
|
||||
next();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/1/19] Remove user search from Reds -- skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 0, 23, 16, 5).getTime();
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
Groups.getByGroupName('Administrators', {}, function(err, groupObj) {
|
||||
if (err && err.message === 'gid-not-found') {
|
||||
winston.info('[2014/1/23] Updating Administrators Group -- skipped');
|
||||
return next();
|
||||
}
|
||||
|
||||
Groups.update(groupObj.gid, {
|
||||
name: 'administrators',
|
||||
hidden: '1'
|
||||
}, function() {
|
||||
winston.info('[2014/1/23] Updating Administrators Group');
|
||||
next();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/1/23] Updating Administrators Group -- skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 0, 25, 0, 0).getTime();
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
db.getSortedSetRange('users:joindate', 0, -1, function(err, uids) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(!uids || !uids.length) {
|
||||
winston.info('[2014/1/25] Updating User Gravatars to HTTPS -- skipped');
|
||||
return next();
|
||||
}
|
||||
|
||||
var gravatar = require('gravatar');
|
||||
|
||||
function updateGravatar(uid, next) {
|
||||
User.getUserFields(uid, ['email', 'picture', 'gravatarpicture'], function(err, userData) {
|
||||
var gravatarPicture = User.createGravatarURLFromEmail(userData.email);
|
||||
if(userData.picture === userData.gravatarpicture) {
|
||||
User.setUserField(uid, 'picture', gravatarPicture);
|
||||
}
|
||||
User.setUserField(uid, 'gravatarpicture', gravatarPicture, next);
|
||||
});
|
||||
}
|
||||
|
||||
winston.info('[2014/1/25] Updating User Gravatars to HTTPS');
|
||||
async.each(uids, updateGravatar, next);
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/1/25] Updating User Gravatars to HTTPS -- skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 0, 27, 12, 35).getTime();
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
var activations = [];
|
||||
|
||||
if (Meta.config['social:facebook:secret'] && Meta.config['social:facebook:app_id']) {
|
||||
activations.push(function(next) {
|
||||
Plugins.toggleActive('nodebb-plugin-sso-facebook', function(result) {
|
||||
winston.info('[2014/1/25] Activating Facebook SSO Plugin');
|
||||
next();
|
||||
});
|
||||
});
|
||||
}
|
||||
if (Meta.config['social:twitter:key'] && Meta.config['social:twitter:secret']) {
|
||||
activations.push(function(next) {
|
||||
Plugins.toggleActive('nodebb-plugin-sso-twitter', function(result) {
|
||||
winston.info('[2014/1/25] Activating Twitter SSO Plugin');
|
||||
next();
|
||||
});
|
||||
});
|
||||
}
|
||||
if (Meta.config['social:google:secret'] && Meta.config['social:google:id']) {
|
||||
activations.push(function(next) {
|
||||
Plugins.toggleActive('nodebb-plugin-sso-google', function(result) {
|
||||
winston.info('[2014/1/25] Activating Google SSO Plugin');
|
||||
next();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async.parallel(activations, function(err) {
|
||||
if (!err) {
|
||||
winston.info('[2014/1/25] Done activating SSO plugins');
|
||||
}
|
||||
|
||||
next(err);
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/1/25] Activating SSO plugins, if set up -- skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 0, 30, 15, 0).getTime();
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
if (Meta.config.defaultLang === 'en') {
|
||||
Meta.configs.set('defaultLang', 'en_GB', next);
|
||||
} else if (Meta.config.defaultLang === 'pt_br') {
|
||||
Meta.configs.set('defaultLang', 'pt_BR', next);
|
||||
} else if (Meta.config.defaultLang === 'zh_cn') {
|
||||
Meta.configs.set('defaultLang', 'zh_CN', next);
|
||||
} else if (Meta.config.defaultLang === 'zh_tw') {
|
||||
Meta.configs.set('defaultLang', 'zh_TW', next);
|
||||
} else {
|
||||
winston.info('[2014/1/30] Fixing language settings -- skipped');
|
||||
return next();
|
||||
}
|
||||
|
||||
winston.info('[2014/1/30] Fixing language settings');
|
||||
next();
|
||||
} else {
|
||||
winston.info('[2014/1/30] Fixing language settings -- skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 0, 30, 16, 0).getTime();
|
||||
|
||||
function updateTopic(tid, next) {
|
||||
Topics.getTopicFields(tid, ['postcount', 'viewcount'], function(err, topicData) {
|
||||
if(err) {
|
||||
next(err);
|
||||
}
|
||||
|
||||
if(topicData) {
|
||||
if(!topicData.postcount) {
|
||||
topicData.postcount = 0;
|
||||
}
|
||||
|
||||
if(!topicData.viewcount) {
|
||||
topicData.viewcount = 0;
|
||||
}
|
||||
|
||||
db.sortedSetAdd('topics:posts', topicData.postcount, tid);
|
||||
db.sortedSetAdd('topics:views', topicData.viewcount, tid);
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
thisSchemaDate = Date.UTC(2014, 1, 19, 18, 15);
|
||||
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
|
||||
|
||||
winston.info('[2014/1/30] Adding new topic sets');
|
||||
db.getSortedSetRange('topics:recent', 0, -1, function(err, tids) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
async.each(tids, updateTopic, function(err) {
|
||||
next(err);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
} else {
|
||||
winston.info('[2014/1/30] Adding new topic sets -- skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 1, 2, 16, 0).getTime();
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
winston.info('[2014/2/6] Upvoting all favourited posts for each user');
|
||||
|
||||
User.getUsers('users:joindate', 0, -1, function (err, users) {
|
||||
function getFavourites(user, next) {
|
||||
function upvote(post, next) {
|
||||
var pid = post.pid,
|
||||
uid = user.uid;
|
||||
|
||||
if (post.uid !== uid) {
|
||||
db.setAdd('pid:' + pid + ':upvote', uid);
|
||||
db.sortedSetAdd('uid:' + uid + ':upvote', post.timestamp, pid);
|
||||
db.incrObjectField('post:' + pid, 'votes');
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
Posts.getFavourites(user.uid, 0, -1, function(err, posts) {
|
||||
async.each(posts.posts, upvote, function(err) {
|
||||
next(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
async.each(users, getFavourites, function(err) {
|
||||
next(err);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/2/6] Upvoting all favourited posts for each user -- skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
|
||||
thisSchemaDate = new Date(2014, 1, 7, 16, 0).getTime();
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
winston.info('[2014/2/7] Updating category recent replies');
|
||||
db.getListRange('categories:cid', 0, -1, function(err, cids) {
|
||||
|
||||
function updateCategory(cid, next) {
|
||||
db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, - 1, function(err, pids) {
|
||||
function updatePid(pid, next) {
|
||||
Posts.getCidByPid(pid, function(err, realCid) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(parseInt(realCid, 10) !== parseInt(cid, 10)) {
|
||||
Posts.getPostField(pid, 'timestamp', function(err, timestamp) {
|
||||
db.sortedSetRemove('categories:recent_posts:cid:' + cid, pid);
|
||||
db.sortedSetAdd('categories:recent_posts:cid:' + realCid, timestamp, pid);
|
||||
next();
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async.each(pids, updatePid, next);
|
||||
});
|
||||
}
|
||||
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
async.each(cids, updateCategory, next);
|
||||
});
|
||||
|
||||
|
||||
} else {
|
||||
winston.info('[2014/2/7] Updating category recent replies -- skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 1, 9, 20, 50).getTime();
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
db.delete('tid:lastFeedUpdate', function(err) {
|
||||
if(err) {
|
||||
winston.err('Error upgrading '+ err.message);
|
||||
process.exit();
|
||||
} else {
|
||||
winston.info('[2014/2/9] Remove Topic LastFeedUpdate value, as feeds are now on-demand');
|
||||
next();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/2/9] Remove Topic LastFeedUpdate value, as feeds are now on-demand - skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 1, 14, 20, 50).getTime();
|
||||
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
db.exists('topics:tid', function(err, exists) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(!exists) {
|
||||
winston.info('[2014/2/14] Upgraded topics to sorted set - skipped');
|
||||
return next();
|
||||
}
|
||||
|
||||
db.getSetMembers('topics:tid', function(err, tids) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(!Array.isArray(tids)) {
|
||||
winston.info('[2014/2/14] Upgraded topics to sorted set - skipped (cant find any tids)');
|
||||
return next();
|
||||
}
|
||||
|
||||
db.rename('topics:tid', 'topics:tid:old', function(err) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
async.each(tids, function(tid, next) {
|
||||
Topics.getTopicField(tid, 'timestamp', function(err, timestamp) {
|
||||
db.sortedSetAdd('topics:tid', timestamp, tid, next);
|
||||
});
|
||||
}, function(err) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
winston.info('[2014/2/14] Upgraded topics to sorted set');
|
||||
db.delete('topics:tid:old', next);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/2/14] Upgrade topics to sorted set - skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 1, 14, 21, 50).getTime();
|
||||
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
db.exists('users:joindate', function(err, exists) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
if(!exists) {
|
||||
winston.info('[2014/2/14] Added posts to sorted set - skipped');
|
||||
return next();
|
||||
}
|
||||
|
||||
db.getSortedSetRange('users:joindate', 0, -1, function(err, uids) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(!Array.isArray(uids)) {
|
||||
winston.info('[2014/2/14] Add posts to sorted set - skipped (cant find any uids)');
|
||||
return next();
|
||||
}
|
||||
|
||||
async.each(uids, function(uid, next) {
|
||||
User.getPostIds(uid, 0, -1, function(err, pids) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
async.each(pids, function(pid, next) {
|
||||
Posts.getPostField(pid, 'timestamp', function(err, timestamp) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
db.sortedSetAdd('posts:pid', timestamp, pid, next);
|
||||
});
|
||||
}, next);
|
||||
});
|
||||
}, function(err) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
winston.info('[2014/2/14] Added posts to sorted set');
|
||||
next();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
} else {
|
||||
winston.info('[2014/2/14] Added posts to sorted set - skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 1, 19, 18, 15).getTime();
|
||||
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
db.setObjectField('widgets:home.tpl', 'motd', JSON.stringify([
|
||||
{
|
||||
"widget": "html",
|
||||
@@ -720,7 +84,12 @@ Upgrade.upgrade = function(callback) {
|
||||
Meta.configs.remove('show_motd');
|
||||
|
||||
winston.info('[2014/2/19] Updated MOTD to use the HTML widget.');
|
||||
next(err);
|
||||
|
||||
if (err) {
|
||||
next(err);
|
||||
} else {
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/2/19] Updating MOTD to use the HTML widget - skipped');
|
||||
@@ -728,11 +97,9 @@ Upgrade.upgrade = function(callback) {
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 1, 20, 15, 30).getTime();
|
||||
thisSchemaDate = Date.UTC(2014, 1, 20, 15, 30);
|
||||
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
var container = '<div class="panel panel-default"><div class="panel-heading">{title}</div><div class="panel-body">{body}</div></div>';
|
||||
|
||||
db.setObjectField('widgets:category.tpl', 'sidebar', JSON.stringify([
|
||||
@@ -759,7 +126,12 @@ Upgrade.upgrade = function(callback) {
|
||||
}
|
||||
]), function(err) {
|
||||
winston.info('[2014/2/20] Adding Recent Replies, Active Users, and Moderator widgets to category sidebar.');
|
||||
next(err);
|
||||
|
||||
if (err) {
|
||||
next(err);
|
||||
} else {
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/2/20] Adding Recent Replies, Active Users, and Moderator widgets to category sidebar - skipped');
|
||||
@@ -767,11 +139,9 @@ Upgrade.upgrade = function(callback) {
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 1, 20, 16, 15).getTime();
|
||||
thisSchemaDate = Date.UTC(2014, 1, 20, 16, 15);
|
||||
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
db.setObjectField('widgets:home.tpl', 'footer', JSON.stringify([
|
||||
{
|
||||
"widget": "forumstats",
|
||||
@@ -779,7 +149,12 @@ Upgrade.upgrade = function(callback) {
|
||||
}
|
||||
]), function(err) {
|
||||
winston.info('[2014/2/20] Adding Forum Stats Widget to the Homepage Footer.');
|
||||
next(err);
|
||||
|
||||
if (err) {
|
||||
next(err);
|
||||
} else {
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/2/20] Adding Forum Stats Widget to the Homepage Footer - skipped');
|
||||
@@ -787,11 +162,9 @@ Upgrade.upgrade = function(callback) {
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 1, 20, 19, 45).getTime();
|
||||
thisSchemaDate = Date.UTC(2014, 1, 20, 19, 45);
|
||||
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
var container = '<div class="panel panel-default"><div class="panel-heading">{title}</div><div class="panel-body">{body}</div></div>';
|
||||
|
||||
db.setObjectField('widgets:home.tpl', 'sidebar', JSON.stringify([
|
||||
@@ -805,7 +178,12 @@ Upgrade.upgrade = function(callback) {
|
||||
}
|
||||
]), function(err) {
|
||||
winston.info('[2014/2/20] Updating Lavender MOTD');
|
||||
next(err);
|
||||
|
||||
if (err) {
|
||||
next(err);
|
||||
} else {
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/2/20] Updating Lavender MOTD - skipped');
|
||||
@@ -813,11 +191,9 @@ Upgrade.upgrade = function(callback) {
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 1, 20, 20, 25).getTime();
|
||||
thisSchemaDate = Date.UTC(2014, 1, 20, 20, 25);
|
||||
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
db.setAdd('plugins:active', 'nodebb-widget-essentials', function(err) {
|
||||
winston.info('[2014/2/20] Activating NodeBB Essential Widgets');
|
||||
Plugins.reload(function() {
|
||||
@@ -826,15 +202,18 @@ Upgrade.upgrade = function(callback) {
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/2/20] Activating NodeBB Essential Widgets - skipped');
|
||||
next();
|
||||
|
||||
if (err) {
|
||||
next(err);
|
||||
} else {
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
}
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 1, 22).getTime();
|
||||
thisSchemaDate = Date.UTC(2014, 1, 22);
|
||||
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
db.exists('categories:cid', function(err, exists) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
@@ -877,7 +256,8 @@ Upgrade.upgrade = function(callback) {
|
||||
return next(err);
|
||||
}
|
||||
winston.info('[2014/2/22] Added categories to sorted set');
|
||||
db.delete('categories:cid:old', next);
|
||||
db.delete('categories:cid:old');
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user