mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: remove now unused world/:tid route and assoc. controller
This commit is contained in:
@@ -1,14 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const nconf = require('nconf');
|
|
||||||
|
|
||||||
const db = require('../../database');
|
const db = require('../../database');
|
||||||
const user = require('../../user');
|
const user = require('../../user');
|
||||||
const topics = require('../../topics');
|
const topics = require('../../topics');
|
||||||
const privileges = require('../../privileges');
|
|
||||||
|
|
||||||
const { notes } = require('../../activitypub');
|
|
||||||
// const helpers = require('../helpers');
|
|
||||||
const pagination = require('../../pagination');
|
const pagination = require('../../pagination');
|
||||||
const helpers = require('../helpers');
|
const helpers = require('../helpers');
|
||||||
|
|
||||||
@@ -38,86 +33,3 @@ controller.list = async function (req, res) {
|
|||||||
|
|
||||||
res.render('world', data);
|
res.render('world', data);
|
||||||
};
|
};
|
||||||
|
|
||||||
controller.get = async function (req, res, next) {
|
|
||||||
/**
|
|
||||||
* Ideally we would use the existing topicsController.get...
|
|
||||||
* this controller may be a stopgap towards that end goal.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const tid = req.params.topic_id;
|
|
||||||
let postIndex = parseInt(req.params.post_index, 10) || 1;
|
|
||||||
const [
|
|
||||||
userPrivileges,
|
|
||||||
settings,
|
|
||||||
// topicData,
|
|
||||||
] = await Promise.all([
|
|
||||||
privileges.topics.get(tid, req.uid),
|
|
||||||
user.getSettings(req.uid),
|
|
||||||
// topics.getTopicData(tid),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const topicData = await topics.getTopicData(tid);
|
|
||||||
topicData.category = {}; // todo
|
|
||||||
|
|
||||||
let currentPage = parseInt(req.query.page, 10) || 1;
|
|
||||||
const pageCount = Math.max(1, Math.ceil((topicData && topicData.postcount) / settings.postsPerPage));
|
|
||||||
const invalidPagination = (settings.usePagination && (currentPage < 1 || currentPage > pageCount));
|
|
||||||
if (
|
|
||||||
!topicData ||
|
|
||||||
userPrivileges.disabled ||
|
|
||||||
invalidPagination// ||
|
|
||||||
// (topicData.scheduled && !userPrivileges.view_scheduled)
|
|
||||||
) {
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!req.query.page) {
|
|
||||||
currentPage = calculatePageFromIndex(postIndex, settings);
|
|
||||||
}
|
|
||||||
if (settings.usePagination && req.query.page) {
|
|
||||||
const top = ((currentPage - 1) * settings.postsPerPage) + 1;
|
|
||||||
const bottom = top + settings.postsPerPage;
|
|
||||||
if (!req.params.post_index || (postIndex < top || postIndex > bottom)) {
|
|
||||||
postIndex = top;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const { start, stop } = calculateStartStop(currentPage, postIndex, settings);
|
|
||||||
|
|
||||||
topicData.posts = await notes.getTopicPosts(tid, req.uid, start, stop);
|
|
||||||
await topics.calculatePostIndices(topicData.posts, start - 1);
|
|
||||||
topicData.posts = await topics.addPostData(topicData.posts, req.uid);
|
|
||||||
topicData.privileges = userPrivileges;
|
|
||||||
|
|
||||||
await topics.increaseViewCount(req, tid);
|
|
||||||
|
|
||||||
topicData.postIndex = postIndex;
|
|
||||||
topicData.pagination = pagination.create(currentPage, pageCount, req.query);
|
|
||||||
topicData.pagination.rel.forEach((rel) => {
|
|
||||||
rel.href = `${nconf.get('url')}/topic/${topicData.slug}${rel.href}`;
|
|
||||||
res.locals.linkTags.push(rel);
|
|
||||||
});
|
|
||||||
|
|
||||||
res.render('topic', topicData);
|
|
||||||
};
|
|
||||||
|
|
||||||
// todo: expose from topic controller?
|
|
||||||
function calculatePageFromIndex(postIndex, settings) {
|
|
||||||
return 1 + Math.floor((postIndex - 1) / settings.postsPerPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo: expose from topic controller?
|
|
||||||
function calculateStartStop(page, postIndex, settings) {
|
|
||||||
let startSkip = 0;
|
|
||||||
|
|
||||||
if (!settings.usePagination) {
|
|
||||||
if (postIndex > 1) {
|
|
||||||
page = 1;
|
|
||||||
}
|
|
||||||
startSkip = Math.max(0, postIndex - Math.ceil(settings.postsPerPage / 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
const start = ((page - 1) * settings.postsPerPage) + startSkip;
|
|
||||||
const stop = start + settings.postsPerPage - 1;
|
|
||||||
return { start: Math.max(0, start), stop: Math.max(0, stop) };
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ const helpers = require('./helpers');
|
|||||||
|
|
||||||
module.exports = function (app, middleware, controllers) {
|
module.exports = function (app, middleware, controllers) {
|
||||||
helpers.setupPageRoute(app, '/world', [middleware.activitypub.enabled], controllers.activitypub.topics.list);
|
helpers.setupPageRoute(app, '/world', [middleware.activitypub.enabled], controllers.activitypub.topics.list);
|
||||||
helpers.setupPageRoute(app, '/world/:topic_id/:post_index?', [middleware.activitypub.enabled], controllers.activitypub.topics.get);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These controllers only respond if the sender is making an json+activitypub style call (i.e. S2S-only)
|
* These controllers only respond if the sender is making an json+activitypub style call (i.e. S2S-only)
|
||||||
|
|||||||
Reference in New Issue
Block a user