From 88b5354529b169022999b99d6c9911c9db178b56 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 21 Feb 2023 19:30:23 +0000 Subject: [PATCH] api: rename /random -> /random/media and implement /random/tag --- lib/PoorBooru/API/V0.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/PoorBooru/API/V0.pm b/lib/PoorBooru/API/V0.pm index 8105797..311aecf 100644 --- a/lib/PoorBooru/API/V0.pm +++ b/lib/PoorBooru/API/V0.pm @@ -114,6 +114,15 @@ get "/tag/:tag_id_or_name" => sub { }; }; +get "/random/tag" => sub { + my $tag = schema("default")->resultset("Tag") + ->search({}, { order_by => \"random()", limit => 1 })->single; + + send_error("Tag not found", 404) if !defined($tag); + + forward "/tag/" . $tag->tag_id; +}; + get "/media" => sub { my $page = query_parameters->get("page") // 1; send_error("Invalid page number", 400) if !validate_page_number($page); @@ -155,7 +164,7 @@ get "/download/:media_id" => sub { ); }; -get "/random" => sub { +get "/random/media" => sub { my $media = schema("default")->resultset("Media") ->search({}, { order_by => \"random()", limit => 1 })->single;