Архивировано
1
0
Ответвление 0
Этот коммит содержится в:
Lucas 2023-03-04 21:58:18 +00:00
родитель 7ccbc3af12
коммит 6ecf98f917
2 изменённых файлов: 23 добавлений и 0 удалений

Просмотреть файл

@ -24,6 +24,8 @@ sub startup ($self)
$r->get("/tags")->to("tags#list");
$r->get("/tag/:tag_id_or_name")->to("tags#show");
$r->get("/random/tag")->to("random#tag");
}
1;

21
lib/PoorBooru/API/V0/Controller/Random.pm Обычный файл
Просмотреть файл

@ -0,0 +1,21 @@
package PoorBooru::API::V0::Controller::Random;
use v5.36;
use strict;
use warnings;
use Mojo::Base "Mojolicious::Controller";
sub tag ($self)
{
my $tag = $self->schema->resultset("Tag")
->search({}, { order_by => \"random()", limit => 1 })->single;
return $self->render(
json => {error => "Tag not found"},
status => 404,
) if !defined($tag);
return $self->redirect_to("/tag/" . $tag->name);
}
1;