diff options
author | Julien Veyssier <julien-nc@posteo.net> | 2025-05-30 13:19:34 +0200 |
---|---|---|
committer | Julien Veyssier <julien-nc@posteo.net> | 2025-06-02 23:26:00 +0200 |
commit | be027ae01ceb4e80722e5b85aed8d9c0a91e688f (patch) | |
tree | a867d5681c003130411d0086f53d432dd5f88aaa | |
parent | 577032c1f76b18904940c6c07ad3bc13f3310a07 (diff) | |
download | nextcloud-server-backport/53205/stable30.tar.gz nextcloud-server-backport/53205/stable30.zip |
fix(PreviewManager): use the forced mimetype in throwIfPreviewsDisabledbackport/53205/stable30
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
-rw-r--r-- | lib/private/PreviewManager.php | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php index caf68b178e3..ed96e2f9501 100644 --- a/lib/private/PreviewManager.php +++ b/lib/private/PreviewManager.php @@ -151,7 +151,7 @@ class PreviewManager implements IPreview { $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 { @@ -175,7 +175,7 @@ class PreviewManager implements IPreview { * @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); } @@ -210,13 +210,15 @@ class PreviewManager implements IPreview { /** * 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; } @@ -226,7 +228,7 @@ class PreviewManager implements IPreview { } 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)) { @@ -452,8 +454,8 @@ class PreviewManager implements IPreview { /** * @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'); } } |