diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index aaa10a71537d..f86aa15dccfb 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1742,7 +1742,11 @@ urlSpec.x = Math.ceil(urlSpec.x); urlSpec.y = Math.ceil(urlSpec.y); urlSpec.forceIcon = 0; - return OC.generateUrl('/core/preview.png?') + $.param(urlSpec); + var file = urlSpec.file; + delete urlSpec.file; + urlSpec.preview = 1; + + return OC.linkToRemoteBase('dav') + '/files/' + OC.getCurrentUser().uid + '/' + file + '?' + $.param(urlSpec); }, /** diff --git a/core/ajax/preview.php b/core/ajax/preview.php deleted file mode 100644 index 07943f3c160d..000000000000 --- a/core/ajax/preview.php +++ /dev/null @@ -1,64 +0,0 @@ - - * @author Joas Schilling - * @author Lukas Reschke - * @author Morris Jobke - * @author Robin Appelman - * @author Thomas Müller - * - * @copyright Copyright (c) 2018, ownCloud GmbH - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ -\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'; -$scalingUp = array_key_exists('scalingup', $_GET) ? (bool)$_GET['scalingup'] : true; -$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; -} - -$info = \OC\Files\Filesystem::getFileInfo($file); - -if (!$info instanceof OCP\Files\FileInfo || !$always && !\OC::$server->getPreviewManager()->isAvailable($info)) { - \OC_Response::setStatus(404); -} 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(); -} diff --git a/lib/private/Files/Node/File.php b/lib/private/Files/Node/File.php index 9af1d2364667..7b6d0192771e 100644 --- a/lib/private/Files/Node/File.php +++ b/lib/private/Files/Node/File.php @@ -154,7 +154,7 @@ public function getThumbnail($options) { $mode = array_key_exists('mode', $options) ? $options['mode'] : 'fill'; $preview = new \OC\Preview(); - $preview->setFile($this->getInternalPath(), $this->getFileInfo()); + $preview->setFile($this); $preview->setMaxX($maxX); $preview->setMaxY($maxY); $preview->setScalingUp($scalingUp); diff --git a/lib/private/Preview.php b/lib/private/Preview.php index 8187412943cc..6a30620f9fae 100644 --- a/lib/private/Preview.php +++ b/lib/private/Preview.php @@ -32,10 +32,11 @@ namespace OC; use OC\Files\View; -use OC\Preview\Provider; use OCP\Files\File; use OCP\Files\FileInfo; use OCP\Files\NotFoundException; +use OCP\Preview\IProvider2; +use OCP\Util; class Preview { //the thumbnail folder @@ -143,7 +144,7 @@ public function __construct( && \OC::$server->getConfig() ->getSystemValue('enable_previews', true) ) { - \OCP\Util::writeLog('core', 'No preview providers exist', \OCP\Util::ERROR); + Util::writeLog('core', 'No preview providers exist', Util::ERROR); throw new \Exception('No preview providers'); } } @@ -360,13 +361,13 @@ public function setKeepAspect($keepAspect) { public function isFileValid() { $file = $this->getFile(); if ($file === null) { - \OCP\Util::writeLog('core', 'No filename passed', \OCP\Util::DEBUG); + Util::writeLog('core', 'No filename passed', Util::DEBUG); return false; } if (!$this->getFileInfo() instanceof FileInfo) { - \OCP\Util::writeLog('core', 'File:"' . $file->getPath() . '" not found', \OCP\Util::DEBUG); + Util::writeLog('core', 'File:"' . $file->getPath() . '" not found', Util::DEBUG); return false; } @@ -832,8 +833,8 @@ private function getCachedPreview($cached) { private function resizeAndStore() { $image = $this->preview; if (!($image instanceof \OCP\IImage)) { - \OCP\Util::writeLog( - 'core', '$this->preview is not an instance of \OCP\IImage', \OCP\Util::DEBUG + Util::writeLog( + 'core', '$this->preview is not an instance of \OCP\IImage', Util::DEBUG ); return; @@ -933,9 +934,9 @@ private function scale($image, $askedWidth, $askedHeight, $previewWidth, $previe // We cap when upscaling if (!is_null($maxScaleFactor)) { if ($factor > $maxScaleFactor) { - \OCP\Util::writeLog( + Util::writeLog( 'core', 'scale factor reduced from ' . $factor . ' to ' . $maxScaleFactor, - \OCP\Util::DEBUG + Util::DEBUG ); $factor = $maxScaleFactor; } @@ -1024,9 +1025,9 @@ private function cropAndFill($image, $askedWidth, $askedHeight, $previewWidth, $ */ private function storePreview($previewWidth, $previewHeight) { if (empty($previewWidth) || empty($previewHeight)) { - \OCP\Util::writeLog( + Util::writeLog( 'core', 'Cannot save preview of dimension ' . $previewWidth . 'x' . $previewHeight, - \OCP\Util::DEBUG + Util::DEBUG ); } else { @@ -1107,17 +1108,16 @@ private function generatePreview() { foreach ($providers as $closure) { $provider = $closure(); - if (!($provider instanceof \OCP\Preview\IProvider2)) { + if (!($provider instanceof IProvider2)) { continue; } - \OCP\Util::writeLog( + Util::writeLog( 'core', 'Generating preview for "' . $file->getPath() . '" with "' . get_class($provider) - . '"', \OCP\Util::DEBUG + . '"', Util::DEBUG ); - /** @var $provider Provider */ - $preview = $provider->getThumbnail($file, $this->configMaxWidth, $this->configMaxHeight, $scalingUp = false); + $preview = $provider->getThumbnail($file, $this->configMaxWidth, $this->configMaxHeight, false); if (!($preview instanceof \OCP\IImage)) { continue; @@ -1206,8 +1206,8 @@ private function storeMaxPreview($previewPath) { private function limitMaxDim($dim, $maxDim, $dimName) { if (!is_null($maxDim)) { if ($dim > $maxDim) { - \OCP\Util::writeLog( - 'core', $dimName . ' reduced from ' . $dim . ' to ' . $maxDim, \OCP\Util::DEBUG + Util::writeLog( + 'core', $dimName . ' reduced from ' . $dim . ' to ' . $maxDim, Util::DEBUG ); $dim = $maxDim; } @@ -1220,14 +1220,14 @@ private function limitMaxDim($dim, $maxDim, $dimName) { * @param array $args */ public static function post_write($args) { - self::post_delete($args, 'files/'); +// self::post_delete($args, 'files/'); } /** * @param array $args */ public static function prepare_delete_files($args) { - self::prepare_delete($args, 'files/'); +// self::prepare_delete($args, 'files/'); } /** @@ -1296,14 +1296,14 @@ private static function getAllChildren($view, $path) { * @param array $args */ public static function post_delete_files($args) { - self::post_delete($args, 'files/'); +// self::post_delete($args, 'files/'); } /** * @param array $args */ public static function post_delete_versions($args) { - self::post_delete($args, 'files/'); +// self::post_delete($args, 'files/'); } /** diff --git a/lib/private/legacy/template/functions.php b/lib/private/legacy/template/functions.php index 75d892573749..8de17e6f7a00 100644 --- a/lib/private/legacy/template/functions.php +++ b/lib/private/legacy/template/functions.php @@ -182,7 +182,7 @@ function mimetype_icon( $mimetype ) { * make preview_icon available as a simple function * Returns the path to the preview of the image. * @param string $path path of file - * @return link to the preview + * @return string link to the preview */ function preview_icon( $path ) { return \OC::$server->getURLGenerator()->linkToRoute('core_ajax_preview', ['x' => 32, 'y' => 32, 'file' => $path]);