]> git.decadent.org.uk Git - memories.git/commitdiff
Mess around with things to make it easier to support multiple file
authorSimon Cozens <simon@simon-cozens.org>
Fri, 16 Feb 2007 22:31:28 +0000 (22:31 +0000)
committerSimon Cozens <simon@simon-cozens.org>
Fri, 16 Feb 2007 22:31:28 +0000 (22:31 +0000)
uploads, quarantining and multiple file types. References #8, #10, #14.

git-svn-id: http://svn.simon-cozens.org/memories/trunk@33 041978f6-d955-411f-a9d7-1d8545c9c3c7

Memories/Photo.pm

index d14619ee03cd0440ba42d354438658a03d368d5c..8286480aa1f952191c75216b33664978e48f3379 100644 (file)
@@ -1,4 +1,7 @@
 package Memories::Photo;
+use File::Basename;
+use File::Copy;
+use Archive::Any;
 use strict;
 use Carp qw(cluck confess);
 use base qw(Memories::DBI Maypole::Model::CDBI::Plain);
@@ -43,52 +46,48 @@ __PACKAGE__->has_a(uploaded => "Time::Piece",
 
 sub do_upload :Exported {
     my ($self, $r) = @_;
-    my %upload = $r->upload("photo");
+    my $upload = $r->{ar}->upload("photo");
+    # Check $self->type
+    my @photos = $self->upload_jpeg($upload->tempname, ($r->params->{title}||basename($upload->filename)), $r->params->{tags}, $r);
+    my @quarantined = grep { !$_->tags } @photos;
+    # Set it up to go again
+    $r->objects(\@photos);
+    $r->template("view");
+    $r->message("Thanks for the upload!"); 
+    # Deal with the quarantined
+}
 
+sub upload_jpeg {
+    my ($self, $filename, $title, $tags, $r) = @_;
+    my $quarantine;
     my $photo = $self->create({
         uploader => $r->user,
         uploaded => Time::Piece->new(),
-        title => $r->params->{title},
+        title => $title,
         hit_count => 0,
         rating => 0,
-        rated => 0, # Oh, the potential for divide by zero errors...
+        rated => 0,
     });
-
-    # Dump content
-    if (!open OUT, ">". $photo->path("file")) {
-        die "Can't write ".$photo->path("file")." because $!";
-    }
-    # XXX Check it's a JPEG, etc.
-    # XXX Unzip ZIP file
-    print OUT $upload{content};
-    close OUT;
+    copy($filename, $photo->path("file"));
     my ($x, $y) = dim(image_info($photo->path));
     $photo->x($x); $photo->y($y);
 
     # Rotate?
     $photo->unrotate(); 
     if (!$photo->title){ 
-        $photo->title($photo->title_exif || $upload{filename});
+        $photo->title($photo->title_exif || basename($filename));
     }
 
     $photo->make_thumb;
-    $r->{params}{tags} ||= join " ", map { qq{"$_"} } $photo->tags_exif;
-    $photo->add_tags($r->{params}{tags});
+    $tags ||= join " ", map { qq{"$_"} } $photo->tags_exif;
+    $photo->add_tags($tags);
     $photo->add_to_imageseek_library;
     Memories->zap_cache();
 
     # Add system tags here
     my $tag = "date:".$photo->shot->ymd;
     $photo->add_to_system_tags({tag => Memories::SystemTag->find_or_create({name =>$tag}) });
-
-    # Set it up to go again
-    $r->objects([$photo]);
-    $r->template("view");
-    $r->message("Thanks for the upload! ".
-        ($r->{params}{tags} ? "" 
-        : "Don't forget to <a href=\"?".$r->config->uri_base."photo/view/".$photo->id."?active=tagedit\">tag your photo</a>"
-        )
-    ); 
+    return $photo;
 }
 
 sub approx_rating {