Skip to content

Commit

Permalink
fix: get query page
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Apr 9, 2023
1 parent 730dc4e commit 7ca4f25
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ router.get('/resources', async (request, env: Env) => {
return makeResponse({ resources });

function resolveParams(): { page: number; pageSize: number } | undefined {
let page = readNum(request.params.page || '1');
let pageSize = readNum(request.params.count || '100');
if (!page || !pageSize) return undefined;
let page = readNum(request.query.page || '1');
let pageSize = readNum(request.query.count || '100');

if (!page || !pageSize) return undefined;
if (page <= 0) page = 1;
if (pageSize <= 0) pageSize = 100;
if (pageSize > 100) pageSize = 100;

return { page, pageSize };

function readNum(raw: string) {
function readNum(raw: string | string[]) {
if (typeof raw === 'string' && /^\d+$/.test(raw)) {
return +raw;
} else {
Expand Down

0 comments on commit 7ca4f25

Please sign in to comment.