From e7edaca4dbae01521d2aada95af229ea3104845a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 14 Aug 2019 09:58:40 +0300 Subject: [PATCH] af_zz_imgproxy: redirect to cached_url if cache already exists so that urls are a bit shorter --- plugins/af_zz_imgproxy/init.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/af_zz_imgproxy/init.php b/plugins/af_zz_imgproxy/init.php index b1281dff0..754de12e1 100755 --- a/plugins/af_zz_imgproxy/init.php +++ b/plugins/af_zz_imgproxy/init.php @@ -57,7 +57,9 @@ class Af_Zz_ImgProxy extends Plugin { $local_filename = sha1($url); if ($this->cache->exists($local_filename)) { - $this->cache->send($local_filename); + header("Location: " . $this->cache->getUrl($local_filename)); + return; + //$this->cache->send($local_filename); } else { $data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); @@ -67,8 +69,8 @@ class Af_Zz_ImgProxy extends Plugin { if (!$disable_cache && strlen($data) > MIN_CACHE_FILE_SIZE) { if ($this->cache->put($local_filename, $data)) { - $mimetype = $this->cache->getMimeType($local_filename); - header("Content-type: $mimetype"); + header("Location: " . $this->cache->getUrl($local_filename)); + return; } } @@ -136,8 +138,11 @@ class Af_Zz_ImgProxy extends Plugin { } } - return get_self_url_prefix() . "/public.php?op=pluginhandler&plugin=af_zz_imgproxy&pmethod=imgproxy&url=" . - urlencode($url); + /* we don't need to handle URLs where local cache already exists, tt-rss rewrites those automatically */ + if (!$this->cache->exists(sha1($url))) { + return get_self_url_prefix() . "/public.php?op=pluginhandler&plugin=af_zz_imgproxy&pmethod=imgproxy&url=" . + urlencode($url); + } } }