backend: merge Gallery controller into Media

This commit is contained in:
Lucas 2023-03-17 20:01:28 +00:00
parent fc407c608e
commit 71d31e625a
3 changed files with 29 additions and 40 deletions

View File

@ -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");

View File

@ -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;

View File

@ -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;