v1.18.x
barisusakli 11 years ago
parent a32fd3f6f9
commit 1d1d677b56

@ -9,6 +9,7 @@ var topicsController = {},
user = require('./../user'),
meta = require('./../meta'),
topics = require('./../topics'),
posts = require('../posts'),
threadTools = require('./../threadTools'),
utils = require('./../../public/src/utils');
@ -181,4 +182,29 @@ topicsController.get = function(req, res, next) {
});
};
topicsController.teaser = function(req, res, next) {
var tid = req.params.topic_id;
topics.getLatestUndeletedPid(tid, function(err, pid) {
if (err) {
return next(err);
}
if (!pid) {
return res.json(404, 'not-found');
}
posts.getPostSummaryByPids([pid], false, function(err, posts) {
if (err) {
return next(err);
}
if (!Array.isArray(posts) || !posts.length) {
return res.json(404, 'not-found');
}
res.json(posts[0]);
});
});
};
module.exports = topicsController;

@ -49,6 +49,8 @@ function staticRoutes(app, middleware, controllers) {
}
function topicRoutes(app, middleware, controllers) {
app.get('/api/topic/teaser/:topic_id', controllers.topics.teaser);
app.get('/topic/:topic_id/:slug?', middleware.buildHeader, middleware.addSlug, controllers.topics.get);
app.get('/api/topic/:topic_id/:slug?', controllers.topics.get);
}

Loading…
Cancel
Save