Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: add option to check preview availability for a specific format
Signed-off-by: Anderson Entwistle <46688047+aentwist@users.noreply.github.com>
  • Loading branch information
aentwist committed Apr 4, 2023
commit 5a87d4a97a1526e563d3eea1e253b422a2eb9a1e
8 changes: 5 additions & 3 deletions lib/private/PreviewManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,15 @@ public function isMimeSupported($mimeType = '*') {
/**
* Check if a preview can be generated for a file
*/
public function isAvailable(\OCP\Files\FileInfo $file): bool {
public function isAvailable(\OCP\Files\FileInfo $file, ?string $previewMimeType = null): bool {
if (!$previewMimeType) $previewMimeType = $file->getMimeType();

if (!$this->config->getSystemValue('enable_previews', true)) {
return false;
}

$this->registerCoreProviders();
if (!$this->isMimeSupported($file->getMimetype())) {
if (!$this->isMimeSupported($previewMimeType)) {
return false;
}

Expand All @@ -259,7 +261,7 @@ public function isAvailable(\OCP\Files\FileInfo $file): bool {
}

foreach ($this->providers as $supportedMimeType => $providers) {
if (preg_match($supportedMimeType, $file->getMimetype())) {
if (preg_match($supportedMimeType, $previewMimeType)) {
foreach ($providers as $providerClosure) {
$provider = $this->helper->getProvider($providerClosure);
if (!($provider instanceof IProviderV2)) {
Expand Down
3 changes: 2 additions & 1 deletion lib/public/IPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ public function isMimeSupported($mimeType = '*');
* Check if a preview can be generated for a file
*
* @param \OCP\Files\FileInfo $file
* @param ?string $previewMimeType MIME type of the preview to be generated

Check failure

Code scanning / Psalm

MismatchingDocblockParamType

Parameter $previewMimeType has wrong type 'null|string', should be 'string'
* @return bool
* @since 8.0.0
*/
public function isAvailable(\OCP\Files\FileInfo $file);
public function isAvailable(\OCP\Files\FileInfo $file, string $previewMimeType);

/**
* Generates previews of a file
Expand Down