From 71d31e625aa2bb162406d4ad395ba73776a3f1ea Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 17 Mar 2023 20:01:28 +0000 Subject: [PATCH] backend: merge Gallery controller into Media --- lib/PoorBooru/Backend.pm | 3 +- lib/PoorBooru/Backend/Controller/Gallery.pm | 38 --------------------- lib/PoorBooru/Backend/Controller/Media.pm | 28 +++++++++++++++ 3 files changed, 29 insertions(+), 40 deletions(-) delete mode 100644 lib/PoorBooru/Backend/Controller/Gallery.pm diff --git a/lib/PoorBooru/Backend.pm b/lib/PoorBooru/Backend.pm index 5917344..35b5355 100644 --- a/lib/PoorBooru/Backend.pm +++ b/lib/PoorBooru/Backend.pm @@ -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"); diff --git a/lib/PoorBooru/Backend/Controller/Gallery.pm b/lib/PoorBooru/Backend/Controller/Gallery.pm deleted file mode 100644 index b2033cb..0000000 --- a/lib/PoorBooru/Backend/Controller/Gallery.pm +++ /dev/null @@ -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; diff --git a/lib/PoorBooru/Backend/Controller/Media.pm b/lib/PoorBooru/Backend/Controller/Media.pm index bf9ac3c..cfceae7 100644 --- a/lib/PoorBooru/Backend/Controller/Media.pm +++ b/lib/PoorBooru/Backend/Controller/Media.pm @@ -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;