backend: handle paged /tags from API
This commit is contained in:
parent
7e3fdadfc6
commit
5b8cbd37e5
@ -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"),
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,23 @@
|
||||
<h1>Tags</h1>
|
||||
<h1>[% title %]</h1>
|
||||
|
||||
<p class="text-center">
|
||||
[% FOREACH tag IN tags -%]
|
||||
<a href="[% tag.uri %]">[% tag.name %] ([% tag.count %])</a>
|
||||
[% END -%]
|
||||
</p>
|
||||
|
||||
<nav class="text-center">
|
||||
[% IF pager.first -%]
|
||||
<a href="[% pager.first %]"><<</a>
|
||||
[% END -%]
|
||||
[% IF pager.prev -%]
|
||||
<a href="[% pager.prev %]"><</a>
|
||||
[% END -%]
|
||||
<span>[% pager.cur %]</span>
|
||||
[% IF pager.next -%]
|
||||
<a href="[% pager.next %]">></a>
|
||||
[% END -%]
|
||||
[% IF pager.last -%]
|
||||
<a href="[% pager.last %]">>></a>
|
||||
[% END -%]
|
||||
</nav>
|
||||
|
Loading…
Reference in New Issue
Block a user