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 (nobox/ is for compatibility with legacy URLs).
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 = 1 if (defined($2) && $2 eq 'box/');
23 } elsif ($r->path_info =~ m#^/([a-zA-Z0-9-]+)/(\d+)x(\d+)(?:\@(\d+(?:\.\d+)?))?/((?:no)?box/)?([a-zA-Z0-9._()-]+)$#) {
29 $infobox = 1 if (defined($5) && $5 eq 'box/');
30 } elsif ($r->path_info =~ m#^/([a-zA-Z0-9-]+)/((?:no)?box/)?([a-zA-Z0-9._()-]+)$#) {
35 $infobox = 1 if (defined($2) && $2 eq 'box/');
39 my ($id, $dbwidth, $dbheight);
40 #if ($event eq 'single' && $filename =~ /^(\d+)\.jpeg$/) {
44 # Look it up in the database
45 my $ref = $dbh->selectrow_hashref('SELECT id,width,height FROM images WHERE event=? AND vhost=? AND filename=?',
46 undef, $event, Sesse::pr0n::Common::get_server_name($r), $filename);
47 return error($r, "Could not find $event/$filename", 404, "File not found") unless (defined($ref));
50 $dbwidth = $ref->{'width'};
51 $dbheight = $ref->{'height'};
53 # Scale if we need to do so
54 my ($fname, $mime_type);
56 ($fname, $mime_type) = Sesse::pr0n::Common::ensure_infobox_cached($r, $filename, $id, $dbwidth, $dbheight, $dpr, $xres, $yres);
58 ($fname, $mime_type) = Sesse::pr0n::Common::ensure_cached($r, $filename, $id, $dbwidth, $dbheight, $xres, $yres);
61 # Output the image to the user
62 my $res = Plack::Response->new(200);
64 if (!defined($mime_type)) {
65 $mime_type = Sesse::pr0n::Common::get_mimetype_from_filename($filename);
67 $res->content_type($mime_type);
69 my (undef, undef, undef, undef, undef, undef, undef, $size, undef, $mtime) = stat($fname)
70 or return error($r, "stat of $fname: $!");
72 $res->content_length($size);
73 Sesse::pr0n::Common::set_last_modified($res, $mtime);
75 # # If the client can use cache, by all means do so
76 #if ((my $rc = $r->meets_conditions) != Apache2::Const::OK) {
80 $res->content(IO::File::WithPath->new($fname));