aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2011-06-16 15:09:44 +0100
committerMatthew Somerville <matthew@mysociety.org>2011-06-16 15:09:44 +0100
commit08d17efdfe76958fa1e74bfe4aac58a000925ee0 (patch)
tree597e14f8445666ebbd231d1f3d1c7ea8671e653b
parent46bff543ca0bf97a5fcef8944de5c5111e1ac054 (diff)
Adapt to Google's image bot requesting strange URLs - can't see them anywhere on the site...
-rw-r--r--perllib/FixMyStreet/App/Controller/Photo.pm17
1 files changed, 13 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm
index ac0c891d4..17862aa0a 100644
--- a/perllib/FixMyStreet/App/Controller/Photo.pm
+++ b/perllib/FixMyStreet/App/Controller/Photo.pm
@@ -30,8 +30,7 @@ sub index :Path :Args(0) {
my $id = $c->req->param('id');
my $comment = $c->req->param('c');
- $c->detach( '/page_error_404_not_found', [ 'No photo' ] )
- unless $id || $comment;
+ $c->detach( 'no_photo' ) unless $id || $comment;
my @photo;
if ( $comment ) {
@@ -41,6 +40,12 @@ sub index :Path :Args(0) {
photo => { '!=', undef },
} );
} else {
+ # GoogleBot-Image is doing this for some reason?
+ if ( $id =~ m{ ^(\d+) \D .* $ }x ) {
+ return $c->res->redirect( $c->uri_with( { id => $1 } ), 301 );
+ }
+
+ $c->detach( 'no_photo' ) if $id =~ /\D/;
@photo = $c->cobrand->problems->search( {
id => $id,
state => [ 'confirmed', 'fixed', 'partial' ],
@@ -48,8 +53,7 @@ sub index :Path :Args(0) {
} );
}
- $c->detach( '/page_error_404_not_found', [ 'No photo' ] )
- unless @photo;
+ $c->detach( 'no_photo' ) unless @photo;
my $photo = $photo[0]->photo;
if ( $c->req->param('tn' ) ) {
@@ -66,6 +70,11 @@ sub index :Path :Args(0) {
$c->res->body( $photo );
}
+sub no_photo : Private {
+ my ( $self, $c ) = @_;
+ $c->detach( '/page_error_404_not_found', [ 'No photo' ] );
+}
+
sub _resize {
my ($photo, $size) = @_;
use Image::Magick;