Added cache to upload thumbnails proxy

This commit is contained in:
Marcin Kurczewski 2014-06-20 18:31:43 +02:00
parent 65836f4789
commit fe451af7be
4 changed files with 17 additions and 16 deletions

2
cache/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*
!.gitignore

View file

@ -3,6 +3,7 @@ dbDriver = "sqlite"
dbLocation = "./data/db.sqlite"
dbUser = "test"
dbPass = "test"
cachePath = "./cache/"
filesPath = "./data/files/"
logsPath = "./data/logs/{yyyy}-{mm}.log"
mediaPath = "./public_html/media/"

View file

@ -153,23 +153,18 @@ class PostController extends AbstractController
return;
}
$tmpPath = tempnam(sys_get_temp_dir(), 'thumb4upload');
try
{
$tmpPath = Core::getConfig()->main->cachePath . DS . md5($url) . '.upload-cache';
if (!file_exists($tmpPath))
TransferHelper::download($url, $tmpPath);
$options = new FileRendererOptions();
$options->lastModified = time();
$options->mimeType = mime_content_type($tmpPath);
$options->lastModified = time() - 3600;
$options->cacheDaysToLive = 0.5;
$options->mimeType = mime_content_type($tmpPath);
$options->fileHash = md5($url);
$options->fileContent = file_get_contents($tmpPath);
$this->renderFile($options);
}
finally
{
TransferHelper::remove($tmpPath);
}
}
public function editView($identifier)
{

View file

@ -28,7 +28,10 @@ class FileRenderer
'inline; filename="' . $options->customFileName . '"');
}
if (isset($options->mimeType))
{
\Chibi\Util\Headers::set('Content-Type', $options->mimeType);
}
if (strtotime($ifModifiedSince) == $lastModified or $eTagHeader == $eTag)
{