diff --git a/lib/PoorBooru/API/V0.pm b/lib/PoorBooru/API/V0.pm index 5caae23..3c81c05 100644 --- a/lib/PoorBooru/API/V0.pm +++ b/lib/PoorBooru/API/V0.pm @@ -21,10 +21,16 @@ use constant { ROWS_PER_PAGE => 20, }; -sub surrounding_pages ($) +sub mkpager ($) { my $pager = $_[0]->pager; - return $pager->previous_page, $pager->next_page; + return { + first => $pager->first_page, + prev => $pager->previous_page, + cur => $pager->current_page, + next => $pager->next_page, + last => $pager->last_page, + }; } get "/meta" => sub { @@ -79,18 +85,16 @@ get "/tag/:tag_id_or_name" => sub { get "/media" => sub { my $page = query_parameters->get("page") // 1; - send_error("Invalide page number", 400) if $page !~ /^[1-9][0-9]*$/; + send_error("Invalid page number", 400) if $page !~ /^[1-9][0-9]*$/; my $paged_media = schema("default")->resultset("Media") ->search({}, { order_by => "upload_date", rows => ROWS_PER_PAGE }) ->page($page); - my ($prev, $next) = surrounding_pages($paged_media); my @media = map { $_->media_id } $paged_media->all; return { - next => ($next and "/media?page=$next"), - prev => ($prev and "/media?page=$prev"), + pager => mkpager($paged_media), media => \@media, }; };