backend: make SeaweedFS::Client::url_for accept a scalar too
This commit is contained in:
parent
396ab297a8
commit
aa3e60d188
@ -5,7 +5,6 @@ use warnings;
|
||||
|
||||
use Mojo::Base "Mojolicious::Controller";
|
||||
use Mojo::JSON qw(decode_json);
|
||||
use SeaweedFS::FID;
|
||||
|
||||
sub list ($self)
|
||||
{
|
||||
@ -24,9 +23,7 @@ sub list ($self)
|
||||
$self->title("Pooru~");
|
||||
my @media = map +{
|
||||
media_link => $self->url_for("media_show", media_id => $_->{media_id}),
|
||||
media_src => $self->seaweed->url_for(
|
||||
SeaweedFS::FID->from_string($_->{seaweedfs_fid})
|
||||
),
|
||||
media_src => $self->seaweed->url_for($_->{seaweedfs_fid}),
|
||||
}, $res->json->{media}->@*;
|
||||
|
||||
return $self->render(
|
||||
@ -51,8 +48,7 @@ sub show ($self)
|
||||
return $self->render(status => $res->code) if $res->is_error;
|
||||
|
||||
my $media = $res->json;
|
||||
$media->{download} = $self->seaweed->url_for(SeaweedFS::FID
|
||||
->from_string($media->{download}));
|
||||
$media->{download} = $self->seaweed->url_for($media->{download});
|
||||
|
||||
return $self->render(
|
||||
template => "media",
|
||||
|
@ -5,7 +5,6 @@ use warnings;
|
||||
|
||||
use Mojo::Base "Mojolicious::Controller";
|
||||
use Mojo::JSON qw(decode_json);
|
||||
use SeaweedFS::FID;
|
||||
|
||||
sub list ($self)
|
||||
{
|
||||
@ -51,9 +50,7 @@ sub show ($self)
|
||||
$self->title($res->json->{name});
|
||||
my @media = map +{
|
||||
media_link => $self->url_for("media_show", media_id => $_->{media_id}),
|
||||
media_src => $self->seaweed->url_for(
|
||||
SeaweedFS::FID->from_string($_->{seaweedfs_fid})
|
||||
),
|
||||
media_src => $self->seaweed->url_for($_->{seaweedfs_fid}),
|
||||
}, $res->json->{media}->@*;
|
||||
|
||||
return $self->render(
|
||||
|
@ -5,7 +5,7 @@ use warnings;
|
||||
|
||||
use Carp;
|
||||
use List::Util qw(sample);
|
||||
use Scalar::Util qw(openhandle);
|
||||
use Scalar::Util qw(blessed);
|
||||
|
||||
use Mojo::UserAgent;
|
||||
use SeaweedFS::FID;
|
||||
@ -30,8 +30,18 @@ sub get
|
||||
|
||||
sub url_for
|
||||
{
|
||||
my ($self, $fid) = @_;
|
||||
my ($self, $p) = @_;
|
||||
|
||||
my $fid;
|
||||
if (defined(blessed $p) && $p->can("volume_id")) {
|
||||
$fid = $p;
|
||||
} elsif (!defined(blessed $p)) {
|
||||
eval {
|
||||
$fid = SeaweedFS::FID->from_string($p);
|
||||
} or $fid = SeaweedFS::FID->from_bin($p);
|
||||
} else {
|
||||
croak "Unsupported FID type " . blessed($p);
|
||||
}
|
||||
my $vid = $fid->volume_id;
|
||||
|
||||
if (!defined($self->{_vurls}{$vid}) || $self->{_vurls}{$vid}->@* == 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user