From 29f1fc41da78a3cb8177e28d0579453c8d6ecc4e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 28 Nov 2015 16:51:11 +0100 Subject: [PATCH] Many more fixes from the infobox cleanup fallout. --- perl/Sesse/pr0n/Common.pm | 36 +++++++++++++++++++----------------- perl/Sesse/pr0n/Image.pm | 2 +- perl/Sesse/pr0n/WebDAV.pm | 2 +- perl/update-image-cache.pl | 2 +- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/perl/Sesse/pr0n/Common.pm b/perl/Sesse/pr0n/Common.pm index d175979..8a881e3 100644 --- a/perl/Sesse/pr0n/Common.pm +++ b/perl/Sesse/pr0n/Common.pm @@ -212,17 +212,20 @@ sub get_disk_location { } sub get_cache_location { - my ($r, $id, $width, $height, $infobox, $dpr) = @_; + my ($r, $id, $width, $height) = @_; my $dir = POSIX::floor($id / 256); - if ($infobox) { - if ($dpr == 1) { - return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-box.png"; - } else { - return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-box\@$dpr.png"; - } + return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-nobox.jpg"; +} + +sub get_infobox_cache_location { + my ($r, $id, $width, $height, $dpr) = @_; + my $dir = POSIX::floor($id / 256); + + if ($dpr == 1) { + return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-box.png"; } else { - return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-nobox.jpg"; + return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-box\@$dpr.png"; } } @@ -569,7 +572,7 @@ sub read_original_image { } sub ensure_cached { - my ($r, $filename, $id, $dbwidth, $dbheight, $dpr, $xres, $yres, @otherres) = @_; + my ($r, $filename, $id, $dbwidth, $dbheight, $xres, $yres, @otherres) = @_; my ($new_dbwidth, $new_dbheight); @@ -578,7 +581,7 @@ sub ensure_cached { return ($fname, undef); } - my $cachename = get_cache_location($r, $id, $xres, $yres, $infobox, $dpr); + my $cachename = get_cache_location($r, $id, $xres, $yres); my $err; if (! -r $cachename or (-M $cachename > -M $fname)) { # If we are in overload mode (aka Slashdot mode), refuse to generate @@ -593,7 +596,7 @@ sub ensure_cached { while (defined($xres) && defined($yres)) { my ($nxres, $nyres) = (shift @otherres, shift @otherres); - my $cachename = get_cache_location($r, $id, $xres, $yres, $infobox, $dpr); + my $cachename = get_cache_location($r, $id, $xres, $yres); my $cimg; if (defined($nxres) && defined($nyres)) { @@ -662,12 +665,12 @@ sub ensure_cached { } sub ensure_infobox_cached { - my ($r, $filename, $id, $dbwidth, $dbheight, $infobox, $dpr, $xres, $yres) = @_; + my ($r, $filename, $id, $dbwidth, $dbheight, $dpr, $xres, $yres) = @_; my ($new_dbwidth, $new_dbheight); my $fname = get_disk_location($r, $id); - my $cachename = get_cache_location($r, $id, $xres, $yres, 1, $dpr); + my $cachename = get_infobox_cache_location($r, $id, $xres, $yres, $dpr); my $err; if (! -r $cachename or (-M $cachename > -M $fname)) { # If we are in overload mode (aka Slashdot mode), refuse to generate @@ -719,11 +722,10 @@ sub ensure_infobox_cached { $err = $img->write(filename => $cachename, quality => 90, depth => 8); log_info($r, "New infobox cache: $width x $height for $id.jpg"); - - return ($cachename, 'image/png'); } -} + return ($cachename, 'image/png'); +} sub get_mimetype_from_filename { my $filename = shift; @@ -745,7 +747,7 @@ sub make_infobox { $info->{'ExposureProgram'} =~ /shutter\b.*\bpriority/i); my $manual_aperture = (defined($info->{'ExposureProgram'}) && $info->{'ExposureProgram'} =~ /aperture\b.*\bpriority/i); - if ($info->{'ExposureProgram'} =~ /manual/i) { + if (defined($info->{'ExposureProgram'}) && $info->{'ExposureProgram'} =~ /manual/i) { $manual_shutter = 1; $manual_aperture = 1; } diff --git a/perl/Sesse/pr0n/Image.pm b/perl/Sesse/pr0n/Image.pm index 4e272fa..4a71603 100644 --- a/perl/Sesse/pr0n/Image.pm +++ b/perl/Sesse/pr0n/Image.pm @@ -55,7 +55,7 @@ sub handler { 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, $dpr, $xres, $yres); + ($fname, $mime_type) = Sesse::pr0n::Common::ensure_cached($r, $filename, $id, $dbwidth, $dbheight, $xres, $yres); } # Output the image to the user diff --git a/perl/Sesse/pr0n/WebDAV.pm b/perl/Sesse/pr0n/WebDAV.pm index 4fb5c17..ade8963 100644 --- a/perl/Sesse/pr0n/WebDAV.pm +++ b/perl/Sesse/pr0n/WebDAV.pm @@ -493,7 +493,7 @@ EOF if ($filename !~ /^\.(_|DS_Store)/) { # FIXME: Ideally we'd want to ensure cache of -1x-1 here as well (for NEFs), but that would # preclude mipmapping in its current form. - Sesse::pr0n::Common::ensure_cached($r, $filename, $newid, undef, undef, 1, 320, 256); + Sesse::pr0n::Common::ensure_cached($r, $filename, $newid, undef, undef, 320, 256); } # OK, we got this far, commit diff --git a/perl/update-image-cache.pl b/perl/update-image-cache.pl index 213a7a0..3857ae2 100755 --- a/perl/update-image-cache.pl +++ b/perl/update-image-cache.pl @@ -118,7 +118,7 @@ while (my $ref = $q->fetchrow_hashref) { next unless $any_old; unlink (@files); if (scalar @noboxres > 0) { - Sesse::pr0n::Common::ensure_cached($r, $ref->{'filename'}, $id, $ref->{'width'}, $ref->{'height'}, 1, sort_res(@noboxres)); + Sesse::pr0n::Common::ensure_cached($r, $ref->{'filename'}, $id, $ref->{'width'}, $ref->{'height'}, sort_res(@noboxres)); } if (scalar @boxres > 0) { Sesse::pr0n::Common::ensure_infobox_cached($r, $ref->{'filename'}, $id, $ref->{'width'}, $ref->{'height'}, 1, sort_res(@boxres)); -- 2.39.5