diff --git a/lib/PoorBooru/Backend.pm b/lib/PoorBooru/Backend.pm index 41328f1..5917344 100644 --- a/lib/PoorBooru/Backend.pm +++ b/lib/PoorBooru/Backend.pm @@ -43,6 +43,8 @@ sub startup ($self) $r->get("/")->to("gallery#index"); + $r->get("/media/:media_id")->to("media#show"); + $r->get("/tags")->to("tags#list"); $r->get("/tag/:tag_id_or_name")->to("tags#show"); } diff --git a/lib/PoorBooru/Backend/Controller/Media.pm b/lib/PoorBooru/Backend/Controller/Media.pm new file mode 100644 index 0000000..bf9ac3c --- /dev/null +++ b/lib/PoorBooru/Backend/Controller/Media.pm @@ -0,0 +1,35 @@ +package PoorBooru::Backend::Controller::Media; +use v5.36; +use strict; +use warnings; + +use Mojo::Base "Mojolicious::Controller"; +use Mojo::JSON qw(decode_json); +use SeaweedFS::FID; + +sub show ($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 $media_id = $self->stash("media_id"); + my $poorbooru_api = $self->config("poorbooru_api"); + my $res = $self->ua->get("$poorbooru_api/media/$media_id?page=$page") + ->result; + + return $self->render(status => $res->code) if $res->is_error; + + my $media = $res->json; + $media->{download} = $self->seaweed->url_for(SeaweedFS::FID + ->from_string($media->{download})); + + return $self->render( + template => "media", + media => $media, + #pager => { $self->pager_links($res->json->{pager}) }, + ); +}; + +1; diff --git a/templates/media.html.ep b/templates/media.html.ep new file mode 100644 index 0000000..849d009 --- /dev/null +++ b/templates/media.html.ep @@ -0,0 +1,20 @@ +% layout "main"; + +

+ <%= link_to $media->{download} => begin %> + <%= image $media->{download} %> + <% end %> +

+ +
+
ID
+
<%= $media->{id} %>
+
Upload name
+
<%= $media->{name} %>
+
Content-Type
+
<%= $media->{content_type} %>
+
Tags
+<% for my $tag ($media->{tags}->@*) { %> +
<%= $tag %>
+<% } %> +