make preview cache work with encryption and improve error handling
This commit is contained in:
parent
08a022aaa4
commit
a03787bc42
|
@ -16,6 +16,7 @@ require_once('preview/movies.php');
|
||||||
require_once('preview/mp3.php');
|
require_once('preview/mp3.php');
|
||||||
require_once('preview/pdf.php');
|
require_once('preview/pdf.php');
|
||||||
require_once('preview/svg.php');
|
require_once('preview/svg.php');
|
||||||
|
require_once('preview/txt.php');
|
||||||
require_once('preview/unknown.php');
|
require_once('preview/unknown.php');
|
||||||
|
|
||||||
class OC_Preview {
|
class OC_Preview {
|
||||||
|
@ -300,7 +301,7 @@ class OC_Preview {
|
||||||
$cached = self::isCached();
|
$cached = self::isCached();
|
||||||
|
|
||||||
if($cached){
|
if($cached){
|
||||||
$image = new \OC_Image($this->userview->getLocalFile($cached));
|
$image = new \OC_Image($this->userview->file_get_contents($cached, 'r'));
|
||||||
$this->preview = $image;
|
$this->preview = $image;
|
||||||
}else{
|
}else{
|
||||||
$mimetype = $this->fileview->getMimeType($file);
|
$mimetype = $this->fileview->getMimeType($file);
|
||||||
|
@ -318,12 +319,17 @@ class OC_Preview {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!($preview instanceof \OC_Image)){
|
//are there any cached thumbnails yet
|
||||||
$preview = @new \OC_Image($preview);
|
if($this->userview->is_dir(self::THUMBNAILS_FOLDER . '/') === false){
|
||||||
|
$this->userview->mkdir(self::THUMBNAILS_FOLDER . '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
//cache thumbnail
|
//cache thumbnail
|
||||||
$preview->save($this->userview->getLocalFile(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png'));
|
$cachepath = self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png';
|
||||||
|
if($this->userview->is_dir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/') === false){
|
||||||
|
$this->userview->mkdir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/');
|
||||||
|
}
|
||||||
|
$this->userview->file_put_contents($cachepath, $preview->data());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -354,13 +360,13 @@ class OC_Preview {
|
||||||
* @return image
|
* @return image
|
||||||
*/
|
*/
|
||||||
public function resizeAndCrop(){
|
public function resizeAndCrop(){
|
||||||
|
$this->preview->fixOrientation();
|
||||||
|
|
||||||
$image = $this->preview;
|
$image = $this->preview;
|
||||||
$x = $this->maxX;
|
$x = $this->maxX;
|
||||||
$y = $this->maxY;
|
$y = $this->maxY;
|
||||||
$scalingup = $this->scalingup;
|
$scalingup = $this->scalingup;
|
||||||
|
|
||||||
$image->fixOrientation();
|
|
||||||
|
|
||||||
if(!($image instanceof \OC_Image)){
|
if(!($image instanceof \OC_Image)){
|
||||||
OC_Log::write('core', 'Object passed to resizeAndCrop is not an instance of OC_Image', OC_Log::DEBUG);
|
OC_Log::write('core', 'Object passed to resizeAndCrop is not an instance of OC_Image', OC_Log::DEBUG);
|
||||||
return;
|
return;
|
||||||
|
@ -502,8 +508,14 @@ class OC_Preview {
|
||||||
if(array_key_exists('scalingup', $_GET)) $scalingup = (bool) $_GET['scalingup'];
|
if(array_key_exists('scalingup', $_GET)) $scalingup = (bool) $_GET['scalingup'];
|
||||||
|
|
||||||
if($file !== '' && $maxX !== 0 && $maxY !== 0){
|
if($file !== '' && $maxX !== 0 && $maxY !== 0){
|
||||||
$preview = new OC_Preview(OC_User::getUser(), 'files', $file, $maxX, $maxY, $scalingup);
|
try{
|
||||||
$preview->showPreview();
|
$preview = new OC_Preview(OC_User::getUser(), 'files', $file, $maxX, $maxY, $scalingup);
|
||||||
|
$preview->showPreview();
|
||||||
|
}catch(Exception $e){
|
||||||
|
OC_Response::setStatus(404);
|
||||||
|
OC_Log::write('core', $e->getmessage(), OC_Log::ERROR);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
OC_Response::setStatus(404);
|
OC_Response::setStatus(404);
|
||||||
exit;
|
exit;
|
||||||
|
@ -552,8 +564,14 @@ class OC_Preview {
|
||||||
}
|
}
|
||||||
|
|
||||||
if($userid !== null && $path !== null){
|
if($userid !== null && $path !== null){
|
||||||
$preview = new OC_Preview($userid, 'files/' . $path, $file, $maxX, $maxY, $scalingup);
|
try{
|
||||||
$preview->showPreview();
|
$preview = new OC_Preview($userid, 'files/' . $path, $file, $maxX, $maxY, $scalingup);
|
||||||
|
$preview->showPreview();
|
||||||
|
}catch(Exception $e){
|
||||||
|
OC_Response::setStatus(404);
|
||||||
|
OC_Log::write('core', $e->getmessage(), OC_Log::ERROR);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
OC_Response::setStatus(404);
|
OC_Response::setStatus(404);
|
||||||
exit;
|
exit;
|
||||||
|
|
Loading…
Reference in New Issue