Skip to content

Commit

Permalink
Fix/enable using the the image proxy with the resize daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
mherger committed May 11, 2019
1 parent f1bacce commit 280dd1f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Slim/Web/ImageProxy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ sub _gotArtwork {
# Unfortunately we have to write the data to a file, in case LMS was using an external image resizer (TinyLMS)
File::Slurp::write_file($fullpath, $http->contentRef);

_resizeFromFile($http->url, $fullpath);

unlink $fullpath;
_resizeFromFile($http->url, $fullpath);
}
else {
_resizeFromFile($http->url, $http->contentRef, $http);
Expand Down Expand Up @@ -305,9 +303,11 @@ sub _resizeFromFile {
else {
Slim::Utils::ImageResizer->resize($fullpath, $cachekey, $spec, sub {
my ($body, $format) = @_;

# Resized image should now be in cache
my $response = $args->[1];

unlink $fullpath if !ref $fullpath && $fullpath =~ /imgproxy_[a-f0-9]+$/i;

if ( !($body && $format && ref $body eq 'SCALAR') && (my $c = $cache->get($cachekey)) ) {
$body = $c->{data_ref};
Expand Down
23 changes: 21 additions & 2 deletions gdresized.pl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ BEGIN
exit 0;
};

my $cache = Slim::Utils::ArtworkCache->new('.');
my $artworkCache = Slim::Utils::ArtworkCache->new('.');
my $imageProxyCache = Slim::Web::ImageProxy::Cache->new('.');

DEBUG && warn "$0 listening on " . SOCKET_PATH . "\n";

Expand All @@ -138,14 +139,16 @@ BEGIN
# An empty spec is allowed, this returns the original image
$spec ||= 'XxX';

DEBUG && warn "file=$file, spec=$spec, cacheroot=$cacheroot, cachekey=$cachekey\n";
my $imageproxy = $cachekey =~ /^imageproxy/;
DEBUG && warn sprintf("file=%s, spec=%s, cacheroot=%s, cachekey=%s imageproxy=%s\n", $file, $spec, $cacheroot, $cachekey, $imageproxy || 0);

if ( !$file || !$spec || !$cacheroot || !$cachekey ) {
die "Invalid parameters: $file, $spec, $cacheroot, $cachekey\n";
}

my @spec = split ',', $spec;

my $cache = $imageproxy ? $imageProxyCache : $artworkCache;
if ( $cache->getRoot() ne $cacheroot ) {
$cache->setRoot($cacheroot);
$cache->pragma('locking_mode = NORMAL');
Expand Down Expand Up @@ -173,6 +176,22 @@ BEGIN
}
}

1;

package Slim::Web::ImageProxy::Cache;

use base 'Slim::Utils::DbArtworkCache';

use strict;

sub new {
my $class = shift;
my $root = shift;

warn 'imageproxy';
return $class->SUPER::new($root, 'imgproxy', 86400*30);
}

__END__
=head1 NAME
Expand Down

0 comments on commit 280dd1f

Please sign in to comment.