Skip to content

Commit

Permalink
Aaand finally try supported mimes only
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed Apr 4, 2017
1 parent 39db2c2 commit 45aef4d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,9 @@
var mime = options.mime;
var ready = options.callback;
var etag = options.etag;
var enabledPreviewProviders = oc_appconfig.core.enabledPreviewProviders || [];
// We join all supported mimes into a single regex
var allMimesPattern = new RegExp(enabledPreviewProviders.join('|'));

// get mime icon url
var iconURL = OC.MimeType.getIconUrl(mime);
Expand All @@ -1741,7 +1744,7 @@

var img = new Image();

if (oc_appconfig.core.previewsEnabled) {
if (oc_appconfig.core.previewsEnabled && allMimesPattern.test(mime)) {
urlSpec.file = OCA.Files.Files.fixPath(path);
if (options.x) {
urlSpec.x = options.x;
Expand Down
1 change: 1 addition & 0 deletions core/js/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
'federatedCloudShareDoc' => \OC::$server->getURLGenerator()->linkToDocs('user-sharing-federated'),
'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing(),
'previewsEnabled' => \OC::$server->getConfig()->getSystemValue('enable_previews', true) === true,
'enabledPreviewProviders' => \OC::$server->getPreviewManager()->getSupportedMimes()
]
]
),
Expand Down
16 changes: 16 additions & 0 deletions lib/private/PreviewManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ public function isMimeSupported($mimeType = '*') {
$this->mimeTypeSupportMap[$mimeType] = false;
return false;
}

/**
* Returns all registered MimeTypes as an array
*
* @return string[]
*/
public function getSupportedMimes(){
$supportedMimes = [];
$this->registerCoreProviders();
$mimeRegexArray = array_keys($this->providers);
// Now trim start/stop regexp delimiters
foreach ($mimeRegexArray as $mimeRegex){
$supportedMimes[] = trim($mimeRegex, '/');
}
return $supportedMimes;
}

/**
* Check if a preview can be generated for a file
Expand Down

0 comments on commit 45aef4d

Please sign in to comment.