+ my $upload = $r->{ar}->upload("photo");
+ # Check $self->type
+ my @photos = ($self->upload_file($r, $upload->tempname, $upload->filename));
+ my @quarantined = grep { !$_->tags } @photos;
+ # Set it up to go again
+ if (@quarantined) {
+ $r->{session}{quarantined} = join ",", sort map { $_->id} @quarantined;
+ $r->objects(\@quarantined);
+ $r->template("quarantine");
+ return;
+ }
+ $r->objects(\@photos);
+ if (@photos == 0) { $r->template("upload"); return }
+ if (@photos > 1) { $r->template("list") }
+ else { $r->template("view"); }
+ $r->message("Thanks for the upload!");
+}
+
+sub quarantine :Exported {
+ my ($self, $r) = @_;
+ my @quarantined = split /,/, $r->{session}{quarantined};
+ my %q = map { $_ => 1 } @quarantined;
+ for (map /(\d+)/,grep /tags\d+/, keys %{$r->{params}}) {
+ my $tags = $r->{params}{"tags$_"};
+ next unless $tags;
+ if (my $photo = $self->retrieve($_)) {
+ $photo->add_tags($tags);
+ delete $q{$_};
+ }
+ }
+ $r->{session}{quarantined} = join ",", sort keys %q;
+ if (!$r->{session}{quarantined}) {
+ $r->template("list");
+ $r->objects([ map { $self->retrieve($_) } @quarantined ]);
+ } else {
+ $r->objects([ map { $self->retrieve($_) } sort keys %q ]);
+ }
+}
+
+sub upload_file {
+ my ($self, $r, $filename, $offered_name) = @_;
+ 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) {
+ 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 {
+ $r->message(basename($offered_name).": I can't handle $res files yet");
+ return ();
+ }
+}
+
+sub upload_archive {
+ my ($self, $r, $filename, $tags) = @_;
+ $r->{params}{title} = ""; # Kill that dead.
+ my $archive = Archive::Any->new($filename);
+ my $dir = tempdir();
+ $archive->extract($dir);
+ my @results;
+ find({ wanted => sub { return unless -f $_;
+ push @results, $self->upload_file($r, $_, $_) },
+ no_chdir => 1}, $dir);
+ rmtree($dir);
+ return @results;
+}