diff options
author | Dave Arter <davea@mysociety.org> | 2018-09-28 16:20:09 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2018-09-28 16:20:09 +0100 |
commit | aedfb6de6b4839396b8bcc885e075b28ea9b4885 (patch) | |
tree | 1ac3c9d0148b3f98ff29985e8c760740bb8d2548 /perllib/FixMyStreet/PhotoStorage.pm | |
parent | ec55469dadd99dd0f20d3d0c3b4202b6b70bb6ab (diff) | |
parent | 07bc1188dc149e05b61e0d93ecf3ef1c26dc8690 (diff) |
Merge branch 'pluggable-photo-storage'
Diffstat (limited to 'perllib/FixMyStreet/PhotoStorage.pm')
-rw-r--r-- | perllib/FixMyStreet/PhotoStorage.pm | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/PhotoStorage.pm b/perllib/FixMyStreet/PhotoStorage.pm new file mode 100644 index 000000000..a441fb718 --- /dev/null +++ b/perllib/FixMyStreet/PhotoStorage.pm @@ -0,0 +1,41 @@ +package FixMyStreet::PhotoStorage; + +use Moose; +use Digest::SHA qw(sha1_hex); +use Module::Load; +use FixMyStreet; + +our $instance; # our, so tests can set to undef when testing different backends +sub backend { + return $instance if $instance; + my $class = 'FixMyStreet::PhotoStorage::'; + $class .= FixMyStreet->config('PHOTO_STORAGE_BACKEND') || 'FileSystem'; + load $class; + $instance = $class->new(); + return $instance; +} + +sub detect_type { + my ($self, $photo) = @_; + return 'jpeg' if $photo =~ /^\x{ff}\x{d8}/; + return 'png' if $photo =~ /^\x{89}\x{50}/; + return 'tiff' if $photo =~ /^II/; + return 'gif' if $photo =~ /^GIF/; + return ''; +} + +=head2 get_fileid + +Calculates an identifier for a binary blob of photo data. +This is just the SHA1 hash of the blob currently. + +=cut + +sub get_fileid { + my ($self, $photo_blob) = @_; + return sha1_hex($photo_blob); +} + + + +1; |