diff options
author | Matthew Somerville <matthew@mysociety.org> | 2013-02-07 18:08:58 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2013-02-07 18:09:05 +0000 |
commit | 3d631a9ee48fbff1741525f7ad9e9a530854d03b (patch) | |
tree | 0a1f2ad022fe90145fe78938fb7ca844dadb370f /perllib/FixMyStreet | |
parent | 54aeaf92acf5091c3b90d91848005893371e9590 (diff) |
Add hash as query parameter on photos so that rotating instantly works, no cache issues (fixes a3).
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App.pm | 21 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 31 |
2 files changed, 29 insertions, 23 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index b76f4d3ba..b57e78a9e 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -443,18 +443,27 @@ Hashref contains height, width and url keys. sub get_photo_params { my ($self, $key) = @_; - $key = ($key eq 'id') ? '' : "/$key"; return {} unless $self->photo; + $key = ($key eq 'id') ? '' : "/$key"; + + my $pre = "/photo$key/" . $self->id; + my $post = '.jpeg'; + my $str = \$self->photo; my $photo = {}; + if (length($self->photo) == 40) { - $photo->{url_full} = '/photo' . $key . '/' . $self->id . '.full.jpeg'; - } else { - ( $photo->{width}, $photo->{height} ) = - Image::Size::imgsize( \$self->photo ); + $post .= '?' . $self->photo; + $photo->{url_full} = "$pre.full$post"; + $str = FixMyStreet->config('UPLOAD_DIR') . $self->photo . '.jpeg'; } - $photo->{url} = '/photo' . $key . '/' . $self->id . '.jpeg'; + + ( $photo->{width}, $photo->{height} ) = Image::Size::imgsize( $str ); + + $photo->{url} = "$pre$post"; + $photo->{url_tn} = "$pre.tn$post"; + $photo->{url_fp} = "$pre.fp$post"; return $photo; } diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 10c0f3ce3..4fa9992f2 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -621,13 +621,7 @@ sub report_edit : Path('report_edit') : Args(1) { $c->forward('get_token'); - if ( $c->req->param('rotate_photo') ) { - $c->forward('rotate_photo'); - return 1; - } - if ( $c->cobrand->moniker eq 'zurich' ) { - FixMyStreet::Map::display_map( $c, latitude => $problem->latitude, @@ -641,7 +635,14 @@ sub report_edit : Path('report_edit') : Args(1) { } ] : [], ); + } + if ( $c->req->param('rotate_photo') ) { + $c->forward('rotate_photo'); + return 1; + } + + if ( $c->cobrand->moniker eq 'zurich' ) { my $done = $c->cobrand->admin_report_edit(); return if $done; } @@ -1320,7 +1321,7 @@ sub rotate_photo : Private { my ( $self, $c ) =@_; my $direction = $c->req->param('rotate_photo'); - return unless $direction =~ /Left/ or $direction =~ /Right/; + return unless $direction eq _('Rotate Left') or $direction eq _('Rotate Right'); my $photo = $c->stash->{problem}->photo; my $file; @@ -1331,14 +1332,12 @@ sub rotate_photo : Private { $photo = $file->slurp; } - $photo = _rotate_image( $photo, $direction =~ /Left/ ? -90 : 90 ); + $photo = _rotate_image( $photo, $direction eq _('Rotate Left') ? -90 : 90 ); return unless $photo; - my $fileid; - if ( !$file ) { - $fileid = sha1_hex($photo); - $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" ); - } + # Write out to new location + my $fileid = sha1_hex($photo); + $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" ); $c->stash->{rotated} = 1; @@ -1348,10 +1347,8 @@ sub rotate_photo : Private { unlink glob FixMyStreet->path_to( 'web', 'photo', $c->stash->{problem}->id . '.*' ); - if ( $fileid ) { - $c->stash->{problem}->photo( $fileid ); - $c->stash->{problem}->update(); - } + $c->stash->{problem}->photo( $fileid ); + $c->stash->{problem}->update(); return 1; } |