Skip to content

Commit

Permalink
Files app uses dav preview endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 authored and patrickjahns committed Jun 11, 2018
1 parent d69e53d commit 541178b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 88 deletions.
6 changes: 5 additions & 1 deletion apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

/**
Expand Down
64 changes: 0 additions & 64 deletions core/ajax/preview.php

This file was deleted.

2 changes: 1 addition & 1 deletion lib/private/Files/Node/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
42 changes: 21 additions & 21 deletions lib/private/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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/');
}

/**
Expand Down Expand Up @@ -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/');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/private/legacy/template/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 541178b

Please sign in to comment.