1 package Sesse::pr0n::Image;
5 use Sesse::pr0n::Common qw(error dberror);
10 my $dbh = Sesse::pr0n::Common::get_dbh();
12 # if ($r->connection->remote_ip() eq '80.212.251.227') {
13 # die "Har du lest FAQen?";
16 # Find the event and file name
17 my ($event,$filename,$xres,$yres,$dpr);
19 if ($r->path_info =~ m#^/([a-zA-Z0-9-]+)/original/((?:no)?box/)?([a-zA-Z0-9._()-]+)$#) {
22 $infobox = 'nobox' if (defined($2) && $2 eq 'nobox/');
23 $infobox = 'box' if (defined($2) && $2 eq 'box/');
24 } elsif ($r->path_info =~ m#^/([a-zA-Z0-9-]+)/(\d+)x(\d+)(?:\@(\d+(?:\.\d+)?))?/((?:no)?box/)?([a-zA-Z0-9._()-]+)$#) {
30 $infobox = 'nobox' if (defined($5) && $5 eq 'nobox/');
31 $infobox = 'box' if (defined($5) && $5 eq 'box/');
32 } elsif ($r->path_info =~ m#^/([a-zA-Z0-9-]+)/((?:no)?box/)?([a-zA-Z0-9._()-]+)$#) {
37 $infobox = 'nobox' if (defined($2) && $2 eq 'nobox/');
38 $infobox = 'box' if (defined($2) && $2 eq 'box/');
42 my ($id, $dbwidth, $dbheight);
43 #if ($event eq 'single' && $filename =~ /^(\d+)\.jpeg$/) {
47 # Look it up in the database
48 my $ref = $dbh->selectrow_hashref('SELECT id,width,height FROM images WHERE event=? AND vhost=? AND filename=?',
49 undef, $event, Sesse::pr0n::Common::get_server_name($r), $filename);
50 return error($r, "Could not find $event/$filename", 404, "File not found") unless (defined($ref));
53 $dbwidth = $ref->{'width'};
54 $dbheight = $ref->{'height'};
56 # Scale if we need to do so
57 my ($fname, $mime_type) = Sesse::pr0n::Common::ensure_cached($r, $filename, $id, $dbwidth, $dbheight, $infobox, $dpr, $xres, $yres);
59 # Output the image to the user
60 my $res = Plack::Response->new(200);
62 if (!defined($mime_type)) {
63 $mime_type = Sesse::pr0n::Common::get_mimetype_from_filename($filename);
65 $res->content_type($mime_type);
67 my (undef, undef, undef, undef, undef, undef, undef, $size, undef, $mtime) = stat($fname)
68 or return error($r, "stat of $fname: $!");
70 $res->content_length($size);
71 Sesse::pr0n::Common::set_last_modified($res, $mtime);
73 # # If the client can use cache, by all means do so
74 #if ((my $rc = $r->meets_conditions) != Apache2::Const::OK) {
78 $res->content(IO::File::WithPath->new($fname));