use File::Basename;
use File::Copy;
use Archive::Any;
-use File::Temp qw(tempdir);
+use File::Temp qw(tempdir tmpnam);
use File::Path qw(rmtree);
use File::Find;
use File::MMagic;
use Time::Piece;
use Image::Seek;
use constant PAGER_SYNTAX => "LimitXY";
-__PACKAGE__->columns(Essential => qw(id title uploader uploaded x y rating rated hit_count));
+__PACKAGE__->columns(Essential => qw(id title uploader uploaded x y rating rated hit_count format));
__PACKAGE__->untaint_columns(printable => [qw/title/]);
__PACKAGE__->columns(TEMP => qw/exif_object/);
my $mm = File::MMagic->new;
my $res = $mm->checktype_filename($filename);
warn "$filename is a $res\n";
- if ($res =~ m{/x-zip} or $offered_name =~ /t(ar\.)?gz/i) {
+ if ($res =~ m{/x-zip} or $offered_name =~ /t(ar\.)?gz$/i) {
return $self->upload_archive($r, $filename);
+ } elsif ($offered_name =~ /\.(raw|nef)/i) {
+ return $self->upload_raw($r, $filename, $offered_name);
} elsif ($res =~ m{image/jpeg}) {
return $self->upload_jpeg($r, $filename, $offered_name);
} else {
return @results;
}
+sub upload_raw {
+ my ($self, $r, $filename, $offered_name) = @_;
+ my $jpg = tmpnam().".jpg";
+ system("dcraw -c $filename | convert - $jpg");
+ my $photo = $self->upload_jpeg($r, $jpg, $offered_name);
+ $filename =~ /\.(.*)$/;
+ my $format = $1;
+ $photo->format($format);
+ # Put the file in place
+ copy($filename,
+ Memories->config->{data_store}."/".$photo->id.".".$format);
+ return $photo;
+}
+
sub upload_jpeg {
my ($self, $r, $filename, $offered_name) = @_;
my $photo = $self->create({
});
}
-sub format {
- "jpg" # For now
-}
-
use Cache::MemoryCache;
use Image::Info qw(dim image_info);
use Image::ExifTool;
# Make dir if it doesn't exist, save trouble later
use File::Path;
if ($is_url ne "url") {mkpath($path);}
- $path .= $self->id.".".$self->format;
+ if ($scale or $is_url ne "url") {
+ $path .= $self->id.".jpg";
+ } else {
+ $path .= $self->id.".".($self->format||"jpg");
+ }
return $path;
}