mirror of
https://github.com/mosbth/cimage.git
synced 2025-01-17 19:18:15 +01:00
improved cache handling for remote, #130
This commit is contained in:
parent
3271d165ff
commit
79a7fd17d8
17
CImage.php
17
CImage.php
@ -512,13 +512,15 @@ class CImage
|
||||
* Allow or disallow remote image download.
|
||||
*
|
||||
* @param boolean $allow true or false to enable and disable.
|
||||
* @param string $cache path to cache dir.
|
||||
* @param string $pattern to use to detect if its a remote file.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRemoteDownload($allow, $pattern = null)
|
||||
public function setRemoteDownload($allow, $cache, $pattern = null)
|
||||
{
|
||||
$this->allowRemote = $allow;
|
||||
$this->remoteCache = $cache;
|
||||
$this->remotePattern = is_null($pattern) ? $this->remotePattern : $pattern;
|
||||
|
||||
$this->log(
|
||||
@ -650,21 +652,12 @@ class CImage
|
||||
}
|
||||
|
||||
$remote = new CRemoteImage();
|
||||
$cache = $this->saveFolder . "/remote/";
|
||||
|
||||
if (!is_dir($cache)) {
|
||||
if (!is_writable($this->saveFolder)) {
|
||||
throw new Exception("Can not create remote cache, cachefolder not writable.");
|
||||
}
|
||||
mkdir($cache);
|
||||
$this->log("The remote cache does not exists, creating it.");
|
||||
}
|
||||
|
||||
if (!is_writable($cache)) {
|
||||
if (!is_writable($this->remoteCache)) {
|
||||
$this->log("The remote cache is not writable.");
|
||||
}
|
||||
|
||||
$remote->setCache($cache);
|
||||
$remote->setCache($this->remoteCache);
|
||||
$remote->useCache($this->useCache);
|
||||
$src = $remote->download($src);
|
||||
|
||||
|
@ -5,10 +5,11 @@ Revision history
|
||||
[![Build Status](https://scrutinizer-ci.com/g/mosbth/cimage/badges/build.png?b=master)](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
|
||||
|
||||
|
||||
v0.7.8* (2015-12-06)
|
||||
v0.7.8* (2015-12-07)
|
||||
-------------------------------------
|
||||
|
||||
* Adding CCache to improve cache handling of dummy and srgb, #130.
|
||||
* Added correct CImage version to remote agent string, #131.
|
||||
* Adding CCache to improve cache handling of caching for dummy, remote and srgb. #130.
|
||||
|
||||
|
||||
v0.7.8 (2015-12-06)
|
||||
|
@ -348,6 +348,16 @@ $img->setVerbose($verbose || $verboseFile);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the cachepath from config.
|
||||
*/
|
||||
$cachePath = getConfig('cache_path', __DIR__ . '/../cache/');
|
||||
$cache = new CCache();
|
||||
$cache->setDir($cachePath);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Allow or disallow remote download of images from other servers.
|
||||
* Passwords apply if used.
|
||||
@ -356,8 +366,10 @@ $img->setVerbose($verbose || $verboseFile);
|
||||
$allowRemote = getConfig('remote_allow', false);
|
||||
|
||||
if ($allowRemote && $passwordMatch !== false) {
|
||||
$cacheRemote = $cache->getPathToSubdir("remote");
|
||||
|
||||
$pattern = getConfig('remote_pattern', null);
|
||||
$img->setRemoteDownload($allowRemote, $pattern);
|
||||
$img->setRemoteDownload($allowRemote, $pattern, $cacheRemote);
|
||||
|
||||
$whitelist = getConfig('remote_whitelist', null);
|
||||
$img->setRemoteHostWhitelist($whitelist);
|
||||
@ -942,15 +954,6 @@ verbose("alias = $alias");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the cachepath from config.
|
||||
*/
|
||||
$cachePath = getConfig('cache_path', __DIR__ . '/../cache/');
|
||||
$cache = new CCache();
|
||||
$cache->setDir($cachePath);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add cache control HTTP header.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user