Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fetch preview images if enable_previews is set to false #26705

Merged
merged 2 commits into from Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 38 additions & 33 deletions apps/files/js/filelist.js
Expand Up @@ -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;
},

/**
Expand Down
8 changes: 5 additions & 3 deletions core/js/config.php
Expand Up @@ -157,7 +157,8 @@
]
),
"oc_appconfig" => json_encode(
["core" => [
[
"core" => [
'defaultExpireDateEnabled' => $defaultExpireDateEnabled,
'defaultExpireDate' => $defaultExpireDate,
'defaultExpireDateEnforced' => $enforceDefaultExpireDate,
Expand All @@ -167,9 +168,10 @@
'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,
]
]
),
"oc_defaults" => json_encode(
[
Expand Down