Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ router.get('/about', (req, res) => {
// Global discovery feed
router.get('/discover', async (req, res) => {
try {
console.log('Discover route accessed');
if (process.env.DEBUG) {
console.log('Discover route accessed');
}
// Validate and sanitize pagination params
const page = Math.max(1, parseInt(req.query.page) || 1);
const limit = Math.min(50, parseInt(req.query.limit) || 20);
Comment on lines 130 to 131
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: Potential Parsing Error with parseInt

The parseInt function is used here without specifying a radix, which can lead to unexpected results if the input isn't strictly decimal. This is particularly risky when dealing with user input that could vary in format.

Recommended Solution:
Always specify a radix when using parseInt to ensure the parsing is done in the intended numeral system. For example:

const page = Math.max(1, parseInt(req.query.page, 10) || 1);
const limit = Math.min(50, parseInt(req.query.limit, 10) || 20);

Expand Down Expand Up @@ -170,7 +172,9 @@ router.get('/discover', async (req, res) => {

const totalPages = Math.ceil(Math.max(userCount, itemCount) / limit);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: Inaccurate Pagination Calculation

The calculation of totalPages uses the maximum of userCount and itemCount divided by limit. This approach might not accurately reflect the total pages needed if the counts of users and items differ significantly, potentially leading to incorrect pagination data.

Recommended Solution:
Consider revising the logic to ensure that the pagination accurately reflects the data being paginated. If separate paginations for users and items are not feasible, a more detailed method to handle differing counts should be implemented.


console.log('Attempting to render discover template');
if (process.env.DEBUG) {
console.log('Attempting to render discover template');
}
res.render('discover', {
title: 'Discover - Wirebase',
updates,
Expand Down