af_zz_imgproxy: redirect to cached_url if cache already exists so that urls are a bit shorter

master
Andrew Dolgov 5 years ago
parent 3c075bfd21
commit e7edaca4db

@ -57,7 +57,9 @@ class Af_Zz_ImgProxy extends Plugin {
$local_filename = sha1($url); $local_filename = sha1($url);
if ($this->cache->exists($local_filename)) { 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 { } else {
$data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); $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 (!$disable_cache && strlen($data) > MIN_CACHE_FILE_SIZE) {
if ($this->cache->put($local_filename, $data)) { if ($this->cache->put($local_filename, $data)) {
$mimetype = $this->cache->getMimeType($local_filename); header("Location: " . $this->cache->getUrl($local_filename));
header("Content-type: $mimetype"); 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=" . /* we don't need to handle URLs where local cache already exists, tt-rss rewrites those automatically */
urlencode($url); if (!$this->cache->exists(sha1($url))) {
return get_self_url_prefix() . "/public.php?op=pluginhandler&plugin=af_zz_imgproxy&pmethod=imgproxy&url=" .
urlencode($url);
}
} }
} }

Loading…
Cancel
Save