mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
closes #1422
This commit is contained in:
@@ -9,6 +9,7 @@ var topicsController = {},
|
|||||||
user = require('./../user'),
|
user = require('./../user'),
|
||||||
meta = require('./../meta'),
|
meta = require('./../meta'),
|
||||||
topics = require('./../topics'),
|
topics = require('./../topics'),
|
||||||
|
posts = require('../posts'),
|
||||||
threadTools = require('./../threadTools'),
|
threadTools = require('./../threadTools'),
|
||||||
utils = require('./../../public/src/utils');
|
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;
|
module.exports = topicsController;
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ function staticRoutes(app, middleware, controllers) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function topicRoutes(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('/topic/:topic_id/:slug?', middleware.buildHeader, middleware.addSlug, controllers.topics.get);
|
||||||
app.get('/api/topic/:topic_id/:slug?', controllers.topics.get);
|
app.get('/api/topic/:topic_id/:slug?', controllers.topics.get);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user