Added cache to upload thumbnails proxy
This commit is contained in:
parent
65836f4789
commit
fe451af7be
4 changed files with 17 additions and 16 deletions
2
cache/.gitignore
vendored
Normal file
2
cache/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!.gitignore
|
|
@ -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/"
|
||||
|
|
|
@ -153,22 +153,17 @@ 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->cacheDaysToLive = 0.5;
|
||||
$options->fileHash = md5($url);
|
||||
$options->fileContent = file_get_contents($tmpPath);
|
||||
$this->renderFile($options);
|
||||
}
|
||||
finally
|
||||
{
|
||||
TransferHelper::remove($tmpPath);
|
||||
}
|
||||
|
||||
$options = new FileRendererOptions();
|
||||
$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);
|
||||
}
|
||||
|
||||
public function editView($identifier)
|
||||
|
|
|
@ -28,7 +28,10 @@ class FileRenderer
|
|||
'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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue