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

This commit is contained in:
Andrew Dolgov 2019-08-14 09:58:40 +03:00
parent 3c075bfd21
commit e7edaca4db
1 changed files with 10 additions and 5 deletions

View File

@ -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,10 +138,13 @@ class Af_Zz_ImgProxy extends Plugin {
}
}
/* 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);
}
}
}
return $url;
}