diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Photo.pm | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Model/PhotoSet.pm | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/PhotoStorage/FileSystem.pm | 5 |
3 files changed, 27 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index 4ae25db24..5712350ed 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -5,8 +5,7 @@ use namespace::autoclean; BEGIN {extends 'Catalyst::Controller'; } use JSON::MaybeXS; -use File::Path; -use File::Slurp; +use Path::Tiny; use Try::Tiny; use FixMyStreet::App::Model::PhotoSet; @@ -81,8 +80,10 @@ sub output : Private { my ( $self, $c, $photo ) = @_; # Save to file - File::Path::make_path( FixMyStreet->path_to( 'web', 'photo', 'c' )->stringify ); - File::Slurp::write_file( FixMyStreet->path_to( 'web', $c->req->path )->stringify, \$photo->{data} ); + path(FixMyStreet->path_to('web', 'photo', 'c'))->mkpath; + my $out = FixMyStreet->path_to('web', $c->req->path); + my $symlink_exists = symlink($photo->{symlink}, $out) if $photo->{symlink}; + path($out)->spew_raw($photo->{data}) unless $symlink_exists; $c->res->content_type( $photo->{content_type} ); $c->res->body( $photo->{data} ); diff --git a/perllib/FixMyStreet/App/Model/PhotoSet.pm b/perllib/FixMyStreet/App/Model/PhotoSet.pm index 21bde52d8..f209a2aed 100644 --- a/perllib/FixMyStreet/App/Model/PhotoSet.pm +++ b/perllib/FixMyStreet/App/Model/PhotoSet.pm @@ -16,8 +16,10 @@ use IPC::Cmd qw(can_run); use IPC::Open3; use MIME::Base64; +use FixMyStreet; use FixMyStreet::PhotoStorage; +# Attached Catalyst app, if present, for feeding back errors during photo upload has c => ( is => 'ro', ); @@ -71,6 +73,15 @@ has storage => ( } ); +has symlinkable => ( + is => 'ro', + lazy => 1, + default => sub { + my $cfg = FixMyStreet->config('PHOTO_STORAGE_OPTIONS'); + return $cfg ? $cfg->{SYMLINK_FULL_SIZE} : 0; + } +); + =head2 C<ids>, C<num_images>, C<get_id>, C<all_ids> C<$photoset-E<GT>ids> is an arrayref containing the fileid data. @@ -184,9 +195,10 @@ has ids => ( # Arrayref of $fileid tuples (always, so post upload/raw data proc sub get_raw_image { my ($self, $index) = @_; my $filename = $self->get_id($index); - my ($photo, $type) = $self->storage->retrieve_photo($filename); + my ($photo, $type, $object) = $self->storage->retrieve_photo($filename); if ($photo) { return { + $object ? (object => $object) : (), data => $photo, content_type => "image/$type", extension => $type, @@ -203,6 +215,12 @@ sub get_image_data { my $photo = $image->{data}; my $size = $args{size}; + + if ($self->symlinkable && $image->{object} && $size eq 'full') { + $image->{symlink} = delete $image->{object}; + return $image; + } + if ( $size eq 'tn' ) { $photo = _shrink( $photo, 'x100' ); } elsif ( $size eq 'fp' ) { diff --git a/perllib/FixMyStreet/PhotoStorage/FileSystem.pm b/perllib/FixMyStreet/PhotoStorage/FileSystem.pm index 772286d53..1d3fe5cfd 100644 --- a/perllib/FixMyStreet/PhotoStorage/FileSystem.pm +++ b/perllib/FixMyStreet/PhotoStorage/FileSystem.pm @@ -70,7 +70,8 @@ sub store_photo { =head2 retrieve_photo Fetches the file content of a particular photo from storage. -Returns the binary blob and the filetype, if the photo exists in storage. +Returns the binary blob, the filetype, and the file path, if +the photo exists in storage. =cut @@ -81,7 +82,7 @@ sub retrieve_photo { my $file = $self->get_file($fileid, $type); if ($file->exists) { my $photo = $file->slurp_raw; - return ($photo, $type); + return ($photo, $type, $file); } } |