api: implement /media/tags/:media_id
This commit is contained in:
parent
ed8f8306b9
commit
945770eb1b
@ -32,6 +32,7 @@ sub startup ($self)
|
||||
|
||||
$r->get("/media")->to("media#list")->name("media_list");
|
||||
$r->get("/media/:media_id")->to("media#show")->name("media_show");
|
||||
$r->get("/media/tags/:media_id")->to("media#tags")->name("media_tags");
|
||||
|
||||
$r->get("/random/tag")->to("random#tag")->name("tag_random");
|
||||
$r->get("/random/media")->to("random#media")->name("media_random");
|
||||
|
@ -41,6 +41,25 @@ sub list ($self)
|
||||
};
|
||||
|
||||
sub show ($self)
|
||||
{
|
||||
my $media_id = $self->stash("media_id");
|
||||
my $media = $self->schema->resultset("Media")
|
||||
->single({ media_id => $media_id });
|
||||
|
||||
return $self->render(
|
||||
json => {error => "Media not found"},
|
||||
status => 404,
|
||||
) if !defined($media);
|
||||
|
||||
return $self->render(json => {
|
||||
id => $media->media_id,
|
||||
name => $media->filename,
|
||||
download => $media->seaweedfs_fid,
|
||||
content_type => $media->content_type,
|
||||
});
|
||||
};
|
||||
|
||||
sub tags ($self)
|
||||
{
|
||||
my $v = $self->validation;
|
||||
my $page = $v->optional("page")->num(1, undef)->param // 1;
|
||||
@ -65,10 +84,6 @@ sub show ($self)
|
||||
my @tags = map { $_->tag_name } $paged_media_tags->all;
|
||||
|
||||
return $self->render(json => {
|
||||
id => $media->media_id,
|
||||
name => $media->filename,
|
||||
download => $media->seaweedfs_fid,
|
||||
content_type => $media->content_type,
|
||||
tags => [ @tags ],
|
||||
pager => { $self->pager($paged_media_tags->pager) },
|
||||
});
|
||||
|
@ -13,8 +13,9 @@ sub index ($self)
|
||||
{ path => "/tags", verb => "GET" },
|
||||
{ path => "/tag/:tag_id_or_name", verb => "GET" },
|
||||
|
||||
{ path => "/media", verb => "GET" },
|
||||
{ path => "/media/:media_id", verb => "GET" },
|
||||
{ path => "/media", verb => "GET" },
|
||||
{ path => "/media/:media_id", verb => "GET" },
|
||||
{ path => "/media/tags/:media_id", verb => "GET" },
|
||||
|
||||
{ path => "/random/media", verb => "GET" },
|
||||
{ path => "/random/tag", verb => "GET" },
|
||||
|
Loading…
Reference in New Issue
Block a user