api: rename /random -> /random/media and implement /random/tag

This commit is contained in:
Lucas 2023-02-21 19:30:23 +00:00
parent ad6a6cb9c0
commit 88b5354529

View File

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