aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Photo.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-03-08 14:05:01 +0000
committerMatthew Somerville <matthew@mysociety.org>2012-03-08 14:05:01 +0000
commit1a5baa677635b0fb981bd4cf83e1843f8d5ef8ab (patch)
treef86ee8c99fd6269b925640dc2bb3ebb44ee279ce /perllib/FixMyStreet/App/Controller/Photo.pm
parent410d1f1edc737d1d60e83f90053fe028eff3de30 (diff)
Store full size photos that are uploaded on filesystem, put hash in database. Fixes #9, basics for #209 (needs light box adding).
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Photo.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Photo.pm46
1 files changed, 38 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm
index 3f55e4692..3ca7f13a9 100644
--- a/perllib/FixMyStreet/App/Controller/Photo.pm
+++ b/perllib/FixMyStreet/App/Controller/Photo.pm
@@ -5,6 +5,7 @@ use namespace::autoclean;
BEGIN {extends 'Catalyst::Controller'; }
use DateTime::Format::HTTP;
+use Path::Class;
=head1 NAME
@@ -25,17 +26,30 @@ Display a photo
=cut
-sub index :Path :Args(0) {
+sub during :LocalRegex('^([0-9a-f]{40})\.temp\.jpeg$') {
my ( $self, $c ) = @_;
+ my ( $hash ) = @{ $c->req->captures };
- my $id = $c->req->param('id');
- my $comment = $c->req->param('c');
- $c->detach( 'no_photo' ) unless $id || $comment;
+ my $file = file( $c->config->{UPLOAD_DIR}, "$hash.jpeg" );
+ my $photo = $file->slurp;
+
+ if ( $c->cobrand->default_photo_resize ) {
+ $photo = _shrink( $photo, $c->cobrand->default_photo_resize );
+ } else {
+ $photo = _shrink( $photo, 'x250' );
+ }
+
+ $c->forward( 'output', [ $photo ] );
+}
+
+sub index :LocalRegex('^(c/)?(\d+)(?:\.(full|tn|fp))?\.jpeg$') {
+ my ( $self, $c ) = @_;
+ my ( $is_update, $id, $size ) = @{ $c->req->captures };
my @photo;
- if ( $comment ) {
+ if ( $is_update ) {
@photo = $c->model('DB::Comment')->search( {
- id => $comment,
+ id => $id,
state => 'confirmed',
photo => { '!=', undef },
} );
@@ -56,14 +70,30 @@ sub index :Path :Args(0) {
$c->detach( 'no_photo' ) unless @photo;
my $photo = $photo[0]->photo;
- if ( $c->req->param('tn' ) ) {
+
+ # If photo field contains a hash
+ if (length($photo) == 40) {
+ my $file = file( $c->config->{UPLOAD_DIR}, "$photo.jpeg" );
+ $photo = $file->slurp;
+ }
+
+ if ( $size eq 'tn' ) {
$photo = _shrink( $photo, 'x100' );
- } elsif ( $c->req->param('fp' ) ) {
+ } elsif ( $size eq 'fp' ) {
$photo = _crop( $photo );
+ } elsif ( $size eq 'full' ) {
} elsif ( $c->cobrand->default_photo_resize ) {
$photo = _shrink( $photo, $c->cobrand->default_photo_resize );
+ } else {
+ $photo = _shrink( $photo, 'x250' );
}
+ $c->forward( 'output', [ $photo ] );
+}
+
+sub output : Private {
+ my ( $self, $c, $photo ) = @_;
+
my $dt = DateTime->now();
$dt->set_year( $dt->year + 1 );