Skip to content

Commit 6ea5127

Browse files
committed
fix(PreviewManager): use the forced mimetype in throwIfPreviewsDisabled
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 72b6aae commit 6ea5127

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/private/PreviewManager.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function getPreview(
154154
$mimeType = null,
155155
bool $cacheResult = true,
156156
): ISimpleFile {
157-
$this->throwIfPreviewsDisabled($file);
157+
$this->throwIfPreviewsDisabled($file, $mimeType);
158158
$previewConcurrency = $this->getGenerator()->getNumConcurrentPreviews('preview_concurrency_all');
159159
$sem = Generator::guardWithSemaphore(Generator::SEMAPHORE_ID_ALL, $previewConcurrency);
160160
try {
@@ -178,7 +178,7 @@ public function getPreview(
178178
* @since 19.0.0
179179
*/
180180
public function generatePreviews(File $file, array $specifications, $mimeType = null) {
181-
$this->throwIfPreviewsDisabled($file);
181+
$this->throwIfPreviewsDisabled($file, $mimeType);
182182
return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType);
183183
}
184184

@@ -213,13 +213,15 @@ public function isMimeSupported($mimeType = '*') {
213213
/**
214214
* Check if a preview can be generated for a file
215215
*/
216-
public function isAvailable(\OCP\Files\FileInfo $file): bool {
216+
public function isAvailable(\OCP\Files\FileInfo $file, ?string $mimeType = null): bool {
217217
if (!$this->enablePreviews) {
218218
return false;
219219
}
220220

221+
$fileMimeType = $mimeType ?? $file->getMimeType();
222+
221223
$this->registerCoreProviders();
222-
if (!$this->isMimeSupported($file->getMimetype())) {
224+
if (!$this->isMimeSupported($fileMimeType)) {
223225
return false;
224226
}
225227

@@ -229,7 +231,7 @@ public function isAvailable(\OCP\Files\FileInfo $file): bool {
229231
}
230232

231233
foreach ($this->providers as $supportedMimeType => $providers) {
232-
if (preg_match($supportedMimeType, $file->getMimetype())) {
234+
if (preg_match($supportedMimeType, $fileMimeType)) {
233235
foreach ($providers as $providerClosure) {
234236
$provider = $this->helper->getProvider($providerClosure);
235237
if (!($provider instanceof IProviderV2)) {
@@ -455,8 +457,8 @@ private function registerBootstrapProviders(): void {
455457
/**
456458
* @throws NotFoundException if preview generation is disabled
457459
*/
458-
private function throwIfPreviewsDisabled(File $file): void {
459-
if (!$this->isAvailable($file)) {
460+
private function throwIfPreviewsDisabled(File $file, ?string $mimeType = null): void {
461+
if (!$this->isAvailable($file, $mimeType)) {
460462
throw new NotFoundException('Previews disabled');
461463
}
462464
}

0 commit comments

Comments
 (0)