backend: implement /random/media and /random/tag

This commit is contained in:
Lucas 2023-02-21 19:55:12 +00:00
parent 88b5354529
commit 91d73cd314

View File

@ -60,7 +60,7 @@ hook before_template_render => sub {
$tokens->{uris}->{root} = uri_for("/"); $tokens->{uris}->{root} = uri_for("/");
$tokens->{uris}->{login} = uri_for("/login"); $tokens->{uris}->{login} = uri_for("/login");
$tokens->{uris}->{logout} = uri_for("/logout"); $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"); $tokens->{uris}->{tags} = uri_for("/tags");
}; };
@ -148,12 +148,22 @@ get "/media/:media_id" => sub {
}; };
}; };
get "/random" => sub { get "/random/media" => sub {
my $res = api_get("/random"); my $res = api_get("/random/media");
send_error("API error", 500) if !$res->{success}; send_error("API error", 500) if !$res->{success};
my $data = decode_json($res->{content}); 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; true;