X-Git-Url: https://git.sesse.net/?p=pr0n;a=blobdiff_plain;f=perl%2FSesse%2Fpr0n%2FImage.pm;h=f12a15891792ed1ba0e195e815c4c157df2d1b29;hp=4f6360a6605f001b1e3a5ace4fc8494490c0f785;hb=6c8c4bf3f1e3109523f9ec6117abfdf0e04a0d99;hpb=09260885c52013320acd21d7ce262e12def7301f diff --git a/perl/Sesse/pr0n/Image.pm b/perl/Sesse/pr0n/Image.pm index 4f6360a..f12a158 100644 --- a/perl/Sesse/pr0n/Image.pm +++ b/perl/Sesse/pr0n/Image.pm @@ -13,29 +13,26 @@ sub handler { # die "Har du lest FAQen?"; # } - # Find the event and file name + # Find the event and file name (nobox/ is for compatibility with legacy URLs). my ($event,$filename,$xres,$yres,$dpr); - my $infobox = 'both'; + my $infobox = 0; if ($r->path_info =~ m#^/([a-zA-Z0-9-]+)/original/((?:no)?box/)?([a-zA-Z0-9._()-]+)$#) { $event = $1; $filename = $3; - $infobox = 'nobox' if (defined($2) && $2 eq 'nobox/'); - $infobox = 'box' if (defined($2) && $2 eq 'box/'); + $infobox = 1 if (defined($2) && $2 eq 'box/'); } elsif ($r->path_info =~ m#^/([a-zA-Z0-9-]+)/(\d+)x(\d+)(?:\@(\d+(?:\.\d+)?))?/((?:no)?box/)?([a-zA-Z0-9._()-]+)$#) { $event = $1; $filename = $6; $xres = $2; $yres = $3; $dpr = $4; - $infobox = 'nobox' if (defined($5) && $5 eq 'nobox/'); - $infobox = 'box' if (defined($5) && $5 eq 'box/'); + $infobox = 1 if (defined($5) && $5 eq 'box/'); } elsif ($r->path_info =~ m#^/([a-zA-Z0-9-]+)/((?:no)?box/)?([a-zA-Z0-9._()-]+)$#) { $event = $1; $filename = $3; $xres = -1; $yres = -1; - $infobox = 'nobox' if (defined($2) && $2 eq 'nobox/'); - $infobox = 'box' if (defined($2) && $2 eq 'box/'); + $infobox = 1 if (defined($2) && $2 eq 'box/'); } $dpr //= 1; @@ -45,16 +42,29 @@ sub handler { #} else { # Look it up in the database - my $ref = $dbh->selectrow_hashref('SELECT id,width,height FROM images WHERE event=? AND vhost=? AND filename=?', + my $ref = $dbh->selectrow_hashref('SELECT id,render_id,width,height FROM images WHERE event=? AND vhost=? AND filename=?', undef, $event, Sesse::pr0n::Common::get_server_name($r), $filename); return error($r, "Could not find $event/$filename", 404, "File not found") unless (defined($ref)); + if (defined($xres) && defined($yres) && defined($ref->{'render_id'}) && !$infobox) { + # We have a render, we're not asked for the original, and we do not have infobox. + $ref = $dbh->selectrow_hashref('SELECT id,filename,width,height FROM images WHERE id=?', + undef, $ref->{'render_id'}); + return error($r, "Could not find render of $event/$filename", 404, "File not found") unless (defined($ref)); + $filename = $ref->{'filename'}; + } + $id = $ref->{'id'}; $dbwidth = $ref->{'width'}; $dbheight = $ref->{'height'}; # Scale if we need to do so - my ($fname, $mime_type) = Sesse::pr0n::Common::ensure_cached($r, $filename, $id, $dbwidth, $dbheight, $infobox, $dpr, $xres, $yres); + my ($fname, $mime_type); + if ($infobox) { + ($fname, $mime_type) = Sesse::pr0n::Common::ensure_infobox_cached($r, $filename, $id, $dbwidth, $dbheight, $dpr, $xres, $yres); + } else { + ($fname, $mime_type) = Sesse::pr0n::Common::ensure_cached($r, $filename, $id, $dbwidth, $dbheight, $xres, $yres); + } # Output the image to the user my $res = Plack::Response->new(200);