misc fixes

handle spider uids properly
This commit is contained in:
Barış Soner Uşaklı
2018-11-12 00:20:44 -05:00
parent afa84023a2
commit 69bb3293ee
30 changed files with 122 additions and 104 deletions

View File

@@ -15,7 +15,7 @@ module.exports = function (Posts) {
};
function toggleBookmark(type, pid, uid, callback) {
if (!parseInt(uid, 10)) {
if (parseInt(uid, 10) <= 0) {
return callback(new Error('[[error:not-logged-in]]'));
}
@@ -85,9 +85,9 @@ module.exports = function (Posts) {
}
Posts.hasBookmarked = function (pid, uid, callback) {
if (!parseInt(uid, 10)) {
if (parseInt(uid, 10) <= 0) {
if (Array.isArray(pid)) {
callback(null, pid.map(function () { return false; }));
callback(null, pid.map(() => false));
} else {
callback(null, false);
}
@@ -95,10 +95,7 @@ module.exports = function (Posts) {
}
if (Array.isArray(pid)) {
var sets = pid.map(function (pid) {
return 'pid:' + pid + ':users_bookmarked';
});
var sets = pid.map(pid => 'pid:' + pid + ':users_bookmarked');
db.isMemberOfSets(sets, uid, callback);
} else {
db.isSetMember('pid:' + pid + ':users_bookmarked', uid, callback);

View File

@@ -35,7 +35,7 @@ Posts.exists = function (pid, callback) {
Posts.getPidsFromSet = function (set, start, stop, reverse, callback) {
if (isNaN(start) || isNaN(stop)) {
return callback(null, []);
return setImmediate(callback, null, []);
}
db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, stop, callback);
};

View File

@@ -144,8 +144,8 @@ module.exports = function (Posts) {
};
Posts.isModerator = function (pids, uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null, pids.map(function () { return false; }));
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback, null, pids.map(() => false));
}
Posts.getCidsByPids(pids, function (err, cids) {
if (err) {

View File

@@ -85,8 +85,8 @@ module.exports = function (Posts) {
};
Posts.hasVoted = function (pid, uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null, { upvoted: false, downvoted: false });
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback, null, { upvoted: false, downvoted: false });
}
async.waterfall([
function (next) {
@@ -99,9 +99,9 @@ module.exports = function (Posts) {
};
Posts.getVoteStatusByPostIDs = function (pids, uid, callback) {
if (!parseInt(uid, 10)) {
var data = pids.map(function () { return false; });
return callback(null, { upvotes: data, downvotes: data });
if (parseInt(uid, 10) <= 0) {
var data = pids.map(() => false);
return setImmediate(callback, null, { upvotes: data, downvotes: data });
}
var upvoteSets = [];
var downvoteSets = [];
@@ -110,15 +110,17 @@ module.exports = function (Posts) {
upvoteSets.push('pid:' + pids[i] + ':upvote');
downvoteSets.push('pid:' + pids[i] + ':downvote');
}
async.parallel({
upvotes: function (next) {
db.isMemberOfSets(upvoteSets, uid, next);
async.waterfall([
function (next) {
db.isMemberOfSets(upvoteSets.concat(downvoteSets), uid, next);
},
downvotes: function (next) {
db.isMemberOfSets(downvoteSets, uid, next);
function (data, next) {
next(null, {
upvotes: data.slice(0, pids.length),
downvotes: data.slice(pids.length, pids.length * 2),
});
},
}, callback);
], callback);
};
Posts.getUpvotedUidsByPids = function (pids, callback) {