aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Veyssier <julien-nc@posteo.net>2025-05-30 13:19:34 +0200
committerJulien Veyssier <julien-nc@posteo.net>2025-06-02 15:50:53 +0200
commitc7e9f2c03dced0b9308af8d6366de3e44a959354 (patch)
tree83fb7fdfc7abc4f641a423fc0fce666eef817ba3
parentd2356d9d76c567a87411c96522d7c0b59b308611 (diff)
downloadnextcloud-server-fix/noid/get-preview-force-mimetype.tar.gz
nextcloud-server-fix/noid/get-preview-force-mimetype.zip
fix(PreviewManager): use the forced mimetype in throwIfPreviewsDisabledfix/noid/get-preview-force-mimetype
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
-rw-r--r--lib/private/PreviewManager.php16
-rw-r--r--lib/public/IPreview.php4
2 files changed, 12 insertions, 8 deletions
diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php
index fa62a7b0257..0bb0280406c 100644
--- a/lib/private/PreviewManager.php
+++ b/lib/private/PreviewManager.php
@@ -154,7 +154,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 {
@@ -178,7 +178,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);
}
@@ -213,13 +213,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;
}
@@ -229,7 +231,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)) {
@@ -455,8 +457,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');
}
}
diff --git a/lib/public/IPreview.php b/lib/public/IPreview.php
index 5a2bcde69f1..3c9eadd4577 100644
--- a/lib/public/IPreview.php
+++ b/lib/public/IPreview.php
@@ -92,10 +92,12 @@ interface IPreview {
* 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
* @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