site: use no_redirect for randomized endpoints

As a really nice consequence, drop max_redirects from Mojo::UserAgent.
This commit is contained in:
Lucas Gabriel Vuotto 2025-05-03 17:57:42 +00:00
parent c1463b36ef
commit 7d8d873fc4
2 changed files with 7 additions and 7 deletions

View file

@ -96,8 +96,7 @@ sub startup ($self)
$self->ua
->connect_timeout(5)
->inactivity_timeout(5)
->max_redirects(1);
->inactivity_timeout(5);
my $r = $self->routes;

View file

@ -7,7 +7,8 @@ sub media ($self)
{
$self->render_later;
my $endpoint = $self->api_v0_url->path("random/media");
my $endpoint = $self->api_v0_url
->path("random/media")->query(no_redirect => 1);
$self->ua->get_p($endpoint)->then(sub ($tx) {
return $self->render(
text => "Backend error.",
@ -15,7 +16,7 @@ sub media ($self)
) if $tx->error;
return $self->redirect_to("show_media",
media_id => $tx->res->json->{id});
media_id => $tx->res->json);
})->wait;
}
@ -23,16 +24,16 @@ sub tag ($self)
{
$self->render_later;
my $endpoint = $self->api_v0_url->path("random/tag");
my $endpoint = $self->api_v0_url
->path("random/tag")->query(no_redirect => 1);
$self->ua->get_p($endpoint)->then(sub ($tx) {
return $self->render(
text => "Backend error.",
status => 500,
) if $tx->error;
my %tag = $tx->res->json->%*;
my $url = $self->url_for("list_media")
->query(tags => $tag{display} . " ");
->query(tags => $tx->res->json . " ");
return $self->redirect_to($url);
})->wait;
}