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" dbLocation = "./data/db.sqlite"
dbUser = "test" dbUser = "test"
dbPass = "test" dbPass = "test"
cachePath = "./cache/"
filesPath = "./data/files/" filesPath = "./data/files/"
logsPath = "./data/logs/{yyyy}-{mm}.log" logsPath = "./data/logs/{yyyy}-{mm}.log"
mediaPath = "./public_html/media/" mediaPath = "./public_html/media/"

View file

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

View file

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