fix: circular object ref.

getCategoriesFields was returning full pseudo-category object even if fields were specific, now it only returns fields requested.
navigating to /category/-1 now redirects to /world
This commit is contained in:
Julian Lam
2024-03-15 12:00:20 -04:00
parent a84dba271c
commit 7af0715146
2 changed files with 8 additions and 1 deletions

View File

@@ -38,7 +38,11 @@ module.exports = function (Categories) {
// Handle cid -1
if (cids.includes(-1)) {
categories.splice(cids.indexOf(-1), 1, worldCategory);
const subset = fields.reduce((category, field) => {
category[field] = worldCategory[field] || undefined;
return category;
}, {});
categories.splice(cids.indexOf(-1), 1, subset);
}
const result = await plugins.hooks.fire('filter:category.getFields', {

View File

@@ -26,6 +26,9 @@ const validSorts = [
categoryController.get = async function (req, res, next) {
const cid = req.params.category_id;
if (cid === '-1') {
return helpers.redirect(res, `/world?${qs.stringify(req.query)}`);
}
let currentPage = parseInt(req.query.page, 10) || 1;
let topicIndex = utils.isNumber(req.params.topic_index) ? parseInt(req.params.topic_index, 10) - 1 : 0;