diff --git a/lib/PoorBooru.pm b/lib/PoorBooru.pm index b496ee0..57f7f14 100644 --- a/lib/PoorBooru.pm +++ b/lib/PoorBooru.pm @@ -72,7 +72,12 @@ get "/" => sub { }; get "/tags" => sub { - my $res = http_tiny()->get("$POORBOORU_API/tags"); + my $page = query_parameters->get("page") // 1; + send_error("Invalid page number", 400) if $page !~ /^[1-9][0-9]*$/; + + my $http = http_tiny(); + my $params = $http->www_form_urlencode({ page => $page }); + my $res = $http->get("$POORBOORU_API/tags?$params"); send_error("API error", 500) if !$res->{success}; my $data = decode_json($res->{content}); @@ -80,11 +85,12 @@ get "/tags" => sub { name => $_->{name}, count => $_->{count}, uri => uri_for("/tag/" . $_->{name}), - } ), @$data; + } ), @{$data->{tags}}; template "tags" => { title => "Tags", tags => \@tags, + pager => gallery_nav_pager($data->{pager}, "/tags"), }; }; diff --git a/views/tags.tt b/views/tags.tt index c35dee8..08fd11e 100644 --- a/views/tags.tt +++ b/views/tags.tt @@ -1,7 +1,23 @@ -

Tags

+

[% title %]

[% FOREACH tag IN tags -%] [% tag.name %] ([% tag.count %]) [% END -%]

+ +