Skip to content

Commit

Permalink
fix: fixed api pagination issue (closes #285)
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Sep 2, 2024
1 parent 81a9daf commit 0014692
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
22 changes: 20 additions & 2 deletions routes/api/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,16 @@ router
: true;
if (!hasPagination) return next();
if (typeof ctx.query.limit === 'undefined') ctx.query.limit = 1000;
return paginate.middleware(50, 1000)(ctx, next);
let defaultLimit = 50;
if (typeof ctx.query.limit === 'number' && ctx.query.limit < 50)
defaultLimit = 10;
else if (
typeof ctx.query.limit === 'string' &&
Number.isFinite(Number.parseInt(ctx.query.limit, 10)) &&
Number.parseInt(ctx.query.limit, 10) < 50
)
defaultLimit = 10;
return paginate.middleware(defaultLimit, 1000)(ctx, next);
},
web.myAccount.retrieveDomains
)
Expand Down Expand Up @@ -295,7 +304,16 @@ router
: true;
if (!hasPagination) return next();
if (typeof ctx.query.limit === 'undefined') ctx.query.limit = 1000;
return paginate.middleware(50, 1000)(ctx, next);
let defaultLimit = 50;
if (typeof ctx.query.limit === 'number' && ctx.query.limit < 50)
defaultLimit = 10;
else if (
typeof ctx.query.limit === 'string' &&
Number.isFinite(Number.parseInt(ctx.query.limit, 10)) &&
Number.parseInt(ctx.query.limit, 10) < 50
)
defaultLimit = 10;
return paginate.middleware(defaultLimit, 1000)(ctx, next);
},
web.myAccount.retrieveAliases,
api.v1.aliases.list
Expand Down
5 changes: 4 additions & 1 deletion test/smtp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,10 @@ test(`${env.SMTP_MESSAGE_MAX_SIZE} message size`, async (t) => {
user: user._id
})
);
t.is(err.message, `Email size of ${bytes(bytes(env.SMTP_MESSAGE_MAX_SIZE))} exceeded.`);
t.is(
err.message,
`Email size of ${bytes(bytes(env.SMTP_MESSAGE_MAX_SIZE))} exceeded.`
);
});

test('smtp outbound queue', async (t) => {
Expand Down

0 comments on commit 0014692

Please sign in to comment.