Merge pull request #108 from shocknet/fix/wall-page-zero

forbid page zero for wall
This commit is contained in:
Daniel Lugo 2020-07-11 15:08:46 -04:00 committed by GitHub
commit ebf6704d66
2 changed files with 11 additions and 5 deletions

View file

@ -38,11 +38,10 @@ const getWallTotalPages = async publicKey => {
const getWallPage = async (page, publicKey) => {
const totalPages = await getWallTotalPages(publicKey)
if (page === 0 || totalPages === 0) {
return {
count: 0,
posts: {}
}
if (page === 0) {
throw new RangeError(
`Page number cannot be zero, only positive and negative integers are allowed.`
)
}
const actualPageIdx = page < 0 ? totalPages + page : page - 1

View file

@ -1856,6 +1856,13 @@ module.exports = async (
})
}
if (pageNum === 0) {
return res.status(400).json({
field: 'page',
errorMessage: 'Page must be a non-zero integer'
})
}
const totalPages = await GunGetters.getWallTotalPages(publicKey)
const fetchedPage = await GunGetters.getWallPage(pageNum, publicKey)