api: make /media parse seaweedfs_fid

This commit is contained in:
Lucas 2023-03-05 20:43:20 +00:00
parent 70191db656
commit af536b9cf6
2 changed files with 5 additions and 2 deletions

View File

@ -4,6 +4,7 @@ use strict;
use warnings; use warnings;
use Mojo::Base "Mojolicious::Controller"; use Mojo::Base "Mojolicious::Controller";
use SeaweedFS::FID;
my $MEDIA_SEARCH_OPTS = { my $MEDIA_SEARCH_OPTS = {
order_by => { -desc => "media_id" }, order_by => { -desc => "media_id" },
@ -31,7 +32,7 @@ sub list ($self)
->search({}, $MEDIA_SEARCH_OPTS)->page($page); ->search({}, $MEDIA_SEARCH_OPTS)->page($page);
my @media = map +{ my @media = map +{
media_id => $_->media_id, media_id => $_->media_id,
seaweedfs_fid => $_->seaweedfs_fid, seaweedfs_fid => SeaweedFS::FID->from_bin($_->seaweedfs_fid),
}, $paged_media->all; }, $paged_media->all;
return $self->render(json => { return $self->render(json => {

View File

@ -24,7 +24,9 @@ sub index ($self)
return $self->render(status => $res->code) if $res->is_error; return $self->render(status => $res->code) if $res->is_error;
my @media = map +{ my @media = map +{
media_src => $self->seaweed->url_for(SeaweedFS::FID->from_bin($_->{seaweedfs_fid})), media_src => $self->seaweed->url_for(
SeaweedFS::FID->from_string($_->{seaweedfs_fid})
),
}, @{$res->json->{media}}; }, @{$res->json->{media}};
return $self->render(template => "gallery", media => \@media); return $self->render(template => "gallery", media => \@media);