backend: merge Gallery controller into Media
This commit is contained in:
parent
fc407c608e
commit
71d31e625a
@ -41,8 +41,7 @@ sub startup ($self)
|
||||
|
||||
my $r = $self->routes;
|
||||
|
||||
$r->get("/")->to("gallery#index");
|
||||
|
||||
$r->get("/")->to("media#list");
|
||||
$r->get("/media/:media_id")->to("media#show");
|
||||
|
||||
$r->get("/tags")->to("tags#list");
|
||||
|
@ -1,38 +0,0 @@
|
||||
package PoorBooru::Backend::Controller::Gallery;
|
||||
use v5.36;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Mojo::Base "Mojolicious::Controller";
|
||||
use Mojo::JSON qw(decode_json);
|
||||
use SeaweedFS::FID;
|
||||
|
||||
sub index ($self)
|
||||
{
|
||||
my $v = $self->validation;
|
||||
my $page = $v->optional("page")->num(1, undef)->param // 1;
|
||||
|
||||
return $self->render(
|
||||
status => 404,
|
||||
) if $v->has_error;
|
||||
|
||||
my $poorbooru_api = $self->config("poorbooru_api");
|
||||
my $res = $self->ua->get("$poorbooru_api/media?page=$page")->result;
|
||||
|
||||
return $self->render(status => $res->code) if $res->is_error;
|
||||
|
||||
$self->title("Pooru~");
|
||||
my @media = map +{
|
||||
media_src => $self->seaweed->url_for(
|
||||
SeaweedFS::FID->from_string($_->{seaweedfs_fid})
|
||||
),
|
||||
}, @{$res->json->{media}};
|
||||
|
||||
return $self->render(
|
||||
template => "gallery",
|
||||
media => [ @media ],
|
||||
pager => { $self->pager_links($res->json->{pager}) },
|
||||
);
|
||||
};
|
||||
|
||||
1;
|
@ -7,6 +7,34 @@ use Mojo::Base "Mojolicious::Controller";
|
||||
use Mojo::JSON qw(decode_json);
|
||||
use SeaweedFS::FID;
|
||||
|
||||
sub list ($self)
|
||||
{
|
||||
my $v = $self->validation;
|
||||
my $page = $v->optional("page")->num(1, undef)->param // 1;
|
||||
|
||||
return $self->render(
|
||||
status => 404,
|
||||
) if $v->has_error;
|
||||
|
||||
my $poorbooru_api = $self->config("poorbooru_api");
|
||||
my $res = $self->ua->get("$poorbooru_api/media?page=$page")->result;
|
||||
|
||||
return $self->render(status => $res->code) if $res->is_error;
|
||||
|
||||
$self->title("Pooru~");
|
||||
my @media = map +{
|
||||
media_src => $self->seaweed->url_for(
|
||||
SeaweedFS::FID->from_string($_->{seaweedfs_fid})
|
||||
),
|
||||
}, @{$res->json->{media}};
|
||||
|
||||
return $self->render(
|
||||
template => "gallery",
|
||||
media => [ @media ],
|
||||
pager => { $self->pager_links($res->json->{pager}) },
|
||||
);
|
||||
};
|
||||
|
||||
sub show ($self)
|
||||
{
|
||||
my $v = $self->validation;
|
||||
|
Loading…
Reference in New Issue
Block a user