diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2016-08-04 19:41:04 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-11-03 14:00:32 +0100 |
commit | 958c1289b15f5bd877dd7ff3b7cf3540a0c5198a (patch) | |
tree | 94dea79e9d3fb96aa8528743960de15271d4c8b4 /core | |
parent | b129adfb58eb98a37278dbd5a2f30b52c90cb4fc (diff) | |
download | nextcloud-server-958c1289b15f5bd877dd7ff3b7cf3540a0c5198a.tar.gz nextcloud-server-958c1289b15f5bd877dd7ff3b7cf3540a0c5198a.zip |
New preview generator
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'core')
-rw-r--r-- | core/ajax/preview.php | 28 | ||||
-rw-r--r-- | core/ajax/preview2.php | 36 | ||||
-rw-r--r-- | core/routes.php | 2 |
3 files changed, 56 insertions, 10 deletions
diff --git a/core/ajax/preview.php b/core/ajax/preview.php index 6cfba6aef30..aac623b5ce6 100644 --- a/core/ajax/preview.php +++ b/core/ajax/preview.php @@ -49,19 +49,27 @@ if ($maxX === 0 || $maxY === 0) { exit; } -$info = \OC\Files\Filesystem::getFileInfo($file); +$folder = \OC::$server->getUserFolder(); -if (!$info instanceof OCP\Files\FileInfo || !$always && !\OC::$server->getPreviewManager()->isAvailable($info)) { +try { + $file = $folder->get($file); +} catch (\OCP\Files\NotFoundException $e) { + return \OC_Response::setStatus(404); +} + +if (!$file instanceof OCP\Files\File || !$always && !\OC::$server->getPreviewManager()->isAvailable($file)) { \OC_Response::setStatus(404); } else if (!$info->isReadable()) { \OC_Response::setStatus(403); } else { - $preview = new \OC\Preview(\OC_User::getUser(), 'files'); - $preview->setFile($file, $info); - $preview->setMaxX($maxX); - $preview->setMaxY($maxY); - $preview->setScalingUp($scalingUp); - $preview->setMode($mode); - $preview->setKeepAspect($keepAspect); - $preview->showPreview(); + $preview = new \OC\Preview2( + \OC::$server->getRootFolder(), + \OC::$server->getConfig(), + \OC::$server->getPreviewManager(), + $file + ); + $image = $preview->getPreview($maxX, $maxY, !$keepAspect, $mode); + + header('Content-Type: ' . $image->getMimeType()); + echo $image->getContent(); } diff --git a/core/ajax/preview2.php b/core/ajax/preview2.php new file mode 100644 index 00000000000..b2bbf64c6d2 --- /dev/null +++ b/core/ajax/preview2.php @@ -0,0 +1,36 @@ +<?php + +\OC_Util::checkLoggedIn(); +\OC::$server->getSession()->close(); + +$file = array_key_exists('file', $_GET) ? (string)$_GET['file'] : ''; +$maxX = array_key_exists('x', $_GET) ? (int)$_GET['x'] : '32'; +$maxY = array_key_exists('y', $_GET) ? (int)$_GET['y'] : '32'; +$keepAspect = array_key_exists('a', $_GET) ? true : false; +$always = array_key_exists('forceIcon', $_GET) ? (bool)$_GET['forceIcon'] : true; +$mode = array_key_exists('mode', $_GET) ? $_GET['mode'] : 'fill'; + +if ($file === '') { + //400 Bad Request + \OC_Response::setStatus(400); + \OCP\Util::writeLog('core-preview', 'No file parameter was passed', \OCP\Util::DEBUG); + exit; +} + +if ($maxX === 0 || $maxY === 0) { + //400 Bad Request + \OC_Response::setStatus(400); + \OCP\Util::writeLog('core-preview', 'x and/or y set to 0', \OCP\Util::DEBUG); + exit; +} + +$userFolder = \OC::$server->getUserFolder(); +$file = $userFolder->get($file); + +$p = new \OC\Preview2(\OC::$server->getRootFolder(), + \OC::$server->getConfig(), + \OC::$server->getPreviewManager(), + $file); + +$p->getPreview($maxX, $maxY, !$keepAspect, $mode); + diff --git a/core/routes.php b/core/routes.php index 7978001af7d..4b73a86042a 100644 --- a/core/routes.php +++ b/core/routes.php @@ -70,6 +70,8 @@ $this->create('search_ajax_search', '/core/search') // Routing $this->create('core_ajax_preview', '/core/preview') ->actionInclude('core/ajax/preview.php'); +$this->create('core_ajax_preview2', '/core/preview2') + ->actionInclude('core/ajax/preview2.php'); $this->create('core_ajax_preview', '/core/preview.png') ->actionInclude('core/ajax/preview.php'); $this->create('core_ajax_update', '/core/ajax/update.php') |