From 280dd1f2d96ade8667bbd1eaa19e549829c01b7f Mon Sep 17 00:00:00 2001 From: Michael Herger Date: Sat, 11 May 2019 07:04:39 +0200 Subject: [PATCH] Fix/enable using the the image proxy with the resize daemon --- Slim/Web/ImageProxy.pm | 8 ++++---- gdresized.pl | 23 +++++++++++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Slim/Web/ImageProxy.pm b/Slim/Web/ImageProxy.pm index e7b42e7ee1f..00761c2794f 100644 --- a/Slim/Web/ImageProxy.pm +++ b/Slim/Web/ImageProxy.pm @@ -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); @@ -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}; diff --git a/gdresized.pl b/gdresized.pl index 6b0418ceee7..b9ce6bf0473 100755 --- a/gdresized.pl +++ b/gdresized.pl @@ -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"; @@ -138,7 +139,8 @@ 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"; @@ -146,6 +148,7 @@ BEGIN my @spec = split ',', $spec; + my $cache = $imageproxy ? $imageProxyCache : $artworkCache; if ( $cache->getRoot() ne $cacheroot ) { $cache->setRoot($cacheroot); $cache->pragma('locking_mode = NORMAL'); @@ -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