X-Git-Url: https://git.sesse.net/?p=pr0n;a=blobdiff_plain;f=perl%2FSesse%2Fpr0n%2FImage.pm;h=da45cfbd098571baece177482b5f795549c2d04f;hp=e436428950b6adc9d5a8e56e23755d3eab4ae710;hb=133c9fb7f197da55e8b85e98a17ae6a184a28832;hpb=6e87d26481ba152a8504c3c6c8650d1927206331 diff --git a/perl/Sesse/pr0n/Image.pm b/perl/Sesse/pr0n/Image.pm index e436428..da45cfb 100644 --- a/perl/Sesse/pr0n/Image.pm +++ b/perl/Sesse/pr0n/Image.pm @@ -15,57 +15,47 @@ sub handler { # Find the event and file name my ($event,$filename,$xres,$yres); - my $infobox = 1; - if ($r->uri =~ m#^/([a-zA-Z0-9-]+)/original/(nobox/)?([a-zA-Z0-9._-]+)$#) { + my $infobox = 'both'; + if ($r->uri =~ m#^/([a-zA-Z0-9-]+)/original/((?:no)?box/)?([a-zA-Z0-9._()-]+)$#) { $event = $1; $filename = $3; - } elsif ($r->uri =~ m#^/([a-zA-Z0-9-]+)/(\d+)x(\d+)/(nobox/)?([a-zA-Z0-9._-]+)$#) { + $infobox = 'nobox' if (defined($2) && $2 eq 'nobox/'); + $infobox = 'box' if (defined($2) && $2 eq 'box/'); + } elsif ($r->uri =~ m#^/([a-zA-Z0-9-]+)/(\d+)x(\d+)/((?:no)?box/)?([a-zA-Z0-9._()-]+)$#) { $event = $1; $filename = $5; $xres = $2; $yres = $3; - $infobox = 0 if (defined($4)); - } elsif ($r->uri =~ m#^/([a-zA-Z0-9-]+)/(nobox/)?([a-zA-Z0-9._-]+)$#) { + $infobox = 'nobox' if (defined($4) && $4 eq 'nobox/'); + $infobox = 'box' if (defined($4) && $4 eq 'box/'); + } elsif ($r->uri =~ m#^/([a-zA-Z0-9-]+)/((?:no)?box/)?([a-zA-Z0-9._()-]+)$#) { $event = $1; $filename = $3; $xres = -1; $yres = -1; - $infobox = 0 if (defined($2)); + $infobox = 'nobox' if (defined($2) && $2 eq 'nobox/'); + $infobox = 'box' if (defined($2) && $2 eq 'box/'); } my ($id, $dbwidth, $dbheight); - if ($event eq 'single' && $filename =~ /^(\d+)\.jpeg$/) { - $id = $1; - } else { - # Alas, we obviously need to do this :-) - # my $evq = $dbh->prepare('SELECT count(*) AS numev FROM events WHERE id=? AND vhost=?') - # or die "prepare(): $!"; - # my $ref = $dbh->selectrow_hashref($evq, undef, $event, $r->get_server_name) - # or dberror($r, "Could not look up $event"); - # $ref->{'numev'} == 1 - # or error($r, "Could not find $event", 404, "File not found"); + #if ($event eq 'single' && $filename =~ /^(\d+)\.jpeg$/) { + # $id = $1; + #} else { - # Look it up in the database - my $ref = $dbh->selectrow_hashref('SELECT id,width,height FROM images WHERE event=? AND filename=?', - undef, $event, $filename); - error($r, "Could not find $event/$filename", 404, "File not found") unless (defined($ref)); + # Look it up in the database + my $ref = $dbh->selectrow_hashref('SELECT id,width,height FROM images WHERE event=? AND vhost=? AND filename=?', + undef, $event, $r->get_server_name, $filename); + error($r, "Could not find $event/$filename", 404, "File not found") unless (defined($ref)); - $id = $ref->{'id'}; - $dbwidth = $ref->{'width'}; - $dbheight = $ref->{'height'}; - } - - $dbwidth = -1 unless defined($dbwidth); - $dbheight = -1 unless defined($dbheight); + $id = $ref->{'id'}; + $dbwidth = $ref->{'width'}; + $dbheight = $ref->{'height'}; # Scale if we need to do so - my ($fname,$thumbnail) = Sesse::pr0n::Common::ensure_cached($r, $filename, $id, $dbwidth, $dbheight, $infobox, $xres, $yres); + my ($fname, $mime_type) = Sesse::pr0n::Common::ensure_cached($r, $filename, $id, $dbwidth, $dbheight, $infobox, $xres, $yres); # Output the image to the user - my $mime_type; - if ($thumbnail) { - $mime_type = "image/jpeg"; - } else { + if (!defined($mime_type)) { $mime_type = Sesse::pr0n::Common::get_mimetype_from_filename($filename); } $r->content_type($mime_type);