From e3790f0275da7e228265cf8d2e7b502c118b5407 Mon Sep 17 00:00:00 2001 From: phisch Date: Thu, 24 Nov 2016 09:40:06 +0100 Subject: [PATCH 1/2] don't try to render preview images if 'enable_previews' has been set to false --- apps/files/js/filelist.js | 71 +++++++++++++++++++++------------------ core/js/config.php | 3 +- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 70bdcfec2422..ad6c24554f27 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1734,44 +1734,49 @@ urlSpec = {}; ready(iconURL); // set mimeicon URL - urlSpec.file = OCA.Files.Files.fixPath(path); - if (options.x) { - urlSpec.x = options.x; - } - if (options.y) { - urlSpec.y = options.y; - } - if (options.a) { - urlSpec.a = options.a; - } - if (options.mode) { - urlSpec.mode = options.mode; - } + var img = new Image(); - if (etag){ - // use etag as cache buster - urlSpec.c = etag; - } + if (oc_appconfig.core.previewsEnabled) { + urlSpec.file = OCA.Files.Files.fixPath(path); + if (options.x) { + urlSpec.x = options.x; + } + if (options.y) { + urlSpec.y = options.y; + } + if (options.a) { + urlSpec.a = options.a; + } + if (options.mode) { + urlSpec.mode = options.mode; + } - previewURL = self.generatePreviewUrl(urlSpec); - previewURL = previewURL.replace('(', '%28'); - previewURL = previewURL.replace(')', '%29'); + if (etag) { + // use etag as cache buster + urlSpec.c = etag; + } - // preload image to prevent delay - // this will make the browser cache the image - var img = new Image(); - img.onload = function(){ - // if loading the preview image failed (no preview for the mimetype) then img.width will < 5 - if (img.width > 5) { - ready(previewURL, img); - } else if (options.error) { - options.error(); + previewURL = self.generatePreviewUrl(urlSpec); + previewURL = previewURL.replace('(', '%28'); + previewURL = previewURL.replace(')', '%29'); + + // preload image to prevent delay + // this will make the browser cache the image + img.onload = function () { + // if loading the preview image failed (no preview for the mimetype) then img.width will < 5 + if (img.width > 5) { + ready(previewURL, img); + } else if (options.error) { + options.error(); + } + }; + if (options.error) { + img.onerror = options.error; } - }; - if (options.error) { - img.onerror = options.error; + img.src = previewURL; + } else { + ready(iconURL, img); } - img.src = previewURL; }, /** diff --git a/core/js/config.php b/core/js/config.php index 0afe8e98336e..6430796cbcea 100644 --- a/core/js/config.php +++ b/core/js/config.php @@ -167,7 +167,8 @@ 'resharingAllowed' => \OCP\Share::isResharingAllowed(), 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, 'federatedCloudShareDoc' => \OC::$server->getURLGenerator()->linkToDocs('user-sharing-federated'), - 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing() + 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing(), + 'previewsEnabled' => \OC::$server->getConfig()->getSystemValue('enable_previews', true) === true, ] ] ), From 0b64e00571cb66fcd0ab9b7709ff3a709271237f Mon Sep 17 00:00:00 2001 From: phisch Date: Thu, 24 Nov 2016 10:56:17 +0100 Subject: [PATCH 2/2] proper indentation --- core/js/config.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/js/config.php b/core/js/config.php index 6430796cbcea..7ebd84d1fd2d 100644 --- a/core/js/config.php +++ b/core/js/config.php @@ -157,7 +157,8 @@ ] ), "oc_appconfig" => json_encode( - ["core" => [ + [ + "core" => [ 'defaultExpireDateEnabled' => $defaultExpireDateEnabled, 'defaultExpireDate' => $defaultExpireDate, 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, @@ -168,9 +169,9 @@ 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, 'federatedCloudShareDoc' => \OC::$server->getURLGenerator()->linkToDocs('user-sharing-federated'), 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing(), - 'previewsEnabled' => \OC::$server->getConfig()->getSystemValue('enable_previews', true) === true, - ] + 'previewsEnabled' => \OC::$server->getConfig()->getSystemValue('enable_previews', true) === true, ] + ] ), "oc_defaults" => json_encode( [