Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/private/PreviewManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function getPreview(
$mimeType = null,
bool $cacheResult = true,
): ISimpleFile {
$this->throwIfPreviewsDisabled($file);
$this->throwIfPreviewsDisabled($file, $mimeType);
$previewConcurrency = $this->getGenerator()->getNumConcurrentPreviews('preview_concurrency_all');
$sem = Generator::guardWithSemaphore(Generator::SEMAPHORE_ID_ALL, $previewConcurrency);
try {
Expand All @@ -178,7 +178,7 @@ public function getPreview(
* @since 19.0.0
*/
public function generatePreviews(File $file, array $specifications, $mimeType = null) {
$this->throwIfPreviewsDisabled($file);
$this->throwIfPreviewsDisabled($file, $mimeType);
return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType);
}

Expand Down Expand Up @@ -213,13 +213,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 $mimeType = null): bool {
if (!$this->enablePreviews) {
return false;
}

$fileMimeType = $mimeType ?? $file->getMimeType();

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

Expand All @@ -229,7 +231,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, $fileMimeType)) {
foreach ($providers as $providerClosure) {
$provider = $this->helper->getProvider($providerClosure);
if (!($provider instanceof IProviderV2)) {
Expand Down Expand Up @@ -455,8 +457,8 @@ private function registerBootstrapProviders(): void {
/**
* @throws NotFoundException if preview generation is disabled
*/
private function throwIfPreviewsDisabled(File $file): void {
if (!$this->isAvailable($file)) {
private function throwIfPreviewsDisabled(File $file, ?string $mimeType = null): void {
if (!$this->isAvailable($file, $mimeType)) {
throw new NotFoundException('Previews disabled');
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/public/IPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ public function isMimeSupported($mimeType = '*');
* Check if a preview can be generated for a file
*
* @param \OCP\Files\FileInfo $file
* @param string|null $mimeType To force a given mimetype for the file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might need a @since for this even when it is optional

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@susnux Hey, what would you recommend in terms of annotation for the addition of an optional param?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The since for 32 looks ok :)

* @return bool
* @since 8.0.0
* @since 32.0.0 - isAvailable($mimeType) added the $mimeType argument to the signature
*/
public function isAvailable(\OCP\Files\FileInfo $file);
public function isAvailable(\OCP\Files\FileInfo $file, ?string $mimeType = null);

/**
* Generates previews of a file
Expand Down
Loading