mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-06-25 17:00:44 +02:00
Add API endpoint analogs to websocket
includes post.getPost, topic.getTopic, category.getCategory, user.getUserBy*
This commit is contained in:
@@ -192,4 +192,18 @@ SocketCategories.isModerator = function(socket, cid, callback) {
|
||||
user.isModerator(socket.uid, cid, callback);
|
||||
};
|
||||
|
||||
SocketCategories.getCategory = function(socket, cid, callback){
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
privileges.categories.can('read', cid, socket.uid, next);
|
||||
},
|
||||
function (canRead, next) {
|
||||
if (!canRead) {
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
categories.getCategoryData(cid, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
module.exports = SocketCategories;
|
||||
|
||||
@@ -77,6 +77,26 @@ SocketPosts.getRawPost = function(socket, pid, callback) {
|
||||
], callback);
|
||||
};
|
||||
|
||||
SocketPosts.getPost = function(socket, pid, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
privileges.posts.can('read', pid, socket.uid, next);
|
||||
},
|
||||
function(canRead, next) {
|
||||
if (!canRead) {
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
posts.getPostData(pid, next);
|
||||
},
|
||||
function(postData, next) {
|
||||
if (parseInt(postData.deleted, 10) === 1) {
|
||||
return next(new Error('[[error:no-post]]'));
|
||||
}
|
||||
next(null, postData);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
SocketPosts.loadMoreFavourites = function(socket, data, callback) {
|
||||
loadMorePosts('uid:' + data.uid + ':favourites', socket.uid, data, callback);
|
||||
};
|
||||
|
||||
@@ -126,4 +126,24 @@ SocketTopics.isModerator = function(socket, tid, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
SocketTopics.getTopic = function (socket, tid, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
privileges.topics.can('read', tid, socket.uid, next);
|
||||
},
|
||||
function (canRead, next) {
|
||||
if (!canRead) {
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
topics.getTopicData(tid, next);
|
||||
},
|
||||
function (topicData, next) {
|
||||
if (parseInt(topicData.deleted, 10) === 1) {
|
||||
return next(new Error('[[error:no-topic]]'));
|
||||
}
|
||||
next(null, topicData);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
module.exports = SocketTopics;
|
||||
|
||||
@@ -194,7 +194,7 @@ SocketUser.saveSettings = function(socket, data, callback) {
|
||||
return next(null, true);
|
||||
}
|
||||
user.isAdminOrGlobalMod(socket.uid, next);
|
||||
},
|
||||
},
|
||||
function(allowed, next) {
|
||||
if (!allowed) {
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
@@ -333,4 +333,45 @@ SocketUser.invite = function(socket, email, callback) {
|
||||
};
|
||||
|
||||
|
||||
SocketUser.getUserByUID = getUserByUID;
|
||||
|
||||
function getUserByUID(socket, uid, callback) {
|
||||
async.parallel({
|
||||
userData: async.apply(user.getUserData, uid),
|
||||
settings: async.apply(user.getSettings, uid)
|
||||
}, function(err, results) {
|
||||
if (err || !results.userData) {
|
||||
return callback(err||new Error('[[error:no-user]]'));
|
||||
}
|
||||
|
||||
results.userData.email = results.settings.showemail ? results.userData.email : undefined;
|
||||
results.userData.fullname = results.settings.showfullname ? results.userData.fullname : undefined;
|
||||
|
||||
callback(null,results.userData);
|
||||
});
|
||||
}
|
||||
|
||||
SocketUser.getUserByUsername = function(socket, username, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
user.getUidByUsername(username || 0, next);
|
||||
},
|
||||
function(uid, next) {
|
||||
getUserByUID(socket, uid, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
SocketUser.getUserByEmail = function(socket, email, callback) {
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
user.getUidByEmail(email || 0, next);
|
||||
},
|
||||
function(uid, next) {
|
||||
getUserByUID(socket, uid, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
module.exports = SocketUser;
|
||||
|
||||
Reference in New Issue
Block a user