|
|
|
@ -1,27 +1,21 @@
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var path = require('path'),
|
|
|
|
|
nconf = require('nconf'),
|
|
|
|
|
async = require('async'),
|
|
|
|
|
fs = require('fs'),
|
|
|
|
|
|
|
|
|
|
db = require('../database'),
|
|
|
|
|
user = require('../user'),
|
|
|
|
|
groups = require('../groups'),
|
|
|
|
|
auth = require('./authentication'),
|
|
|
|
|
topics = require('../topics'),
|
|
|
|
|
ThreadTools = require('../threadTools'),
|
|
|
|
|
posts = require('../posts'),
|
|
|
|
|
categories = require('../categories'),
|
|
|
|
|
categoryTools = require('../categoryTools'),
|
|
|
|
|
meta = require('../meta'),
|
|
|
|
|
Plugins = require('../plugins'),
|
|
|
|
|
plugins = require('../plugins'),
|
|
|
|
|
utils = require('../../public/src/utils'),
|
|
|
|
|
translator = require('../../public/src/translator'),
|
|
|
|
|
pkg = require('../../package.json');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(function (Api) {
|
|
|
|
|
Api.createRoutes = function (app) {
|
|
|
|
|
|
|
|
|
|
module.exports = function(app, middleware, controllers) {
|
|
|
|
|
app.namespace('/api', function () {
|
|
|
|
|
app.all('*', function(req, res, next) {
|
|
|
|
|
if(req.user) {
|
|
|
|
@ -34,6 +28,8 @@ var path = require('path'),
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get('/user/uid/:uid', middleware.checkGlobalPrivacySettings, controllers.accounts.getUserByUID);
|
|
|
|
|
|
|
|
|
|
app.get('/get_templates_listing', function (req, res) {
|
|
|
|
|
utils.walk(path.join(__dirname, '../../', 'public/templates'), function (err, data) {
|
|
|
|
|
res.json(data.concat(app.get_custom_templates()).filter(function(value, index, self) {
|
|
|
|
@ -50,7 +46,7 @@ var path = require('path'),
|
|
|
|
|
config.minimumTitleLength = meta.config.minimumTitleLength;
|
|
|
|
|
config.maximumTitleLength = meta.config.maximumTitleLength;
|
|
|
|
|
config.minimumPostLength = meta.config.minimumPostLength;
|
|
|
|
|
config.hasImageUploadPlugin = Plugins.hasListeners('filter:uploadImage');
|
|
|
|
|
config.hasImageUploadPlugin = plugins.hasListeners('filter:uploadImage');
|
|
|
|
|
config.maximumProfileImageSize = meta.config.maximumProfileImageSize;
|
|
|
|
|
config.minimumUsernameLength = meta.config.minimumUsernameLength;
|
|
|
|
|
config.maximumUsernameLength = meta.config.maximumUsernameLength;
|
|
|
|
@ -86,111 +82,6 @@ var path = require('path'),
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get('/topic/:id/:slug?', function (req, res, next) {
|
|
|
|
|
var uid = req.user? parseInt(req.user.uid, 10) : 0;
|
|
|
|
|
var tid = req.params.id;
|
|
|
|
|
var page = 1;
|
|
|
|
|
if(req.query && req.query.page) {
|
|
|
|
|
page = req.query.page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!utils.isNumber(page) || parseInt(page, 10) < 1) {
|
|
|
|
|
return res.send(404);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user.getSettings(uid, function(err, settings) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var start = (page - 1) * settings.postsPerPage;
|
|
|
|
|
var end = start + settings.postsPerPage - 1;
|
|
|
|
|
|
|
|
|
|
ThreadTools.privileges(tid, uid, function(err, privileges) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!privileges.read) {
|
|
|
|
|
res.send(403);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
topics.getTopicWithPosts(tid, uid, start, end, function (err, data) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(page > data.pageCount) {
|
|
|
|
|
return res.send(404);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parseInt(data.deleted, 10) === 1 && parseInt(data.expose_tools, 10) === 0) {
|
|
|
|
|
return res.json(404, {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.currentPage = page;
|
|
|
|
|
data.privileges = privileges;
|
|
|
|
|
|
|
|
|
|
if (uid) {
|
|
|
|
|
topics.markAsRead(tid, uid, function(err) {
|
|
|
|
|
topics.pushUnreadCount(uid);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
topics.increaseViewCount(tid);
|
|
|
|
|
|
|
|
|
|
res.json(data);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get('/category/:id/:slug?', function (req, res, next) {
|
|
|
|
|
var uid = (req.user) ? req.user.uid : 0;
|
|
|
|
|
var page = 1;
|
|
|
|
|
if(req.query && req.query.page) {
|
|
|
|
|
page = req.query.page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!utils.isNumber(page) || parseInt(page, 10) < 1) {
|
|
|
|
|
return res.send(404);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user.getSettings(uid, function(err, settings) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var start = (page - 1) * settings.topicsPerPage,
|
|
|
|
|
end = start + settings.topicsPerPage - 1;
|
|
|
|
|
|
|
|
|
|
categoryTools.privileges(req.params.id, uid, function(err, privileges) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!privileges.read) {
|
|
|
|
|
return res.send(403);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
categories.getCategoryById(req.params.id, start, end, uid, function (err, data) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.currentPage = page;
|
|
|
|
|
data.privileges = privileges;
|
|
|
|
|
|
|
|
|
|
if (data && !data.disabled) {
|
|
|
|
|
res.json(data);
|
|
|
|
|
} else {
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get('/notifications', function(req, res) {
|
|
|
|
|
if (req.user && req.user.uid) {
|
|
|
|
|
user.notifications.getAll(req.user.uid, null, null, function(err, notifications) {
|
|
|
|
@ -203,28 +94,13 @@ var path = require('path'),
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get('/search', function (req, res) {
|
|
|
|
|
if ((req.user && req.user.uid) || meta.config.allowGuestSearching === '1') {
|
|
|
|
|
return res.json({
|
|
|
|
|
show_no_topics: 'hide',
|
|
|
|
|
show_no_posts: 'hide',
|
|
|
|
|
show_results: 'hide',
|
|
|
|
|
search_query: '',
|
|
|
|
|
posts: [],
|
|
|
|
|
topics: []
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
res.send(403);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get('/search/:term', function (req, res, next) {
|
|
|
|
|
if (!Plugins.hasListeners('filter:search.query')) {
|
|
|
|
|
if (!plugins.hasListeners('filter:search.query')) {
|
|
|
|
|
return res.redirect('/404');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function searchPosts(callback) {
|
|
|
|
|
Plugins.fireHook('filter:search.query', {
|
|
|
|
|
plugins.fireHook('filter:search.query', {
|
|
|
|
|
index: 'post',
|
|
|
|
|
query: req.params.term
|
|
|
|
|
}, function(err, pids) {
|
|
|
|
@ -237,7 +113,7 @@ var path = require('path'),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function searchTopics(callback) {
|
|
|
|
|
Plugins.fireHook('filter:search.query', {
|
|
|
|
|
plugins.fireHook('filter:search.query', {
|
|
|
|
|
index: 'topic',
|
|
|
|
|
query: req.params.term
|
|
|
|
|
}, function(err, tids) {
|
|
|
|
@ -322,7 +198,7 @@ var path = require('path'),
|
|
|
|
|
} else {
|
|
|
|
|
posts.uploadPostFile(file, next);
|
|
|
|
|
}
|
|
|
|
|
}, next)
|
|
|
|
|
}, next);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.post('/topic/thumb/upload', function(req, res, next) {
|
|
|
|
@ -335,23 +211,14 @@ var path = require('path'),
|
|
|
|
|
}, next);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get('/reset', function (req, res) {
|
|
|
|
|
res.json({});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get('/reset/:code', function (req, res) {
|
|
|
|
|
res.json({
|
|
|
|
|
reset_code: req.params.code
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.namespace('/categories', function() {
|
|
|
|
|
app.get(':cid/moderators', function(req, res) {
|
|
|
|
|
app.get('/categories/:cid/moderators', function(req, res) {
|
|
|
|
|
categories.getModerators(req.params.cid, function(err, moderators) {
|
|
|
|
|
res.json({moderators: moderators});
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}(exports));
|
|
|
|
|
|
|
|
|
|
// this should have been in the API namespace
|
|
|
|
|
// also, perhaps pass in :userslug so we can use checkAccountPermissions middleware - in future will allow admins to upload a picture for a user
|
|
|
|
|
app.post('/user/uploadpicture', middleware.checkGlobalPrivacySettings, /*middleware.checkAccountPermissions,*/ controllers.accounts.uploadPicture);
|
|
|
|
|
};
|