diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Photo.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Photo.pm | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index bc72f4bfb..e8025e0a1 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -69,7 +69,7 @@ sub index :LocalRegex('^(c/)?(\d+)(?:\.(\d+))?(?:\.(full|tn|fp))?\.jpeg$') { $c->detach( 'no_photo' ) if $id =~ /\D/; ($item) = $c->cobrand->problems->search( { id => $id, - state => [ FixMyStreet::DB::Result::Problem->visible_states(), 'partial' ], + state => [ FixMyStreet::DB::Result::Problem->visible_states() ], photo => { '!=', undef }, } ); } @@ -150,6 +150,33 @@ sub _crop { return $blobs[0]; } +sub upload : Local { + my ( $self, $c ) = @_; + my @items = ( + ( map { + /^photo/ ? # photo, photo1, photo2 etc. + ($c->req->upload($_)) : () + } sort $c->req->upload), + ); + my $photoset = FixMyStreet::App::Model::PhotoSet->new({ + c => $c, + data_items => \@items, + }); + + my $fileid = $photoset->data; + my $out; + if ($c->stash->{photo_error} || !$fileid) { + $c->res->status(500); + $out = { error => $c->stash->{photo_error} || _('Unknown error') }; + } else { + $out = { id => $fileid }; + } + + my $body = JSON->new->utf8(1)->encode($out); + $c->res->content_type('application/json; charset=utf-8'); + $c->res->body($body); +} + =head2 process_photo Handle the photo - either checking and storing it after an upload or retrieving |