From 91d73cd314e317e2491b774aed9f7be4331ae6db Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 21 Feb 2023 19:55:12 +0000 Subject: [PATCH] backend: implement /random/media and /random/tag --- lib/PoorBooru.pm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/PoorBooru.pm b/lib/PoorBooru.pm index 2c7b6cf..2af4d6d 100644 --- a/lib/PoorBooru.pm +++ b/lib/PoorBooru.pm @@ -60,7 +60,7 @@ hook before_template_render => sub { $tokens->{uris}->{root} = uri_for("/"); $tokens->{uris}->{login} = uri_for("/login"); $tokens->{uris}->{logout} = uri_for("/logout"); - $tokens->{uris}->{random} = uri_for("/random"); + $tokens->{uris}->{random} = uri_for("/random/media"); $tokens->{uris}->{tags} = uri_for("/tags"); }; @@ -148,12 +148,22 @@ get "/media/:media_id" => sub { }; }; -get "/random" => sub { - my $res = api_get("/random"); +get "/random/media" => sub { + my $res = api_get("/random/media"); send_error("API error", 500) if !$res->{success}; my $data = decode_json($res->{content}); - forward "/media/" . $data->{id}; + # XXX body content. + redirect "/media/" . $data->{id}; +}; + +get "/random/tag" => sub { + my $res = api_get("/random/tag"); + send_error("API error", 500) if !$res->{success}; + + my $data = decode_json($res->{content}); + # XXX body content. + redirect "/tag/" . $data->{id}; }; true;